osal
osal copied to clipboard
Extend os_get_current_time_us bits by helper
Extend the timer used to 64bit by keeping track of when it wraps
- Fixed for freertos and rt-kernel case
- Added test case for wrapping clock
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.