Skip to content

[feature-wisun] Make _unacknowledged_ticks uint32_t to prevent overflow #13901

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

Merged
merged 1 commit into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions platform/source/SysTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,15 @@ void SysTimer<US_IN_TICK, IRQ>::acknowledge_tick()
{
// Try to avoid missed ticks if OS's IRQ level is not keeping
// up with our handler.
// 8-bit counter to save space, and also make sure it we don't
// try TOO hard to resync if something goes really awry -
// resync will reset if the count hits 256.
if (core_util_atomic_decr_u8(&_unacknowledged_ticks, 1) > 0) {
// This value should not get large during normal operation.
// However, when interrupts are not handled for a while
// (e.g. by debug halt or large critical sections) this
// number will get large very quickly. All these un-
// acknowledged ticks need to be processed because otherwise
// the OS timing will be off. Processing may take a while.
// For more info see: https://github.com/ARMmbed/mbed-os/issues/13801

if (core_util_atomic_decr_u32(&_unacknowledged_ticks, 1) > 0) {
_set_irq_pending();
}
}
Expand Down
4 changes: 2 additions & 2 deletions platform/source/SysTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable<SysTimer<US_
*/
int unacknowledged_ticks() const
{
return core_util_atomic_load_u8(&_unacknowledged_ticks);
return core_util_atomic_load_u32(&_unacknowledged_ticks);
}

/** Get the current tick count
Expand Down Expand Up @@ -227,7 +227,7 @@ class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable<SysTimer<US_
static void _clear_irq_pending();
us_timestamp_t _time_us;
uint64_t _tick;
uint8_t _unacknowledged_ticks;
uint32_t _unacknowledged_ticks;
bool _wake_time_set;
bool _wake_time_passed;
bool _wake_early;
Expand Down