diff --git a/include/kernel.h b/include/kernel.h index 6f497ae46de..ba6c20f935b 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -1483,6 +1483,8 @@ __syscall u32_t k_timer_status_get(struct k_timer *timer); */ __syscall u32_t k_timer_status_sync(struct k_timer *timer); +extern s32_t z_timeout_remaining(struct _timeout *timeout); + /** * @brief Get time remaining before a timer next expires. * @@ -1497,7 +1499,7 @@ __syscall s32_t k_timer_remaining_get(struct k_timer *timer); static inline s32_t _impl_k_timer_remaining_get(struct k_timer *timer) { - return _timeout_remaining_get(&timer->timeout); + return __ticks_to_ms(z_timeout_remaining(&timer->timeout)); } /** @@ -2730,7 +2732,7 @@ static inline int k_delayed_work_submit(struct k_delayed_work *work, */ static inline s32_t k_delayed_work_remaining_get(struct k_delayed_work *work) { - return _timeout_remaining_get(&work->timeout); + return __ticks_to_ms(z_timeout_remaining(&work->timeout)); } /** @} */ diff --git a/include/sys_clock.h b/include/sys_clock.h index b9a5049362a..869d1e95cfb 100644 --- a/include/sys_clock.h +++ b/include/sys_clock.h @@ -220,8 +220,6 @@ struct _timeout { _timeout_func_t func; }; -extern s32_t _timeout_remaining_get(struct _timeout *timeout); - /* * Number of ticks for x seconds. NOTE: With MSEC() or USEC(), * since it does an integer division, x must be greater or equal to diff --git a/kernel/include/timeout_q.h b/kernel/include/timeout_q.h index 73a31606ea8..82adc3e9019 100644 --- a/kernel/include/timeout_q.h +++ b/kernel/include/timeout_q.h @@ -20,6 +20,8 @@ extern "C" { #ifdef CONFIG_SYS_CLOCK_EXISTS +struct _thread_base; + extern u64_t z_last_tick_announced; void _init_timeout(struct _timeout *t, _timeout_func_t fn); @@ -37,6 +39,8 @@ int _abort_thread_timeout(struct k_thread *thread); s32_t _get_next_timeout_expiry(void); +s32_t z_timeout_remaining(struct _timeout *timeout); + #else /* Stubs when !CONFIG_SYS_CLOCK_EXISTS */ diff --git a/kernel/sys_clock.c b/kernel/sys_clock.c index 5c7e5f3b76d..07d6e582682 100644 --- a/kernel/sys_clock.c +++ b/kernel/sys_clock.c @@ -574,4 +574,31 @@ void _add_thread_timeout(struct k_thread *thread, s32_t timeout_in_ticks) _add_timeout(&thread->base.timeout, NULL, timeout_in_ticks); } +s32_t z_timeout_remaining(struct _timeout *timeout) +{ + unsigned int key = irq_lock(); + s32_t remaining_ticks; + + if (timeout->delta_ticks_from_prev == _INACTIVE) { + remaining_ticks = 0; + } else { + /* + * compute remaining ticks by walking the timeout list + * and summing up the various tick deltas involved + */ + struct _timeout *t = + (struct _timeout *)sys_dlist_peek_head(&_timeout_q); + + remaining_ticks = t->delta_ticks_from_prev; + while (t != timeout) { + t = (struct _timeout *)sys_dlist_peek_next(&_timeout_q, + &t->node); + remaining_ticks += t->delta_ticks_from_prev; + } + } + + irq_unlock(key); + return remaining_ticks; +} + #endif /* CONFIG_SYS_CLOCK_EXISTS */ diff --git a/kernel/timer.c b/kernel/timer.c index 423f55ae372..1a0d7a5e4d0 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -226,33 +226,6 @@ u32_t _impl_k_timer_status_sync(struct k_timer *timer) Z_SYSCALL_HANDLER1_SIMPLE(k_timer_status_sync, K_OBJ_TIMER, struct k_timer *); #endif -s32_t _timeout_remaining_get(struct _timeout *timeout) -{ - unsigned int key = irq_lock(); - s32_t remaining_ticks; - - if (timeout->delta_ticks_from_prev == _INACTIVE) { - remaining_ticks = 0; - } else { - /* - * compute remaining ticks by walking the timeout list - * and summing up the various tick deltas involved - */ - struct _timeout *t = - (struct _timeout *)sys_dlist_peek_head(&_timeout_q); - - remaining_ticks = t->delta_ticks_from_prev; - while (t != timeout) { - t = (struct _timeout *)sys_dlist_peek_next(&_timeout_q, - &t->node); - remaining_ticks += t->delta_ticks_from_prev; - } - } - - irq_unlock(key); - return __ticks_to_ms(remaining_ticks); -} - #ifdef CONFIG_USERSPACE Z_SYSCALL_HANDLER1_SIMPLE(k_timer_remaining_get, K_OBJ_TIMER, struct k_timer *); Z_SYSCALL_HANDLER1_SIMPLE(k_timer_user_data_get, K_OBJ_TIMER, struct k_timer *);