diff options
| author | ivmarkov <[email protected]> | 2022-10-24 11:10:59 +0300 |
|---|---|---|
| committer | ivmarkov <[email protected]> | 2022-10-24 11:10:59 +0300 |
| commit | f78c706b89feed71a7e0a3eaf332f55813698c7f (patch) | |
| tree | 391d9421741a988c461335876eaa4a51e0225c8b /embassy-nrf/src | |
| parent | 4d5550070fe5e80ff2296a71239c568c774b9ceb (diff) | |
Address review feedback
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/time_driver.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index 0d03ad529..bc2c8a3c1 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs | |||
| @@ -245,19 +245,23 @@ impl Driver for RtcDriver { | |||
| 245 | 245 | ||
| 246 | fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool { | 246 | fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool { |
| 247 | critical_section::with(|cs| { | 247 | critical_section::with(|cs| { |
| 248 | let t = self.now(); | ||
| 249 | |||
| 250 | // If alarm timestamp has passed don't set the alarm and return `false` to indicate that. | ||
| 251 | if timestamp <= t { | ||
| 252 | return false; | ||
| 253 | } | ||
| 254 | |||
| 255 | let n = alarm.id() as _; | 248 | let n = alarm.id() as _; |
| 256 | let alarm = self.get_alarm(cs, alarm); | 249 | let alarm = self.get_alarm(cs, alarm); |
| 257 | alarm.timestamp.set(timestamp); | 250 | alarm.timestamp.set(timestamp); |
| 258 | 251 | ||
| 259 | let r = rtc(); | 252 | let r = rtc(); |
| 260 | 253 | ||
| 254 | let t = self.now(); | ||
| 255 | if timestamp <= t { | ||
| 256 | // If alarm timestamp has passed the alarm will not fire. | ||
| 257 | // Disarm the alarm and return `false` to indicate that. | ||
| 258 | r.intenclr.write(|w| unsafe { w.bits(compare_n(n)) }); | ||
| 259 | |||
| 260 | alarm.timestamp.set(u64::MAX); | ||
| 261 | |||
| 262 | return false; | ||
| 263 | } | ||
| 264 | |||
| 261 | // If it hasn't triggered yet, setup it in the compare channel. | 265 | // If it hasn't triggered yet, setup it in the compare channel. |
| 262 | 266 | ||
| 263 | // Write the CC value regardless of whether we're going to enable it now or not. | 267 | // Write the CC value regardless of whether we're going to enable it now or not. |
