osal
osal copied to clipboard
Make sure os_get_current_time_us wraps as 32bit boundary
Extend the timer used to 64bit by keeping track of when it wraps
Background When kernel is running at tick rate different from 1000 ticks per seconds:
- tick_to_ms will not wrap at 32 bit boundary
- tick_to_ms will degrade to 1 second accuracy when tick is larger than UINT32_MAX / 1000
This lead to issues when os_get_current_time_us is used as a periodic timing manager as in the following example:
uint32_t diff = os_get_current_time_us() - start;
if (diff > delay)
do_something()
This is welled formed if os_get_current_time_us() always wraps around at 32bit max boundary, but lead to unexpected behaviour otherwise.