From 45303796d77051e2520a94b01ee6a18da23b27c9 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Fri, 2 Jun 2017 19:04:19 +0200 Subject: [PATCH] nrf5/hal/rtc: Updating hal driver to calculate prescaler a bit more verbose. Using 1 second interval ticks. --- nrf5/hal/hal_rtc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nrf5/hal/hal_rtc.c b/nrf5/hal/hal_rtc.c index bd3905bb4f..d3ea751915 100644 --- a/nrf5/hal/hal_rtc.c +++ b/nrf5/hal/hal_rtc.c @@ -30,6 +30,10 @@ #ifdef HAL_RTC_MODULE_ENABLED +#define HAL_LFCLK_FREQ (32768UL) +#define HAL_RTC_FREQ (10UL) +#define HAL_RTC_COUNTER_PRESCALER ((HAL_LFCLK_FREQ/HAL_RTC_FREQ)-1) + static hal_rtc_app_callback m_callback; static uint32_t m_period[sizeof(RTC_BASE_POINTERS) / sizeof(uint32_t)]; @@ -50,14 +54,14 @@ void hal_rtc_init(hal_rtc_conf_t const * p_rtc_conf) { m_period[p_rtc_conf->id] = p_rtc_conf->period; - p_rtc->PRESCALER = (32768 / 32) - 1; // approx ms ticks. + p_rtc->PRESCALER = HAL_RTC_COUNTER_PRESCALER; hal_irq_priority(RTC_IRQ_NUM(p_rtc_conf->id), p_rtc_conf->irq_priority); } void hal_rtc_start(uint8_t id) { NRF_RTC_Type * p_rtc = RTC_BASE(id); - uint32_t period = m_period[id]; + uint32_t period = HAL_RTC_FREQ * m_period[id]; uint32_t counter = p_rtc->COUNTER; p_rtc->CC[0] = counter + period;