Skip to content

Commit

Permalink
[MERGE] Ensure timer_read() is safe to call from interrupt handlers o…
Browse files Browse the repository at this point in the history
…n ARM (24592)
  • Loading branch information
drashna committed Nov 8, 2024
1 parent 2690082 commit b05dd2e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions platforms/chibios/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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,
Expand All @@ -114,7 +114,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;
}
Expand Down

0 comments on commit b05dd2e

Please sign in to comment.