Skip to content

Commit

Permalink
fix monotonics
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Oct 25, 2024
1 parent ff78db4 commit a7b2970
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

- Fix pac `defmt` feature
- Fix timer interrupt status clear

## [v0.22.0] - 2024-10-04

Expand Down
20 changes: 16 additions & 4 deletions src/timer/monotonics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ macro_rules! make_timer {

// The above line raises an update event which will indicate that the timer is already finished.
// Since this is not the case, it should be cleared.
self.tim.sr().modify(|_, w| w.uif().clear_bit());
self.tim.sr().write(|w| {
unsafe { w.bits(!0) };
w.uif().clear_bit()
});

$tq.initialize(MonoTimerBackend::<pac::$timer> { _tim: PhantomData });
$overflow.store(0, Ordering::SeqCst);
Expand Down Expand Up @@ -231,7 +234,10 @@ macro_rules! make_timer {
}

fn clear_compare_flag() {
Self::tim().sr().modify(|_, w| w.cc2if().clear_bit());
Self::tim().sr().write(|w| {
unsafe { w.bits(!0) };
w.cc2if().clear_bit()
});
}

fn pend_interrupt() {
Expand All @@ -249,13 +255,19 @@ macro_rules! make_timer {
fn on_interrupt() {
// Full period
if Self::tim().sr().read().uif().bit_is_set() {
Self::tim().sr().modify(|_, w| w.uif().clear_bit());
Self::tim().sr().write(|w| {
unsafe { w.bits(!0) };
w.uif().clear_bit()
});
let prev = $overflow.fetch_add(1, Ordering::Relaxed);
assert!(prev % 2 == 1, "Monotonic must have missed an interrupt!");
}
// Half period
if Self::tim().sr().read().cc1if().bit_is_set() {
Self::tim().sr().modify(|_, w| w.cc1if().clear_bit());
Self::tim().sr().write(|w| {
unsafe { w.bits(!0) };
w.cc1if().clear_bit()
});
let prev = $overflow.fetch_add(1, Ordering::Relaxed);
assert!(prev % 2 == 0, "Monotonic must have missed an interrupt!");
}
Expand Down

0 comments on commit a7b2970

Please sign in to comment.