mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-16 21:01:31 +00:00
ensure calls to timer_read from interrupts are safe
This commit is contained in:
parent
22e6a8d15e
commit
1b6d41c398
@ -78,7 +78,7 @@ uint16_t timer_read(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timer_read32(void) {
|
uint32_t timer_read32(void) {
|
||||||
chSysLock();
|
syssts_t sts = chSysGetStatusAndLockX();
|
||||||
uint32_t ticks = get_system_time_ticks() - ticks_offset;
|
uint32_t ticks = get_system_time_ticks() - ticks_offset;
|
||||||
if (ticks < last_ticks) {
|
if (ticks < last_ticks) {
|
||||||
// The 32-bit tick counter overflowed and wrapped around. We cannot just extend the counter to 64 bits here,
|
// 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;
|
last_ticks = ticks;
|
||||||
uint32_t ms_offset_copy = ms_offset; // read while still holding the lock to ensure a consistent value
|
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;
|
return (uint32_t)TIME_I2MS(ticks) + ms_offset_copy;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user