From 612a47ef4d09da3553145d77bf1750314bbb7b16 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Fri, 1 Dec 2023 08:59:22 +0100 Subject: Fix mono delay (#843) * rtic-time: Compenstate for timer uncertainty * Update changelog and incorrect cargo.lock in an example * Fix Monotonic impls * Fix tests * Fix other monotonics, again * Update changelog * Fix example * Fix DelayUs and DelayMs impls * Minor coding style fix in u64 conversions * Fix all changelogs * Fix changelog * Fix blocking DelayUs * Minor monotonic rework * Add delay precision test * Add more tests * Add rust-version tags to Cargo.toml * Fix imxrt, rp2040 and systick timer * Fix more monotonics * Fix systick monotonic * Some reverts * Fix imxrt * Fix nrf * Fix rp2040 * Fix stm32 * Fix systick * Fix rtic-time tests * Bump to e-h.rc2 * Apply e-h.rc2 fixes to rtic-time * Apply fixes from arbiter * Fix clippy warning * Minor beautification * Revert previous changes * Fix variable name * Add blocking tests, but disable them by default --- rtic-time/tests/timer_queue.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'rtic-time/tests/timer_queue.rs') diff --git a/rtic-time/tests/timer_queue.rs b/rtic-time/tests/timer_queue.rs index 9ad7175..8bae385 100644 --- a/rtic-time/tests/timer_queue.rs +++ b/rtic-time/tests/timer_queue.rs @@ -17,7 +17,7 @@ static NOW: Mutex> = Mutex::new(None); pub struct Duration(u64); impl Duration { - pub fn from_ticks(millis: u64) -> Self { + pub const fn from_ticks(millis: u64) -> Self { Self(millis) } @@ -161,6 +161,7 @@ impl TestMono { impl Monotonic for TestMono { const ZERO: Self::Instant = Instant::ZERO; + const TICK_PERIOD: Self::Duration = Duration::from_ticks(1); type Instant = Instant; @@ -210,7 +211,8 @@ fn timer_queue() { let elapsed = start.elapsed().as_ticks(); println!("{total_millis} ticks delay reached after {elapsed} ticks"); - if elapsed != total_millis { + // Expect a delay of one longer, to compensate for timer uncertainty + if elapsed != total_millis + 1 { panic!( "{total_millis} ticks delay was not on time ({elapsed} ticks passed instead)" ); @@ -263,25 +265,25 @@ fn timer_queue() { if Instant::now() == 0.into() { // First, we want to be waiting for our 300 tick delay - assert_eq!(TestMono::compare(), Some(300.into())); + assert_eq!(TestMono::compare(), Some(301.into())); } if Instant::now() == 100.into() { // After 100 ticks, we enqueue a new delay that is supposed to last // until the 200-tick-mark - assert_eq!(TestMono::compare(), Some(200.into())); + assert_eq!(TestMono::compare(), Some(201.into())); } - if Instant::now() == 200.into() { + if Instant::now() == 201.into() { // After 200 ticks, we dequeue the 200-tick-mark delay and // requeue the 300 tick delay - assert_eq!(TestMono::compare(), Some(300.into())); + assert_eq!(TestMono::compare(), Some(301.into())); } - if Instant::now() == 300.into() { + if Instant::now() == 301.into() { // After 300 ticks, we dequeue the 300-tick-mark delay and // go to the 400 tick delay that is already enqueued - assert_eq!(TestMono::compare(), Some(400.into())); + assert_eq!(TestMono::compare(), Some(401.into())); } } -- cgit v1.2.3