Skip to content

Commit 23be86d

Browse files
committed
fix overflow detection, document feature
1 parent 406a283 commit 23be86d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use rtic_monotonic::Monotonic;
1717
///
1818
/// Note that the SysTick interrupt must not be disabled longer than half the
1919
/// cycle counter overflow period (typically a couple seconds).
20+
///
21+
/// When the `extend` feature is enabled, the cycle counter width is extended to
22+
/// `u64` by detecting and counting overflows.
2023
pub struct DwtSystick<const TIMER_HZ: u32> {
2124
dwt: DWT,
2225
systick: SYST,
@@ -76,7 +79,7 @@ impl<const TIMER_HZ: u32> Monotonic for DwtSystick<TIMER_HZ> {
7679
let now = self.dwt.cyccnt.read();
7780

7881
// Detect CYCCNT overflow
79-
if now.wrapping_sub(low) >= 1 << 31 {
82+
if now < low {
8083
high = high.wrapping_add(1);
8184
}
8285
self.last = ((high as u64) << 32) | (now as u64);

0 commit comments

Comments
 (0)