Re: Kernel MS Precision

Benjamin Walsh <benjamin.walsh@...>

On Fri, Mar 24, 2017 at 08:24:17AM +0000, Andreas Lenz wrote:
Hi Ben,

#define US_TIMEOUT(us) \
(int32_t)((((uint32_t)(us)) & 0x3fffffff) | 0x80000000)
// ^^^^^^^^^^^^^^^^^^^^^^^^
// keep the two upper bits as control bits just in
// case '10' would mean 'microseconds', '11' could
// mean something else
You could also use the full bits and add one additional byte to
specify the unit of the number.

Timers store their unit together with duration and period. For example
k_timer_start(timer, 100, 0, K_MSECONDS)
k_timer_start(timer, 100, 0, K_USECONDS)
Yeah, but that is not backwards-compatible with the API. And that only
works for timers, not the other APIs that take timeouts. Although, that
might be irrelevant.

For the "mean something else", I have a use case for low-priority, or
lazy timers.

They don't prevent the kernel to go into idle and expire later when
the system wakes up again.
Interesting idea. That could be a new API for timers though, it doesn't
have to modify an already existing one.

k_timer_start_lazy(timer, <timeout>);

Actually, it would probably have to be handled differently as well,
since the current implementation of timeouts does not handle having more
expired ticks than the next timer to expire, and this condition would
happen with this new feature when the kernel is in tickless idle.

What I have in mind is battery monitoring where checks should be done
about once every hour, but only when the system is active.

However, K_FOREVER might be problematic as the time can wrap.

Best regards,

Join to automatically receive all group messages.