From 7924c667f3588aae304aa6c305e06974f0072118 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Tue, 4 Apr 2023 14:35:19 +0100 Subject: [PATCH] drivers: timer: nrf_rtc_timer: Implement stop function Implements functionality to stop the nRF RTC system timer source. Signed-off-by: Jamie McCrae --- drivers/timer/Kconfig.nrf_rtc | 1 + drivers/timer/nrf_rtc_timer.c | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/drivers/timer/Kconfig.nrf_rtc b/drivers/timer/Kconfig.nrf_rtc index 5e64545067a..cda05d4dabe 100644 --- a/drivers/timer/Kconfig.nrf_rtc +++ b/drivers/timer/Kconfig.nrf_rtc @@ -8,6 +8,7 @@ config NRF_RTC_TIMER depends on CLOCK_CONTROL depends on SOC_COMPATIBLE_NRF select TICKLESS_CAPABLE + select SYSTEM_TIMER_HAS_DISABLE_SUPPORT depends on !$(dt_nodelabel_enabled,rtc1) help This module implements a kernel device driver for the nRF Real Time diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 180425c7c23..ebf3ad92b28 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -660,15 +660,8 @@ uint32_t sys_clock_cycle_get_32(void) return (uint32_t)z_nrf_rtc_timer_read(); } -static int sys_clock_driver_init(const struct device *dev) +static void int_event_disable_rtc(void) { - ARG_UNUSED(dev); - static const enum nrf_lfclk_start_mode mode = - IS_ENABLED(CONFIG_SYSTEM_CLOCK_NO_WAIT) ? - CLOCK_CONTROL_NRF_LF_START_NOWAIT : - (IS_ENABLED(CONFIG_SYSTEM_CLOCK_WAIT_FOR_AVAILABILITY) ? - CLOCK_CONTROL_NRF_LF_START_AVAILABLE : - CLOCK_CONTROL_NRF_LF_START_STABLE); uint32_t mask = NRF_RTC_INT_TICK_MASK | NRF_RTC_INT_OVERFLOW_MASK | NRF_RTC_INT_COMPARE0_MASK | @@ -681,6 +674,27 @@ static int sys_clock_driver_init(const struct device *dev) /* Reset event routing enabling to expected reset values */ nrf_rtc_event_disable(RTC, mask); +} + +void sys_clock_disable(void) +{ + nrf_rtc_task_trigger(RTC, NRF_RTC_TASK_STOP); + irq_disable(RTC_IRQn); + int_event_disable_rtc(); + NVIC_ClearPendingIRQ(RTC_IRQn); +} + +static int sys_clock_driver_init(const struct device *dev) +{ + ARG_UNUSED(dev); + static const enum nrf_lfclk_start_mode mode = + IS_ENABLED(CONFIG_SYSTEM_CLOCK_NO_WAIT) ? + CLOCK_CONTROL_NRF_LF_START_NOWAIT : + (IS_ENABLED(CONFIG_SYSTEM_CLOCK_WAIT_FOR_AVAILABILITY) ? + CLOCK_CONTROL_NRF_LF_START_AVAILABLE : + CLOCK_CONTROL_NRF_LF_START_STABLE); + + int_event_disable_rtc(); /* TODO: replace with counter driver to access RTC */ nrf_rtc_prescaler_set(RTC, 0);