From eb0cbb433c7471c8f1a10e91c04d46d912525993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 4 Jan 2023 14:01:36 +0100 Subject: [PATCH] drivers: nrf_rtc_timer: Correct initial timeout value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Values to be set to the comparator need to be specified in RTC cycles, not ticks, so the initial value used in the tickless mode needs to be MAX_CYCLES, otherwise when CONFIG_SYS_CLOCK_TICKS_PER_SEC is set to a value less then the RTC frequency, the initially configured timeout will be unnecessarily shorter. On the occassion, remove also the call to counter() when setting the initial timeout value in non-tickless mode. RTC is cleared a few lines above, so at this point it will most likely be 0, and even if it was not, compare_set() would properly handle a target time value that had already passed. Signed-off-by: Andrzej Głąbek --- drivers/timer/nrf_rtc_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index ba93537b58f..03398848c8e 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -670,7 +670,7 @@ static int sys_clock_driver_init(const struct device *dev) } uint32_t initial_timeout = IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? - MAX_TICKS : (counter() + CYC_PER_TICK); + MAX_CYCLES : CYC_PER_TICK; compare_set(0, initial_timeout, sys_clock_timeout_handler, NULL);