mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-23 20:51:31 +11:00
Merge pull request #263 from WeirdConstructor/fix_alarm_schedule_race_cond
Fix alarm schedule race condition
This commit is contained in:
commit
d3c9c3b4e2
|
@ -249,17 +249,19 @@ macro_rules! impl_alarm {
|
||||||
if duration < MIN_MICROSECONDS {
|
if duration < MIN_MICROSECONDS {
|
||||||
return Err(ScheduleAlarmError::AlarmTooSoon);
|
return Err(ScheduleAlarmError::AlarmTooSoon);
|
||||||
} else {
|
} else {
|
||||||
// safety: This is a read action and should not have any UB
|
cortex_m::interrupt::free(|_| {
|
||||||
let target_time = unsafe { &*TIMER::ptr() }
|
// safety: This is a read action and should not have any UB
|
||||||
.timelr
|
let target_time = unsafe { &*TIMER::ptr() }
|
||||||
.read()
|
.timelr
|
||||||
.bits()
|
.read()
|
||||||
.wrapping_add(duration);
|
.bits()
|
||||||
|
.wrapping_add(duration);
|
||||||
|
|
||||||
// safety: This is the only code in the codebase that accesses memory address $timer_alarm
|
// safety: This is the only code in the codebase that accesses memory address $timer_alarm
|
||||||
unsafe { &*TIMER::ptr() }
|
unsafe { &*TIMER::ptr() }
|
||||||
.$timer_alarm
|
.$timer_alarm
|
||||||
.write(|w| unsafe { w.bits(target_time) });
|
.write(|w| unsafe { w.bits(target_time) });
|
||||||
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue