From 5440137b58ac4e1ebd6475796338190ebf391216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=20Lepp=C3=A4nen?= Date: Wed, 11 Nov 2020 11:39:53 +0200 Subject: [PATCH] [feature-wisun] Make _unacknowledged_ticks uint32_t to prevent overflow --- platform/source/SysTimer.cpp | 13 +++++++++---- platform/source/SysTimer.h | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/platform/source/SysTimer.cpp b/platform/source/SysTimer.cpp index 0803849e25d..6ebfbf053ea 100644 --- a/platform/source/SysTimer.cpp +++ b/platform/source/SysTimer.cpp @@ -192,10 +192,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(); } } diff --git a/platform/source/SysTimer.h b/platform/source/SysTimer.h index 3098a8e6142..73285a4ffdd 100644 --- a/platform/source/SysTimer.h +++ b/platform/source/SysTimer.h @@ -172,7 +172,7 @@ class SysTimer: private mbed::TimerEvent, private mbed::NonCopyable