diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-04 20:03:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-04 20:03:58 +0000 |
| commit | 72ae46083e64acc012c6b85d3ef7a115657a01e3 (patch) | |
| tree | 024dbdb94cb5537312c5c34f121257265c165bea /rtic-monotonics/src/rp2040.rs | |
| parent | 064cf19265f72d7f01e0847c545e6250391a2172 (diff) | |
| parent | aeec8bd41bdf3d57098902407ec320f59365641a (diff) | |
Merge #721
721: Added nRF monotonics r=perlindgren a=korken89
Testing completed
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'rtic-monotonics/src/rp2040.rs')
| -rw-r--r-- | rtic-monotonics/src/rp2040.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs index 9d2f4f3..c656afc 100644 --- a/rtic-monotonics/src/rp2040.rs +++ b/rtic-monotonics/src/rp2040.rs @@ -1,4 +1,28 @@ //! A monotonic implementation for RP2040's Timer peripheral. +//! +//! # Example +//! +//! ``` +//! use rtic_monotonics::rp2040::*; +//! +//! 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); +//! } +//! +//! async fn usage() { +//! loop { +//! // Use the monotonic +//! Timer::delay(100.millis()).await; +//! } +//! } +//! ``` use super::Monotonic; pub use super::{TimeoutError, TimerQueue}; @@ -22,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 { @@ -41,6 +68,7 @@ impl Timer { } /// Timeout at a specific time. + #[inline] pub async fn timeout_at<F: Future>( instant: <Self as Monotonic>::Instant, future: F, @@ -64,6 +92,7 @@ impl Timer { } /// Delay to some specific time instant. + #[inline] pub async fn delay_until(instant: <Self as Monotonic>::Instant) { TIMER_QUEUE.delay_until(instant).await; } |
