Skip to content

Commit 169db54

Browse files
committed
use disable_timer to set a long reload
Also add comments clarifying the now() calls
1 parent eeb1481 commit 169db54

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,23 @@ impl<const TIMER_HZ: u32> Monotonic for DwtSystick<TIMER_HZ> {
124124
Self::Instant::from_ticks(0)
125125
}
126126

127-
#[inline(always)]
128-
fn clear_compare_flag(&mut self) {
129-
// Set a long reload in case `set_compare()` is not called again.
130-
#[cfg(feature = "extend")]
127+
#[cfg(feature = "extend")]
128+
fn disable_timer(&mut self) {
129+
// Do not disable but set a maximum reload value.
131130
self.systick.set_reload(0xff_ffff);
132-
#[cfg(feature = "extend")]
131+
// Also clear the current counter since.
132+
// That doesn't cause a SysTick interrupt and loads the reload
133+
// value on the next cycle.
133134
self.systick.clear_current();
134135
}
135136

136137
#[cfg(feature = "extend")]
137138
fn on_interrupt(&mut self) {
138139
// Ensure `now()` is called regularly to track overflows.
139140
// Since SysTick is narrower than CYCCNT, this is sufficient.
141+
// TODO: check whether this could be moved to `disable_timer()`
142+
// as that's the complementary code branch to `set_compare()`
143+
// (which already calls `now()`).
140144
self.now();
141145
}
142146
}

0 commit comments

Comments
 (0)