mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 23:43:40 +00:00
nrf: fix sleep
For some reason, the old behavior stopped working at some point (maybe at the nrfx update?). Change sleep behavior to be more correct.
This commit is contained in:
@@ -11,8 +11,13 @@ static volatile bool rtc_wakeup;
|
|||||||
void rtc_sleep(uint32_t ticks) {
|
void rtc_sleep(uint32_t ticks) {
|
||||||
NRF_RTC0->INTENSET = RTC_INTENSET_COMPARE0_Msk;
|
NRF_RTC0->INTENSET = RTC_INTENSET_COMPARE0_Msk;
|
||||||
rtc_wakeup = false;
|
rtc_wakeup = false;
|
||||||
NRF_RTC0->TASKS_CLEAR = 1;
|
if (ticks == 1) {
|
||||||
NRF_RTC0->CC[0] = ticks;
|
// Race condition (even in hardware) at ticks == 1.
|
||||||
|
// TODO: fix this in a better way by detecting it, like the manual
|
||||||
|
// describes.
|
||||||
|
ticks = 2;
|
||||||
|
}
|
||||||
|
NRF_RTC0->CC[0] = (NRF_RTC0->COUNTER + ticks) & 0x00ffffff;
|
||||||
while (!rtc_wakeup) {
|
while (!rtc_wakeup) {
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user