17 #include PLATFORM_HEADER
26 static boolean sleepTimerInterruptOccurred =
FALSE;
54 time = SLEEPTMR_CNTH<<16;
55 time |= SLEEPTMR_CNTL;
61 void halSleepTimerIsr(
void)
64 INT_SLEEPTMRFLAG = INT_SLEEPTMRWRAP | INT_SLEEPTMRCMPA | INT_SLEEPTMRCMPB;
67 sleepTimerInterruptOccurred =
TRUE;
70 #define CONVERT_QS_TO_TICKS(x) ((x) << 8)
71 #define CONVERT_TICKS_TO_QS(x) ((x) >> 8)
72 #define TIMER_MAX_QS 0x1000000 // = 4194304 seconds * 4 = 16777216
73 static StStatus internalSleepForQs(
boolean useGpioWakeMask,
75 uint32_t gpioWakeBitMask)
77 StStatus status = ST_SUCCESS;
78 uint32_t sleepOverflowCount;
90 INT_CFGCLR = INT_SLEEPTMR;
95 sleepOverflowCount = (*duration)/TIMER_MAX_QS;
97 remainder = CONVERT_QS_TO_TICKS((*duration)%TIMER_MAX_QS);
101 sleepTimerInterruptOccurred =
FALSE;
105 SLEEPTMR_CMPAL = (startCount+remainder)&0xFFFF;
106 SLEEPTMR_CMPAH = ((startCount+remainder)>>16)&0xFFFF;
108 INT_SLEEPTMRFLAG = INT_SLEEPTMRCMPA;
109 INT_SLEEPTMRCFG = INT_SLEEPTMRCMPA;
111 if(sleepOverflowCount) {
113 SLEEPTMR_CMPBL = startCount&0xFFFF;
114 SLEEPTMR_CMPBH = (startCount>>16)&0xFFFF;
118 INT_SLEEPTMRFLAG = INT_SLEEPTMRCMPB;
119 INT_SLEEPTMRCFG = INT_SLEEPTMRCMPB;
123 INT_CFGSET = INT_SLEEPTMR;
126 while(*duration > 0) {
131 INT_SLEEPTMRCFG = INT_SLEEPTMRCFG_RESET;
135 if(!sleepTimerInterruptOccurred) {
136 status = ST_SLEEP_INTERRUPTED;
146 if(sleepOverflowCount) {
147 sleepOverflowCount--;
148 *duration -= TIMER_MAX_QS;
150 *duration -= CONVERT_TICKS_TO_QS(remainder);
152 sleepTimerInterruptOccurred =
FALSE;
153 if(sleepOverflowCount) {
155 INT_SLEEPTMRFLAG = INT_SLEEPTMRCMPB;
156 INT_SLEEPTMRCFG = INT_SLEEPTMRCMPB;
157 }
else if(!sleepOverflowCount && (*duration>0)){
159 INT_SLEEPTMRFLAG = INT_SLEEPTMRCMPA;
160 INT_SLEEPTMRCFG = INT_SLEEPTMRCMPA;
170 return internalSleepForQs(
TRUE, duration, gpioWakeBitMask);
void halSleepWithOptions(SleepModes sleepMode, uint32_t gpioWakeBitMask)
Puts the microcontroller to sleep in a specified mode, allows the GPIO wake sources to be determined ...
uint16_t halCommonGetInt16uMillisecondTick(void)
Returns the current system time in system ticks, as a 16-bit value.
Utility and convenience functions for STM32W108 microcontroller, common to both the full and minimal ...
StStatus halSleepForQsWithOptions(uint32_t *duration, uint32_t gpioWakeBitMask)
Uses the system timer to enter ::SLEEPMODE_WAKETIMER for approximately the specified amount of time (...
#define TRUE
An alias for one, used for clarity.
Minimal Hal functions common across all microcontroller-specific files.
uint32_t halCommonGetInt32uMillisecondTick(void)
Returns the current system time in system ticks, as a 32-bit value.
#define INTERRUPTS_ON()
Enable global interrupts without regard to the current or previous state.
#define FALSE
An alias for zero, used for clarity.
#define ATOMIC(blah)
A block of code may be made atomic by wrapping it with this macro.
uint16_t halCommonGetInt16uQuarterSecondTick(void)
Returns the current system time in quarter second ticks, as a 16-bit value.
Header file for system_timer APIs.