Change time Driver contract to never fire the alarm synchronously

This commit is contained in:
ivmarkov
2022-10-24 09:17:43 +03:00
parent 53608a87ac
commit 4d5550070f
8 changed files with 113 additions and 117 deletions

View File

@ -243,20 +243,19 @@ impl Driver for RtcDriver {
})
}
fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) {
fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool {
critical_section::with(|cs| {
let t = self.now();
// If alarm timestamp has passed don't set the alarm and return `false` to indicate that.
if timestamp <= t {
return false;
}
let n = alarm.id() as _;
let alarm = self.get_alarm(cs, alarm);
alarm.timestamp.set(timestamp);
let t = self.now();
// If alarm timestamp has passed, trigger it instantly.
if timestamp <= t {
self.trigger_alarm(n, cs);
return;
}
let r = rtc();
// If it hasn't triggered yet, setup it in the compare channel.
@ -287,6 +286,8 @@ impl Driver for RtcDriver {
// It will be setup later by `next_period`.
r.intenclr.write(|w| unsafe { w.bits(compare_n(n)) });
}
true
})
}
}