diff options
| author | David Hoelscher <infinityis@users.noreply.github.com> | 2025-01-02 01:11:10 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-01 23:11:10 -0800 |
| commit | c53d02d511ef9c3b42097123749895a91536bcdd (patch) | |
| tree | 5a994248174086f9f2bf9eb9d06a1755c82c3243 /platforms | |
| parent | cf975e2bfa9fc5315cff1eb82498e7184a87feb1 (diff) | |
Ensure timer_read() is safe to call from interrupt handlers on ARM (#24529)
Diffstat (limited to 'platforms')
| -rw-r--r-- | platforms/chibios/timer.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/platforms/chibios/timer.c b/platforms/chibios/timer.c index 4a347b445d..a07cf5714f 100644 --- a/platforms/chibios/timer.c +++ b/platforms/chibios/timer.c | |||
| @@ -99,7 +99,7 @@ uint16_t timer_read(void) { | |||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | uint32_t timer_read32(void) { | 101 | uint32_t timer_read32(void) { |
| 102 | chSysLock(); | 102 | syssts_t sts = chSysGetStatusAndLockX(); |
| 103 | uint32_t ticks = get_system_time_ticks() - ticks_offset; | 103 | uint32_t ticks = get_system_time_ticks() - ticks_offset; |
| 104 | if (ticks < last_ticks) { | 104 | if (ticks < last_ticks) { |
| 105 | // The 32-bit tick counter overflowed and wrapped around. We cannot just extend the counter to 64 bits here, | 105 | // The 32-bit tick counter overflowed and wrapped around. We cannot just extend the counter to 64 bits here, |
| @@ -114,7 +114,7 @@ uint32_t timer_read32(void) { | |||
| 114 | } | 114 | } |
| 115 | last_ticks = ticks; | 115 | last_ticks = ticks; |
| 116 | uint32_t ms_offset_copy = ms_offset; // read while still holding the lock to ensure a consistent value | 116 | uint32_t ms_offset_copy = ms_offset; // read while still holding the lock to ensure a consistent value |
| 117 | chSysUnlock(); | 117 | chSysRestoreStatusX(sts); |
| 118 | 118 | ||
| 119 | return (uint32_t)TIME_I2MS(ticks) + ms_offset_copy; | 119 | return (uint32_t)TIME_I2MS(ticks) + ms_offset_copy; |
| 120 | } | 120 | } |
