17 #include PLATFORM_HEADER
19 #include "hal/micro/micro-common.h"
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 int32u gpioWakeBitMask)
77 StStatus status = ST_SUCCESS;
78 int32u 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);