aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivmarkov <[email protected]>2022-10-24 11:10:59 +0300
committerivmarkov <[email protected]>2022-10-24 11:10:59 +0300
commitf78c706b89feed71a7e0a3eaf332f55813698c7f (patch)
tree391d9421741a988c461335876eaa4a51e0225c8b
parent4d5550070fe5e80ff2296a71239c568c774b9ceb (diff)
Address review feedback
-rw-r--r--embassy-nrf/src/time_driver.rs18
-rw-r--r--embassy-rp/src/timer.rs20
-rw-r--r--embassy-stm32/src/time_driver.rs18
3 files changed, 34 insertions, 22 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.
diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs
index 8f280f550..80efd779f 100644
--- a/embassy-rp/src/timer.rs
+++ b/embassy-rp/src/timer.rs
@@ -71,13 +71,6 @@ impl Driver for TimerDriver {
71 fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool { 71 fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool {
72 let n = alarm.id() as usize; 72 let n = alarm.id() as usize;
73 critical_section::with(|cs| { 73 critical_section::with(|cs| {
74 let now = self.now();
75
76 // If alarm timestamp has passed don't set the alarm and return `false` to indicate that.
77 if timestamp <= now {
78 return false;
79 }
80
81 let alarm = &self.alarms.borrow(cs)[n]; 74 let alarm = &self.alarms.borrow(cs)[n];
82 alarm.timestamp.set(timestamp); 75 alarm.timestamp.set(timestamp);
83 76
@@ -87,7 +80,18 @@ impl Driver for TimerDriver {
87 // it is checked if the alarm time has passed. 80 // it is checked if the alarm time has passed.
88 unsafe { pac::TIMER.alarm(n).write_value(timestamp as u32) }; 81 unsafe { pac::TIMER.alarm(n).write_value(timestamp as u32) };
89 82
90 true 83 let now = self.now();
84 if timestamp <= now {
85 // If alarm timestamp has passed the alarm will not fire.
86 // Disarm the alarm and return `false` to indicate that.
87 unsafe { pac::TIMER.armed().write(|w| w.set_armed(1 << n)) }
88
89 alarm.timestamp.set(u64::MAX);
90
91 false
92 } else {
93 true
94 }
91 }) 95 })
92 } 96 }
93} 97}
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs
index e4c266e7f..ab55cc081 100644
--- a/embassy-stm32/src/time_driver.rs
+++ b/embassy-stm32/src/time_driver.rs
@@ -294,19 +294,23 @@ impl Driver for RtcDriver {
294 294
295 fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool { 295 fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) -> bool {
296 critical_section::with(|cs| { 296 critical_section::with(|cs| {
297 let t = self.now();
298
299 // If alarm timestamp has passed don't set the alarm and return `false` to indicate that.
300 if timestamp <= t {
301 return false;
302 }
303
304 let r = T::regs_gp16(); 297 let r = T::regs_gp16();
305 298
306 let n = alarm.id() as _; 299 let n = alarm.id() as _;
307 let alarm = self.get_alarm(cs, alarm); 300 let alarm = self.get_alarm(cs, alarm);
308 alarm.timestamp.set(timestamp); 301 alarm.timestamp.set(timestamp);
309 302
303 let t = self.now();
304 if timestamp <= t {
305 // If alarm timestamp has passed the alarm will not fire.
306 // Disarm the alarm and return `false` to indicate that.
307 unsafe { r.dier().modify(|w| w.set_ccie(n + 1, false)) };
308
309 alarm.timestamp.set(u64::MAX);
310
311 return false;
312 }
313
310 let safe_timestamp = timestamp.max(t + 3); 314 let safe_timestamp = timestamp.max(t + 3);
311 315
312 // Write the CCR value regardless of whether we're going to enable it now or not. 316 // Write the CCR value regardless of whether we're going to enable it now or not.