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/systick.rs | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'rtic-monotonics/src/systick.rs') diff --git a/rtic-monotonics/src/systick.rs b/rtic-monotonics/src/systick.rs index 265ca9a..9bd056c 100644 --- a/rtic-monotonics/src/systick.rs +++ b/rtic-monotonics/src/systick.rs @@ -40,11 +40,11 @@ use cortex_m::peripheral::SYST; pub use fugit; cfg_if::cfg_if! { if #[cfg(feature = "systick-64bit")] { - pub use fugit::ExtU64; + pub use fugit::{ExtU64, ExtU64Ceil}; use atomic_polyfill::AtomicU64; static SYSTICK_CNT: AtomicU64 = AtomicU64::new(0); } else { - pub use fugit::ExtU32; + pub use fugit::{ExtU32, ExtU32Ceil}; use atomic_polyfill::AtomicU32; static SYSTICK_CNT: AtomicU32 = AtomicU32::new(0); } @@ -156,6 +156,7 @@ impl Monotonic for Systick { } const ZERO: Self::Instant = Self::Instant::from_ticks(0); + const TICK_PERIOD: Self::Duration = Self::Duration::from_ticks(1); fn now() -> Self::Instant { if Self::systick().has_wrapped() { @@ -188,27 +189,17 @@ impl Monotonic for Systick { fn disable_timer() {} } -#[cfg(feature = "embedded-hal-async")] -impl embedded_hal_async::delay::DelayUs for Systick { - async fn delay_us(&mut self, us: u32) { - #[cfg(feature = "systick-64bit")] - let us = u64::from(us); - Self::delay(us.micros()).await; - } +cfg_if::cfg_if! { + if #[cfg(feature = "systick-64bit")] { + rtic_time::embedded_hal_delay_impl_fugit64!(Systick); - async fn delay_ms(&mut self, ms: u32) { - #[cfg(feature = "systick-64bit")] - let ms = u64::from(ms); - Self::delay(ms.millis()).await; - } -} + #[cfg(feature = "embedded-hal-async")] + rtic_time::embedded_hal_async_delay_impl_fugit64!(Systick); + } else { + rtic_time::embedded_hal_delay_impl_fugit32!(Systick); -impl embedded_hal::delay::DelayUs for Systick { - fn delay_us(&mut self, us: u32) { - #[cfg(feature = "systick-64bit")] - let us = u64::from(us); - let done = Self::now() + us.micros(); - while Self::now() < done {} + #[cfg(feature = "embedded-hal-async")] + rtic_time::embedded_hal_async_delay_impl_fugit32!(Systick); } } -- cgit v1.2.3