STC15W408AS library 0.18.0
Loading...
Searching...
No Matches
power_management.h
Go to the documentation of this file.
1#ifndef POWER_MANAGEMENTH
2#define POWER_MANAGEMENTH
3
12#include <sys.h>
13#include <bits.h>
14#include <stdint.h>
15
21#define WIRC_H_ADDRESS 0xf8
22
28#define WIRC_L_ADDRESS 0xf9
29
30
41#define WAKEUP_DEFAULT_FREQ 32768U
42
55#define idle() (bit_set(PCON, SBIT0))
56
66#define power_down() \
67do { \
68 bit_set(PCON, SBIT1); \
69 __asm__("nop"); \
70 __asm__("nop"); \
71 __asm__("nop"); \
72} while(0)
73
85#define wakeup_timer_init(ticks) \
86do { \
87 WKTCH = (ticks >> 8) | 0x80; \
88 WKTCL = ticks & 0xff; \
89} while(0)
90
91
116#define wakeup_timer_init_seconds(seconds) \
117do { \
118 uint16_t wakeup_freq = wakeup_timer_internal_clk_freq(); \
119 if (!wakeup_freq) { wakeup_freq = WAKEUP_DEFAULT_FREQ; } \
120 uint16_t timer_ticks = seconds * (wakeup_freq >> 4); \
121 wakeup_timer_init(timer_ticks); \
122} while(0)
123
124static volatile __idata uint8_t * const wirc_h_ptr = (__idata uint8_t *) WIRC_H_ADDRESS;
125static volatile __idata uint8_t * const wirc_l_ptr = (__idata uint8_t *) WIRC_L_ADDRESS;
144#define wakeup_timer_internal_clk_freq() (((uint16_t)*wirc_h_ptr << 8) | *wirc_l_ptr)
145
160#define get_power_low_voltage_flag() (test_if_bit_set(PCON, 5))
161
171#define clear_power_low_voltage_flag() (bit_clr(PCON, SBIT5))
172
173#endif
#define WIRC_L_ADDRESS
Wakeup timer internal clock frequency value low byte address.
Definition power_management.h:28
#define WIRC_H_ADDRESS
Wakeup timer internal clock frequency value high byte address.
Definition power_management.h:21