Skip to content

Commit 5440137

Browse files
author
Mika Leppänen
committed
[feature-wisun] Make _unacknowledged_ticks uint32_t to prevent overflow
1 parent a0a4707 commit 5440137

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

platform/source/SysTimer.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ void SysTimer<US_IN_TICK, IRQ>::acknowledge_tick()
192192
{
193193
// Try to avoid missed ticks if OS's IRQ level is not keeping
194194
// up with our handler.
195-
// 8-bit counter to save space, and also make sure it we don't
196-
// try TOO hard to resync if something goes really awry -
197-
// resync will reset if the count hits 256.
198-
if (core_util_atomic_decr_u8(&_unacknowledged_ticks, 1) > 0) {
195+
// This value should not get large during normal operation.
196+
// However, when interrupts are not handled for a while
197+
// (e.g. by debug halt or large critical sections) this
198+
// number will get large very quickly. All these un-
199+
// acknowledged ticks need to be processed because otherwise
200+
// the OS timing will be off. Processing may take a while.
201+
// For more info see: https://github.com/ARMmbed/mbed-os/issues/13801
202+
203+
if (core_util_atomic_decr_u32(&_unacknowledged_ticks, 1) > 0) {
199204
_set_irq_pending();
200205
}
201206
}

platform/source/SysTimer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable<SysTimer<US_
172172
*/
173173
int unacknowledged_ticks() const
174174
{
175-
return core_util_atomic_load_u8(&_unacknowledged_ticks);
175+
return core_util_atomic_load_u32(&_unacknowledged_ticks);
176176
}
177177

178178
/** Get the current tick count
@@ -227,7 +227,7 @@ class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable<SysTimer<US_
227227
static void _clear_irq_pending();
228228
us_timestamp_t _time_us;
229229
uint64_t _tick;
230-
uint8_t _unacknowledged_ticks;
230+
uint32_t _unacknowledged_ticks;
231231
bool _wake_time_set;
232232
bool _wake_time_passed;
233233
bool _wake_early;

0 commit comments

Comments
 (0)