From 1b6d41c398a223ab87d7ad5de5be7f04518892e4 Mon Sep 17 00:00:00 2001 From: David Hoelscher Date: Fri, 25 Oct 2024 18:15:19 -0500 Subject: [PATCH] ensure calls to timer_read from interrupts are safe --- platforms/chibios/timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platforms/chibios/timer.c b/platforms/chibios/timer.c index 5e01ea63724..fdfc6e38ede 100644 --- a/platforms/chibios/timer.c +++ b/platforms/chibios/timer.c @@ -78,7 +78,7 @@ uint16_t timer_read(void) { } uint32_t timer_read32(void) { - chSysLock(); + syssts_t sts = chSysGetStatusAndLockX(); uint32_t ticks = get_system_time_ticks() - ticks_offset; if (ticks < last_ticks) { // The 32-bit tick counter overflowed and wrapped around. We cannot just extend the counter to 64 bits here, @@ -93,7 +93,7 @@ uint32_t timer_read32(void) { } last_ticks = ticks; uint32_t ms_offset_copy = ms_offset; // read while still holding the lock to ensure a consistent value - chSysUnlock(); + chSysRestoreStatusX(sts); return (uint32_t)TIME_I2MS(ticks) + ms_offset_copy; }