From 3ffaaa989a99e93202d2bfc6603f642e86ce9236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Wed, 4 Jan 2023 13:49:50 +0100 Subject: [PATCH] drivers: nrf_rtc_timer: Always announce actual number of elapsed ticks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In non-tickless mode, the timeout handler always announced maximum 1 tick to kernel, but in fact it cannot be guaranteed that the handler execution is not delayed and that the number of elapsed ticks does not exceed 1. Use the actual number instead. Switch also to using a 32-bit value for `dticks` to get a bit simpler generated code (ticks delta is not supposed to be that huge). Signed-off-by: Andrzej Głąbek --- drivers/timer/nrf_rtc_timer.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/timer/nrf_rtc_timer.c b/drivers/timer/nrf_rtc_timer.c index 40b77c7129c..ba93537b58f 100644 --- a/drivers/timer/nrf_rtc_timer.c +++ b/drivers/timer/nrf_rtc_timer.c @@ -405,7 +405,7 @@ static void sys_clock_timeout_handler(int32_t chan, void *user_data) { uint32_t cc_value = absolute_time_to_cc(expire_time); - uint64_t dticks = (expire_time - last_count) / CYC_PER_TICK; + uint32_t dticks = (uint32_t)(expire_time - last_count) / CYC_PER_TICK; last_count += dticks * CYC_PER_TICK; @@ -419,8 +419,7 @@ static void sys_clock_timeout_handler(int32_t chan, sys_clock_timeout_handler, NULL); } - sys_clock_announce(IS_ENABLED(CONFIG_TICKLESS_KERNEL) ? - (int32_t)dticks : (dticks > 0)); + sys_clock_announce(dticks); } static bool channel_processing_check_and_clear(int32_t chan)