-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug] Computing time intervals with millis #72
Comments
thanks again, PR #73 should fix this. Feel free to re-open & comment if you think it doesn't |
fix #72 address overflow with board_delay
A simple way to fix it, due to 2's complement arithmetic overflow which is well-defined behaviour (at least in C99), is like this: static inline void board_delay(uint32_t ms)
{
uint32_t start_ms = board_millis();
while( board_millis() - start_ms < ms) {}
} Also, there are many places in the code that use this pattern, eg in if ( board_millis() < start_ms + interval_ms) return; |
Ah thank you, that is very neat 😄 . That proves how amazing Math is 🔢 |
Describe the bug
When computing time intervals care must be taken with wrap around. Eg:
If
start_ms
is close to0xffffffff
such that addingms
wraps it around then the function will most likely return straightaway.The text was updated successfully, but these errors were encountered: