From dd0715c770f21a78dca874a5353123d283c2586d Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 14 Apr 2021 13:36:58 +0200 Subject: [PATCH] kernel: timer: Adding support to CONFIG_MULTITHREADING=n Updated timer to not touch thread/scheduler code when multithreading is off. Signed-off-by: Krzysztof Chruscinski --- kernel/timer.c | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/kernel/timer.c b/kernel/timer.c index 8bdff9a590d..a5c93d5ce32 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -66,6 +66,10 @@ void z_timer_expiration_handler(struct _timeout *t) timer->expiry_fn(timer); } + if (!IS_ENABLED(CONFIG_MULTITHREADING)) { + return; + } + thread = z_waitq_head(&timer->wait_q); if (thread == NULL) { @@ -96,7 +100,10 @@ void k_timer_init(struct k_timer *timer, timer->stop_fn = stop_fn; timer->status = 0U; - z_waitq_init(&timer->wait_q); + if (IS_ENABLED(CONFIG_MULTITHREADING)) { + z_waitq_init(&timer->wait_q); + } + z_init_timeout(&timer->timeout); SYS_TRACING_OBJ_INIT(k_timer, timer); @@ -165,11 +172,13 @@ void z_impl_k_timer_stop(struct k_timer *timer) timer->stop_fn(timer); } - struct k_thread *pending_thread = z_unpend1_no_timeout(&timer->wait_q); + if (IS_ENABLED(CONFIG_MULTITHREADING)) { + struct k_thread *pending_thread = z_unpend1_no_timeout(&timer->wait_q); - if (pending_thread != NULL) { - z_ready_thread(pending_thread); - z_reschedule_unlocked(); + if (pending_thread != NULL) { + z_ready_thread(pending_thread); + z_reschedule_unlocked(); + } } } @@ -206,6 +215,29 @@ uint32_t z_impl_k_timer_status_sync(struct k_timer *timer) { __ASSERT(!arch_is_in_isr(), ""); + if (!IS_ENABLED(CONFIG_MULTITHREADING)) { + uint32_t result; + + do { + k_spinlock_key_t key = k_spin_lock(&lock); + + if (!z_is_inactive_timeout(&timer->timeout)) { + result = *(volatile uint32_t *)&timer->status; + timer->status = 0U; + k_spin_unlock(&lock, key); + if (result > 0) { + break; + } + } else { + result = timer->status; + k_spin_unlock(&lock, key); + break; + } + } while (true); + + return result; + } + k_spinlock_key_t key = k_spin_lock(&lock); uint32_t result = timer->status;