aboutsummaryrefslogtreecommitdiff
path: root/rtic-monotonics/src/nrf
diff options
context:
space:
mode:
Diffstat (limited to 'rtic-monotonics/src/nrf')
-rw-r--r--rtic-monotonics/src/nrf/rtc.rs31
-rw-r--r--rtic-monotonics/src/nrf/timer.rs31
2 files changed, 40 insertions, 22 deletions
diff --git a/rtic-monotonics/src/nrf/rtc.rs b/rtic-monotonics/src/nrf/rtc.rs
index 724c477..03610c0 100644
--- a/rtic-monotonics/src/nrf/rtc.rs
+++ b/rtic-monotonics/src/nrf/rtc.rs
@@ -5,19 +5,22 @@
//! ```
//! use rtic_monotonics::nrf::rtc::*;
//!
-//! # async fn usage() {
-//! # let rtc = unsafe { core::mem::transmute(()) };
-//! // Generate the required token
-//! let token = rtic_monotonics::create_nrf_rtc0_monotonic_token!();
+//! fn init() {
+//! # // This is normally provided by the selected PAC
+//! # let rtc = unsafe { core::mem::transmute(()) };
+//! // Generate the required token
+//! let token = rtic_monotonics::create_nrf_rtc0_monotonic_token!();
//!
-//! // Start the monotonic
-//! Rtc0::start(rtc, token);
+//! // Start the monotonic
+//! Rtc0::start(rtc, token);
+//! }
//!
-//! loop {
-//! // Use the monotonic
-//! Rtc0::delay(100.millis()).await;
+//! async fn usage() {
+//! loop {
+//! // Use the monotonic
+//! Rtc0::delay(100.millis()).await;
+//! }
//! }
-//! # }
//! ```
#[cfg(feature = "nrf52810")]
@@ -106,7 +109,13 @@ macro_rules! make_rtc {
$tq.initialize(Self {});
- unsafe { pac::NVIC::unmask(Interrupt::$rtc) };
+ // SAFETY: We take full ownership of the peripheral and interrupt vector,
+ // plus we are not using any external shared resources so we won't impact
+ // basepri/source masking based critical sections.
+ unsafe {
+ crate::set_monotonic_prio(pac::NVIC_PRIO_BITS, Interrupt::$rtc);
+ pac::NVIC::unmask(Interrupt::$rtc);
+ }
}
/// Used to access the underlying timer queue
diff --git a/rtic-monotonics/src/nrf/timer.rs b/rtic-monotonics/src/nrf/timer.rs
index ad490cc..db5316f 100644
--- a/rtic-monotonics/src/nrf/timer.rs
+++ b/rtic-monotonics/src/nrf/timer.rs
@@ -5,19 +5,22 @@
//! ```
//! use rtic_monotonics::nrf::timer::*;
//!
-//! # async fn usage() {
-//! # let timer = unsafe { core::mem::transmute(()) };
-//! // Generate the required token
-//! let token = rtic_monotonics::create_nrf_timer0_monotonic_token!();
+//! fn init() {
+//! # // This is normally provided by the selected PAC
+//! # let timer = unsafe { core::mem::transmute(()) };
+//! // Generate the required token
+//! let token = rtic_monotonics::create_nrf_timer0_monotonic_token!();
//!
-//! // Start the monotonic
-//! Timer0::start(timer, token);
+//! // Start the monotonic
+//! Timer0::start(timer, token);
+//! }
//!
-//! loop {
-//! // Use the monotonic
-//! Timer0::delay(100.millis()).await;
+//! async fn usage() {
+//! loop {
+//! // Use the monotonic
+//! Timer0::delay(100.millis()).await;
+//! }
//! }
-//! # }
//! ```
use super::super::Monotonic;
@@ -135,7 +138,13 @@ macro_rules! make_timer {
timer.events_compare[0].write(|w| w);
timer.events_compare[1].write(|w| w);
- unsafe { pac::NVIC::unmask(Interrupt::$timer) };
+ // SAFETY: We take full ownership of the peripheral and interrupt vector,
+ // plus we are not using any external shared resources so we won't impact
+ // basepri/source masking based critical sections.
+ unsafe {
+ crate::set_monotonic_prio(pac::NVIC_PRIO_BITS, Interrupt::$timer);
+ pac::NVIC::unmask(Interrupt::$timer);
+ }
}
/// Used to access the underlying timer queue