From a2f153249f926876e7169016f3dc8e861a9ef065 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 1 Apr 2023 20:48:23 +0200 Subject: Added nRF monotonics --- rtic-monotonics/src/rp2040.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'rtic-monotonics/src/rp2040.rs') diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs index 9d2f4f3..5e880cd 100644 --- a/rtic-monotonics/src/rp2040.rs +++ b/rtic-monotonics/src/rp2040.rs @@ -1,4 +1,25 @@ //! A monotonic implementation for RP2040's Timer peripheral. +//! +//! # Example +//! +//! ``` +//! use rtic_monotonics::rp2040::*; +//! +//! # async fn usage() { +//! # let timer = unsafe { core::mem::transmute(()) }; +//! # let mut resets = unsafe { core::mem::transmute(()) }; +//! // Generate the required token +//! let token = rtic_monotonics::create_rp2040_monotonic_token!(); +//! +//! // Start the monotonic +//! Timer::start(timer, &mut resets, token); +//! +//! loop { +//! // Use the monotonic +//! Timer::delay(100.millis()).await; +//! } +//! # } +//! ``` use super::Monotonic; pub use super::{TimeoutError, TimerQueue}; @@ -41,6 +62,7 @@ impl Timer { } /// Timeout at a specific time. + #[inline] pub async fn timeout_at( instant: ::Instant, future: F, @@ -64,6 +86,7 @@ impl Timer { } /// Delay to some specific time instant. + #[inline] pub async fn delay_until(instant: ::Instant) { TIMER_QUEUE.delay_until(instant).await; } -- cgit v1.2.3 From aeec8bd41bdf3d57098902407ec320f59365641a Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 2 Apr 2023 20:32:10 +0200 Subject: Add setting of priority to interrupts --- rtic-monotonics/src/rp2040.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'rtic-monotonics/src/rp2040.rs') diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs index 5e880cd..c656afc 100644 --- a/rtic-monotonics/src/rp2040.rs +++ b/rtic-monotonics/src/rp2040.rs @@ -5,20 +5,23 @@ //! ``` //! use rtic_monotonics::rp2040::*; //! -//! # async fn usage() { -//! # let timer = unsafe { core::mem::transmute(()) }; -//! # let mut resets = unsafe { core::mem::transmute(()) }; -//! // Generate the required token -//! let token = rtic_monotonics::create_rp2040_monotonic_token!(); +//! fn init() { +//! # // This is normally provided by the selected PAC +//! # let timer = unsafe { core::mem::transmute(()) }; +//! # let mut resets = unsafe { core::mem::transmute(()) }; +//! // Generate the required token +//! let token = rtic_monotonics::create_rp2040_monotonic_token!(); //! -//! // Start the monotonic -//! Timer::start(timer, &mut resets, token); +//! // Start the monotonic +//! Timer::start(timer, &mut resets, token); +//! } //! -//! loop { -//! // Use the monotonic -//! Timer::delay(100.millis()).await; +//! async fn usage() { +//! loop { +//! // Use the monotonic +//! Timer::delay(100.millis()).await; +//! } //! } -//! # } //! ``` use super::Monotonic; @@ -43,7 +46,10 @@ impl Timer { TIMER_QUEUE.initialize(Self {}); - unsafe { NVIC::unmask(Interrupt::TIMER_IRQ_0) }; + unsafe { + crate::set_monotonic_prio(rp2040_pac::NVIC_PRIO_BITS, Interrupt::TIMER_IRQ_0); + NVIC::unmask(Interrupt::TIMER_IRQ_0); + } } fn timer() -> &'static timer::RegisterBlock { -- cgit v1.2.3