65 #include "em_device.h"
78 #define ULFRCOFREQ 1000
79 #define ULFRCOFREQ_MS 1.000
80 #define LFXOFREQ 32768
81 #define LFXOFREQ_MS 32.768
87 static volatile bool RTC_sleep_wakeup =
false;
90 static volatile uint32_t msTicks;
103 static void initRTC (
void);
119 #if SYSTICKDELAY == 1
126 if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000))
while (1);
128 #if DEBUG_DBPRINT == 1
129 dbinfo(
"SysTick initialized");
137 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk;
141 uint32_t curTicks = msTicks;
142 while ((msTicks - curTicks) < msDelay);
145 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk & ~SysTick_CTRL_ENABLE_Msk;
172 CMU_ClockEnable(cmuClock_RTC,
true);
183 #if DEBUG_DBPRINT == 1
184 dbcrit(
"Delay too long, can't fit in the field!");
188 CMU_ClockEnable(cmuClock_RTC,
false);
202 #if DEBUG_DBPRINT == 1
203 dbcrit(
"Delay too long, can't fit in the field!");
207 CMU_ClockEnable(cmuClock_RTC,
false);
251 CMU_ClockEnable(cmuClock_RTC,
false);
292 CMU_ClockEnable(cmuClock_RTC,
true);
295 #if DEBUG_DBPRINT == 1
297 dbwarnInt(
"Sleeping in EM3 for ", sSleep,
" s\n\r");
299 dbwarnInt(
"Sleeping in EM2 for ", sSleep,
" s\n\r");
311 #if DEBUG_DBPRINT == 1
312 dbcrit(
"Delay too long, can't fit in the field!");
316 CMU_ClockEnable(cmuClock_RTC,
false);
326 if ((
LFXOFREQ * sSleep) <= 0x00ffffff) RTC_CompareSet(0, (
LFXOFREQ * sSleep));
330 #if DEBUG_DBPRINT == 1
331 dbcrit(
"Delay too long, can't fit in the field!");
335 CMU_ClockEnable(cmuClock_RTC,
false);
385 CMU_ClockEnable(cmuClock_RTC,
false);
398 return (RTC_sleep_wakeup);
408 RTC_sleep_wakeup =
false;
422 uint32_t sSleep = RTC_CounterGet();
445 static void initRTC (
void)
455 CMU_ClockEnable(cmuClock_HFLE,
true);
458 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_ULFRCO);
463 CMU_OscillatorEnable(cmuOsc_LFXO,
true,
true);
467 CMU_ClockEnable(cmuClock_HFLE,
true);
470 CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFXO);
475 CMU_ClockEnable(cmuClock_RTC,
true);
478 RTC_IntEnable(RTC_IEN_COMP0);
479 RTC_IntClear(RTC_IFC_COMP0);
480 NVIC_ClearPendingIRQ(RTC_IRQn);
481 NVIC_EnableIRQ(RTC_IRQn);
484 RTC_Init_TypeDef rtc = RTC_INIT_DEFAULT;
490 #if DEBUG_DBPRINT == 1
492 dbinfo(
"RTC initialized with ULFRCO\n\r");
494 dbinfo(
"RTC initialized with LFXO\n\r");
502 #if SYSTICKDELAY == 1