diff --git a/platform/include/platform/internal/SysTimer.h b/platform/include/platform/internal/SysTimer.h index 229d535695..ac4357bdae 100644 --- a/platform/include/platform/internal/SysTimer.h +++ b/platform/include/platform/internal/SysTimer.h @@ -191,7 +191,7 @@ public: */ std::chrono::duration unacknowledged_ticks() const { - return std::chrono::duration(core_util_atomic_load_u8(&_unacknowledged_ticks)); + return std::chrono::duration(core_util_atomic_load_u32(&_unacknowledged_ticks)); } /** Get the current tick count @@ -248,7 +248,7 @@ protected: const highres_time_point _epoch; highres_time_point _time; uint64_t _tick; - uint8_t _unacknowledged_ticks; + uint32_t _unacknowledged_ticks; bool _wake_time_set; bool _wake_time_passed; bool _wake_early; diff --git a/platform/source/SysTimer.cpp b/platform/source/SysTimer.cpp index 2345e68bdd..6286cb739a 100644 --- a/platform/source/SysTimer.cpp +++ b/platform/source/SysTimer.cpp @@ -191,10 +191,15 @@ void SysTimer::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(); } }