Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure os_get_current_time_us wraps as 32bit boundary #17

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

elupus
Copy link
Contributor

@elupus elupus commented Jan 23, 2023

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.

tick_to_ms is not guaranteed to wrap at 32bit
boundary if tick speed is not set to 1ms per tick.
It will also regress to low precision (1second) when
the tick count is larger than UINT32_MAX / 1000.
@elupus
Copy link
Contributor Author

elupus commented Jan 23, 2023

FreeRTOS port suffers equal problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant