Address review feedback

This commit is contained in:
ivmarkov
2022-10-24 11:10:59 +03:00
parent 4d5550070f
commit f78c706b89
3 changed files with 34 additions and 22 deletions

View File

@ -245,19 +245,23 @@ impl Driver for RtcDriver {
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 r = rtc();
let t = self.now();
if timestamp <= t {
// If alarm timestamp has passed the alarm will not fire.
// Disarm the alarm and return `false` to indicate that.
r.intenclr.write(|w| unsafe { w.bits(compare_n(n)) });
alarm.timestamp.set(u64::MAX);
return false;
}
// If it hasn't triggered yet, setup it in the compare channel.
// Write the CC value regardless of whether we're going to enable it now or not.