From b4aeef4d5bcdcc46144cdbfb181e98ff2a91b1df Mon Sep 17 00:00:00 2001 From: Eric Johnson Date: Fri, 5 Mar 2021 08:31:50 -0600 Subject: [PATCH] kernel: timer: Fix incorrect behavior for timers with K_FOREVER period Zephyr docs state that timers will act as one-shot timers when started with a period of K_NO_WAIT or K_FOREVER. However the code adjusting period was setting K_FOREVER timeout ticks to 1 which caused the timer to expire every tick. This adds a check to not adjust K_FOREVER periods Signed-off-by: Eric Johnson --- kernel/timer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/timer.c b/kernel/timer.c index b88c5dcc4e6..8bdff9a590d 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -126,7 +126,8 @@ void z_impl_k_timer_start(struct k_timer *timer, k_timeout_t duration, * argument the same way k_sleep() does), but historical. The * timer_api test relies on this behavior. */ - if (period.ticks != 0 && Z_TICK_ABS(period.ticks) < 0) { + if (!K_TIMEOUT_EQ(period, K_FOREVER) && period.ticks != 0 && + Z_TICK_ABS(period.ticks) < 0) { period.ticks = MAX(period.ticks - 1, 1); } if (Z_TICK_ABS(duration.ticks) < 0) {