Skip to content

Commit

Permalink
[nfc] refactor set_compare to be more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Feb 4, 2022
1 parent 1c8dec5 commit eeb1481
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ impl<const TIMER_HZ: u32> Monotonic for DwtSystick<TIMER_HZ> {
// We need to convert into its domain.
let now = self.now();

let max = 0x00ff_ffff;

let dur = match val.checked_duration_since(now) {
None => 1, // In the past

let reload = val
.checked_duration_since(now)
// Minimum reload value if `val` is in the past
.map_or(0, |t| t.ticks())
// ARM Architecture Reference Manual says:
// "Setting SYST_RVR to zero has the effect of
// disabling the SysTick counter independently
// of the counter enable bit.", so the min is 1
Some(x) => max.min(x.ticks()).max(1),
};
.max(1)
// SysTick is a 24 bit counter.
.min(0xff_ffff) as u32;

self.systick.set_reload(dur as u32);
self.systick.set_reload(reload);
self.systick.clear_current();
}

Expand Down

0 comments on commit eeb1481

Please sign in to comment.