STC15W408AS library 0.17.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#include <stdbool.h>
16
22#define WIRC_H_ADDRESS 0xf8
23
29#define WIRC_L_ADDRESS 0xf9
30
31
42#define WAKEUP_DEFAULT_FREQ 32768U
43
56#define idle() (bit_set(PCON, SBIT0))
57
67#define power_down() \
68do { \
69 bit_set(PCON, SBIT1); \
70 __asm__("nop"); \
71 __asm__("nop"); \
72 __asm__("nop"); \
73} while(0)
74
86#define wakeup_timer_init(ticks) \
87do { \
88 WKTCH = (ticks >> 8) | 0x80; \
89 WKTCL = ticks & 0xff; \
90} while(0)
91
92
117#define wakeup_timer_init_seconds(seconds) \
118do { \
119 uint16_t wakeup_freq = wakeup_timer_internal_clk_freq(); \
120 if (!wakeup_freq) { wakeup_freq = WAKEUP_DEFAULT_FREQ; } \
121 uint16_t timer_ticks = seconds * (wakeup_freq >> 4); \
122 wakeup_timer_init(timer_ticks); \
123} while(0)
124
125static volatile __idata uint8_t * const wirc_h_ptr = (__idata uint8_t *) WIRC_H_ADDRESS;
126static volatile __idata uint8_t * const wirc_l_ptr = (__idata uint8_t *) WIRC_L_ADDRESS;
145#define wakeup_timer_internal_clk_freq() (((uint16_t)*wirc_h_ptr << 8) | *wirc_l_ptr)
146
161#define get_power_low_voltage_flag() (get_bit(PCON, 5))
162
172#define clear_power_low_voltage_flag() (bit_clr(PCON, CBIT5))
173
174#endif
#define WIRC_L_ADDRESS
Wakeup timer internal clock frequency value low byte address.
Definition power_management.h:29
#define WIRC_H_ADDRESS
Wakeup timer internal clock frequency value high byte address.
Definition power_management.h:22