Re: Kernel MS Precision


Andreas Lenz
 

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)

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.
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,
Andreas

Join devel@lists.zephyrproject.org to automatically receive all group messages.