From 5a11a90bd91892d783c1dfb679bfe6f3eb3444a7 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 24 Jan 2023 12:34:11 +0100 Subject: [PATCH] Systick runs at 1 kHz --- rtic-monotonics/src/systick_monotonic.rs | 25 ++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/rtic-monotonics/src/systick_monotonic.rs b/rtic-monotonics/src/systick_monotonic.rs index 7c713b6108..af17f937fe 100644 --- a/rtic-monotonics/src/systick_monotonic.rs +++ b/rtic-monotonics/src/systick_monotonic.rs @@ -10,11 +10,12 @@ use cortex_m::peripheral::SYST; use embedded_hal_async::delay::DelayUs; use fugit::ExtU32; -/// Systick implementing `rtic_monotonic::Monotonic` which runs at a -/// settable rate using the `TIMER_HZ` parameter. -pub struct Systick; +const TIMER_HZ: u32 = 1_000; -impl Systick { +/// Systick implementing `rtic_monotonic::Monotonic` which runs at 1 kHz. +pub struct Systick; + +impl Systick { /// Start a `Monotonic` based on SysTick. /// /// The `sysclk` parameter is the speed at which SysTick runs at. This value should come from @@ -49,7 +50,7 @@ impl Systick { static SYSTICK_CNT: AtomicU32 = AtomicU32::new(0); -impl Monotonic for Systick { +impl Monotonic for Systick { type Instant = fugit::TimerInstantU32; type Duration = fugit::TimerDurationU32; @@ -87,17 +88,17 @@ impl Monotonic for Systick { } /// Timer queue wrapper to implement traits on -pub struct SystickTimerQueue(TimerQueue>); +pub struct SystickTimerQueue(TimerQueue); -impl SystickTimerQueue { +impl SystickTimerQueue { /// Create a new timer queue. pub const fn new() -> Self { Self(TimerQueue::new()) } } -impl Deref for SystickTimerQueue { - type Target = TimerQueue>; +impl Deref for SystickTimerQueue { + type Target = TimerQueue; #[inline(always)] fn deref(&self) -> &Self::Target { @@ -105,7 +106,7 @@ impl Deref for SystickTimerQueue { } } -impl DelayUs for SystickTimerQueue { +impl DelayUs for SystickTimerQueue { type Error = core::convert::Infallible; async fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { @@ -122,8 +123,8 @@ impl DelayUs for SystickTimerQueue { /// Register the Systick interrupt and crate a timer queue with a specific name and speed. #[macro_export] macro_rules! make_systick_timer_queue { - ($timer_queue_name:ident, $systick_speed:expr) => { - static $timer_queue_name: SystickTimerQueue<$systick_speed> = SystickTimerQueue::new(); + ($timer_queue_name:ident) => { + static $timer_queue_name: SystickTimerQueue = SystickTimerQueue::new(); #[no_mangle] #[allow(non_snake_case)]