diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/cyccnt.rs | 6 | ||||
| -rw-r--r-- | src/tq.rs | 7 |
2 files changed, 11 insertions, 2 deletions
diff --git a/src/cyccnt.rs b/src/cyccnt.rs index 4b12408..6bc2ef0 100644 --- a/src/cyccnt.rs +++ b/src/cyccnt.rs @@ -42,12 +42,14 @@ impl Instant { /// Returns the amount of time elapsed since this instant was created. pub fn elapsed(&self) -> Duration { - Instant::now() - *self + let diff = Instant::now().inner.wrapping_sub(self.inner); + assert!(diff >= 0, "instant now is earlier than self"); + Duration { inner: diff as u32 } } /// Returns the amount of time elapsed from another instant to this one. pub fn duration_since(&self, earlier: Instant) -> Duration { - let diff = self.inner - earlier.inner; + let diff = self.inner.wrapping_sub(earlier.inner); assert!(diff >= 0, "second instant is later than self"); Duration { inner: diff as u32 } } @@ -68,6 +68,13 @@ where .map(|x| x / ratio.denominator) }) { None => MAX, + + // ARM Architecture Reference Manual says: + // "Setting SYST_RVR to zero has the effect of + // disabling the SysTick counter independently + // of the counter enable bit." + Some(0) => 1, + Some(x) => cmp::min(MAX, x), }; mem::transmute::<_, SYST>(()).set_reload(dur); |
