73 #include "em_device.h" 86 #define ULFRCOFREQ 1000 87 #define ULFRCOFREQ_MS 1.000 88 #define LFXOFREQ 32768 89 #define LFXOFREQ_MS 32.768 98 static volatile uint32_t msTicks;
105 #if SYSTICKDELAY == 1 106 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;
145 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
149 uint32_t curTicks = msTicks;
150 while ((msTicks - curTicks) < msDelay);
153 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk;
180 CMU_ClockEnable(cmuClock_RTC,
true);
191 #if DEBUG_DBPRINT == 1 192 dbcrit(
"Delay too long, can't fit in the field!");
196 CMU_ClockEnable(cmuClock_RTC,
false);
210 #if DEBUG_DBPRINT == 1 211 dbcrit(
"Delay too long, can't fit in the field!");
215 CMU_ClockEnable(cmuClock_RTC,
false);
259 CMU_ClockEnable(cmuClock_RTC,
false);
300 CMU_ClockEnable(cmuClock_RTC,
true);
303 #if DEBUG_DBPRINT == 1 305 dbwarnInt(
"Sleeping in EM3 for ", sSleep,
" s\n\r");
307 dbwarnInt(
"Sleeping in EM2 for ", sSleep,
" s\n\r");
319 #if DEBUG_DBPRINT == 1 320 dbcrit(
"Delay too long, can't fit in the field!");
324 CMU_ClockEnable(cmuClock_RTC,
false);
334 if ((
LFXOFREQ * sSleep) <= 0x00ffffff) RTC_CompareSet(0, (
LFXOFREQ * sSleep));
338 #if DEBUG_DBPRINT == 1 339 dbcrit(
"Delay too long, can't fit in the field!");
343 CMU_ClockEnable(cmuClock_RTC,
false);
393 CMU_ClockEnable(cmuClock_RTC,
false);
430 uint32_t sSleep = RTC_CounterGet();
463 CMU_ClockEnable(cmuClock_HFLE,
true);
466 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);
471 CMU_OscillatorEnable(cmuOsc_LFXO,
true,
true);
475 CMU_ClockEnable(cmuClock_HFLE,
true);
478 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
483 CMU_ClockEnable(cmuClock_RTC,
true);
486 RTC_IntEnable(RTC_IEN_COMP0);
487 RTC_IntClear(RTC_IFC_COMP0);
488 NVIC_ClearPendingIRQ(RTC_IRQn);
489 NVIC_EnableIRQ(RTC_IRQn);
492 RTC_Init_TypeDef rtc = RTC_INIT_DEFAULT;
498 #if DEBUG_DBPRINT == 1 500 dbinfo(
"RTC initialized with ULFRCO\n\r");
502 dbinfo(
"RTC initialized with LFXO\n\r");
510 #if SYSTICKDELAY == 1 515 void SysTick_Handler (
void)
535 RTC_IntClear(RTC_IFC_COMP0);
void sleep(uint32_t sSleep)
Sleep for a certain amount of seconds in EM2/3.
static void initRTC(void)
RTC initialization.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
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.
void error(uint8_t number)
Error method.
The pin definitions for the regular and custom Happy Gecko board.
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.