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-monotonics/src/rp2040.rs | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) (limited to 'rtic-monotonics/src/rp2040.rs') diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs index 130c7d3..998b532 100644 --- a/rtic-monotonics/src/rp2040.rs +++ b/rtic-monotonics/src/rp2040.rs @@ -28,7 +28,7 @@ use super::Monotonic; pub use super::{TimeoutError, TimerQueue}; use core::future::Future; -pub use fugit::{self, ExtU64}; +pub use fugit::{self, ExtU64, ExtU64Ceil}; use rp2040_pac::{timer, Interrupt, NVIC, RESETS, TIMER}; /// Timer implementing [`Monotonic`] which runs at 1 MHz. @@ -104,6 +104,7 @@ impl Monotonic for Timer { type Duration = fugit::TimerDurationU64<1_000_000>; const ZERO: Self::Instant = Self::Instant::from_ticks(0); + const TICK_PERIOD: Self::Duration = Self::Duration::from_ticks(1); fn now() -> Self::Instant { let timer = Self::timer(); @@ -151,23 +152,10 @@ impl Monotonic for Timer { fn disable_timer() {} } -#[cfg(feature = "embedded-hal-async")] -impl embedded_hal_async::delay::DelayUs for Timer { - async fn delay_us(&mut self, us: u32) { - Self::delay((us as u64).micros()).await; - } - - async fn delay_ms(&mut self, ms: u32) { - Self::delay((ms as u64).millis()).await; - } -} +rtic_time::embedded_hal_delay_impl_fugit64!(Timer); -impl embedded_hal::delay::DelayUs for Timer { - fn delay_us(&mut self, us: u32) { - let done = Self::now() + u64::from(us).micros(); - while Self::now() < done {} - } -} +#[cfg(feature = "embedded-hal-async")] +rtic_time::embedded_hal_async_delay_impl_fugit64!(Timer); /// Register the Timer interrupt for the monotonic. #[macro_export] -- cgit v1.2.3