aboutsummaryrefslogtreecommitdiff
path: root/rtic-time
diff options
context:
space:
mode:
Diffstat (limited to 'rtic-time')
-rw-r--r--rtic-time/CHANGELOG.md2
-rw-r--r--rtic-time/src/lib.rs4
-rw-r--r--rtic-time/src/monotonic.rs7
3 files changed, 11 insertions, 2 deletions
diff --git a/rtic-time/CHANGELOG.md b/rtic-time/CHANGELOG.md
index d3a9d84..3a2fb91 100644
--- a/rtic-time/CHANGELOG.md
+++ b/rtic-time/CHANGELOG.md
@@ -9,6 +9,8 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
### Added
+- `should_dequeue` to the `Monotonic` trait to handle bugged timers
+
### Changed
### Fixed
diff --git a/rtic-time/src/lib.rs b/rtic-time/src/lib.rs
index 78b57a4..9bf1485 100644
--- a/rtic-time/src/lib.rs
+++ b/rtic-time/src/lib.rs
@@ -131,7 +131,7 @@ impl<Mono: Monotonic> TimerQueue<Mono> {
let head = self.queue.pop_if(|head| {
release_at = Some(head.release_at);
- let should_pop = Mono::now() >= head.release_at;
+ let should_pop = Mono::should_dequeue_check(head.release_at);
head.was_poped.store(should_pop, Ordering::Relaxed);
should_pop
@@ -145,7 +145,7 @@ impl<Mono: Monotonic> TimerQueue<Mono> {
Mono::enable_timer();
Mono::set_compare(instant);
- if Mono::now() >= instant {
+ if Mono::should_dequeue_check(instant) {
// The time for the next instant passed while handling it,
// continue dequeueing
continue;
diff --git a/rtic-time/src/monotonic.rs b/rtic-time/src/monotonic.rs
index 9b3742f..513cc07 100644
--- a/rtic-time/src/monotonic.rs
+++ b/rtic-time/src/monotonic.rs
@@ -33,6 +33,13 @@ pub trait Monotonic {
/// queue in RTIC checks this.
fn set_compare(instant: Self::Instant);
+ /// Override for the dequeue check, override with timers that have bugs.
+ ///
+ /// E.g. nRF52 RTCs needs to be dequeued if the time is within 4 ticks.
+ fn should_dequeue_check(release_at: Self::Instant) -> bool {
+ <Self as Monotonic>::now() >= release_at
+ }
+
/// Clear the compare interrupt flag.
fn clear_compare_flag();