Skip to content

Commit eeb1481

Browse files
committed
[nfc] refactor set_compare to be more readable
1 parent 1c8dec5 commit eeb1481

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ impl<const TIMER_HZ: u32> Monotonic for DwtSystick<TIMER_HZ> {
103103
// We need to convert into its domain.
104104
let now = self.now();
105105

106-
let max = 0x00ff_ffff;
107-
108-
let dur = match val.checked_duration_since(now) {
109-
None => 1, // In the past
110-
106+
let reload = val
107+
.checked_duration_since(now)
108+
// Minimum reload value if `val` is in the past
109+
.map_or(0, |t| t.ticks())
111110
// ARM Architecture Reference Manual says:
112111
// "Setting SYST_RVR to zero has the effect of
113112
// disabling the SysTick counter independently
114113
// of the counter enable bit.", so the min is 1
115-
Some(x) => max.min(x.ticks()).max(1),
116-
};
114+
.max(1)
115+
// SysTick is a 24 bit counter.
116+
.min(0xff_ffff) as u32;
117117

118-
self.systick.set_reload(dur as u32);
118+
self.systick.set_reload(reload);
119119
self.systick.clear_current();
120120
}
121121

0 commit comments

Comments
 (0)