kernel/timeout: fix k_timer_remaining_get() when tickless

In some circumstances (e.g., a tickless kernel), k_timer_remaining_get()
would not account for time passed that didn't involve clock interrupts.
This adds a simple fix for that, and adds a test case.  In addition, the
return value of k_timer_remaining_get() is clamped at 0 in the case of
overdue timers and the API description is adjusted to reflect this.

Fixes: #13353

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
This commit is contained in:
Charles E. Youse 2019-03-01 10:51:04 -08:00 committed by Andrew Boie
commit 0ad4022e51
4 changed files with 34 additions and 4 deletions

View file

@ -1561,7 +1561,8 @@ __syscall u32_t k_timer_remaining_get(struct k_timer *timer);
static inline u32_t _impl_k_timer_remaining_get(struct k_timer *timer)
{
return (u32_t)__ticks_to_ms(z_timeout_remaining(&timer->timeout));
const s32_t ticks = z_timeout_remaining(&timer->timeout);
return (ticks > 0) ? (u32_t)__ticks_to_ms(ticks) : 0U;
}
/**