diff options
| author | Nick Moore <nick@zoic.org> | 2019-02-07 23:50:14 +1100 |
|---|---|---|
| committer | Nick Moore <nick@zoic.org> | 2019-04-02 13:27:28 +1100 |
| commit | f846fa109ea20e74983fba7b7662f2bae9cc8fea (patch) | |
| tree | 5759656208b764277652f407e15003b9caeeff2e /ports/nrf | |
| parent | f88f9fd7482092a33d0fdf8f666b6019b484561a (diff) | |
enable NRFX RTC adafruit/circuitpython#1046
Diffstat (limited to 'ports/nrf')
| -rwxr-xr-x | ports/nrf/Makefile | 1 | ||||
| -rw-r--r-- | ports/nrf/common-hal/rtc/RTC.c | 28 | ||||
| -rw-r--r-- | ports/nrf/nrfx_config.h | 3 |
3 files changed, 28 insertions, 4 deletions
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 3681ac49e..3cb4b52aa 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -140,6 +140,7 @@ SRC_NRFX = $(addprefix nrfx/,\ drivers/src/nrfx_twim.c \ drivers/src/nrfx_uarte.c \ drivers/src/nrfx_gpiote.c \ + drivers/src/nrfx_rtc.c \ ) ifdef EXTERNAL_FLASH_DEVICES diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c index 7690b3bd3..85cdb4c37 100644 --- a/ports/nrf/common-hal/rtc/RTC.c +++ b/ports/nrf/common-hal/rtc/RTC.c @@ -33,24 +33,44 @@ #include "supervisor/shared/translate.h" #include "nrfx_rtc.h" +#include "nrf_clock.h" -static uint32_t _rtc_seconds = 0; +#define RTC_CLOCK_HZ (8) -void rtc_handler(nrfx_rtc_int_type_t int_type) { +static uint32_t rtc_offset = 0; + +const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(0); +const nrfx_rtc_config_t rtc_config = { + .prescaler = RTC_FREQ_TO_PRESCALER(RTC_CLOCK_HZ), + .reliable = 0, + .tick_latency = 0, + .interrupt_priority = 6 +}; + +void rtc_handler(nrfx_rtc_int_type_t int_type) { + // do nothing } void rtc_init(void) { + if (!nrf_clock_lf_is_running()) { + nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART); + } + nrfx_rtc_counter_clear(&rtc_instance); + nrfx_rtc_init(&rtc_instance, &rtc_config, rtc_handler); + nrfx_rtc_enable(&rtc_instance); } void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { - timeutils_seconds_since_2000_to_struct_time(_rtc_seconds, tm); + uint32_t t = rtc_offset + (nrfx_rtc_counter_get(&rtc_instance) / RTC_CLOCK_HZ ); + timeutils_seconds_since_2000_to_struct_time(t, tm); } void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { - _rtc_seconds = timeutils_seconds_since_2000( + rtc_offset = timeutils_seconds_since_2000( tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec ); + nrfx_rtc_counter_clear(&rtc_instance); } // A positive value speeds up the clock by removing clock cycles. diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h index 57a2727aa..b8a0a7f60 100644 --- a/ports/nrf/nrfx_config.h +++ b/ports/nrf/nrfx_config.h @@ -70,6 +70,9 @@ #define NRFX_PWM3_ENABLED 0 #endif +#define NRFX_RTC_ENABLED 1 +#define NRFX_RTC0_ENABLED 1 + // TIMERS #define NRFX_TIMER_ENABLED 1 // Don't enable TIMER0: it's used by the SoftDevice. |
