mirror of https://github.com/tinygo-org/tinygo.git
Browse Source
This is the last critical part of the C runtime. Code size is reduced by 4 bytes for examples/blinky2 (probably due to inlining) and is unchanged for examples/test.pull/6/head
Ayke van Laethem
6 years ago
3 changed files with 27 additions and 39 deletions
@ -1,30 +0,0 @@ |
|||
|
|||
#include "hal/nrf_gpio.h" |
|||
#include "hal/nrf_uart.h" |
|||
#include "nrf.h" |
|||
#include "runtime.h" |
|||
#include "runtime_nrf.h" |
|||
#include <string.h> |
|||
|
|||
static volatile bool rtc_wakeup; |
|||
|
|||
void rtc_sleep(uint32_t ticks) { |
|||
NRF_RTC0->INTENSET = RTC_INTENSET_COMPARE0_Msk; |
|||
rtc_wakeup = false; |
|||
if (ticks == 1) { |
|||
// 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) { |
|||
__WFI(); |
|||
} |
|||
} |
|||
|
|||
void RTC0_IRQHandler() { |
|||
NRF_RTC0->INTENCLR = RTC_INTENSET_COMPARE0_Msk; |
|||
NRF_RTC0->EVENTS_COMPARE[0] = 0; |
|||
rtc_wakeup = true; |
|||
} |
Loading…
Reference in new issue