73 #include "em_device.h" 85 #define ULFRCOFREQ 1000 86 #define ULFRCOFREQ_MS 1.000 87 #define LFXOFREQ 32768 88 #define LFXOFREQ_MS 32.768 104 #if SYSTICKDELAY == 1 105 bool SysTick_initialized =
false;
127 #if SYSTICKDELAY == 1 130 if (!SysTick_initialized)
134 if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
while (1);
136 #if DEBUG_DBPRINT == 1 137 dbinfo(
"SysTick initialized");
140 SysTick_initialized =
true;
148 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
157 while ((msTicks - curTicks) < msDelay);
160 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk;
191 CMU_ClockEnable(cmuClock_RTC,
true);
207 #if DEBUG_DBPRINT == 1 208 dbcrit(
"Delay too long, can't fit in the field!");
212 CMU_ClockEnable(cmuClock_RTC,
false);
226 #if DEBUG_DBPRINT == 1 227 dbcrit(
"Delay too long, can't fit in the field!");
231 CMU_ClockEnable(cmuClock_RTC,
false);
275 CMU_ClockEnable(cmuClock_RTC,
false);
321 CMU_ClockEnable(cmuClock_RTC,
true);
329 #if DEBUG_DBPRINT == 1 330 #if ANNOUNCE_SLEEPING == 1 332 dbinfoInt(
"Sleeping in EM3 for ", sSleep,
" s\n\r\n\r");
334 dbinfoInt(
"Sleeping in EM2 for ", sSleep,
" s\n\r\n\r");
347 #if DEBUG_DBPRINT == 1 348 dbcrit(
"Delay too long, can't fit in the field!");
352 CMU_ClockEnable(cmuClock_RTC,
false);
362 if ((
LFXOFREQ * sSleep) <= 0x00ffffff) RTC_CompareSet(0, (
LFXOFREQ * sSleep));
366 #if DEBUG_DBPRINT == 1 367 dbcrit(
"Delay too long, can't fit in the field!");
371 CMU_ClockEnable(cmuClock_RTC,
false);
420 CMU_ClockEnable(cmuClock_RTC,
false);
491 CMU_ClockEnable(cmuClock_HFLE,
true);
494 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);
499 CMU_OscillatorEnable(cmuOsc_LFXO,
true,
true);
503 CMU_ClockEnable(cmuClock_HFLE,
true);
506 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
511 CMU_ClockEnable(cmuClock_RTC,
true);
514 RTC_IntEnable(RTC_IEN_COMP0);
515 RTC_IntClear(RTC_IFC_COMP0);
516 NVIC_ClearPendingIRQ(RTC_IRQn);
517 NVIC_EnableIRQ(RTC_IRQn);
520 RTC_Init_TypeDef rtc = RTC_INIT_DEFAULT;
526 #if DEBUG_DBPRINT == 1 528 dbinfo(
"RTC initialized with ULFRCO");
530 dbinfo(
"RTC initialized with LFXO");
538 #if SYSTICKDELAY == 1 543 void SysTick_Handler (
void)
563 RTC_IntClear(RTC_IFC_COMP0);
void sleep(uint32_t sSleep)
Sleep for a certain amount of seconds in EM2/3.
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
static void initRTC(void)
RTC initialization.
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
void RTC_IRQHandler(void)
Interrupt Service Routine for the RTC.
uint32_t RTC_getPassedSleeptime(void)
Method to get the time spend sleeping (in seconds) in the case of GPIO wake-up.
void RTC_clearWakeup(void)
Method to clear RTC_sleep_wakeup.
bool RTC_checkWakeup(void)
Method to check if the wakeup was caused by the RTC.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
Enable or disable printing to UART with dbprint.
static volatile bool RTC_sleep_wakeup
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...