aboutsummaryrefslogtreecommitdiff
path: root/rtic-monotonics/src/rp2040.rs
diff options
context:
space:
mode:
authorEmil Fresk <emil.fresk@gmail.com>2023-03-11 20:47:39 +0100
committerEmil Fresk <emil.fresk@gmail.com>2023-03-11 20:59:26 +0100
commite4d9284e258a34b10cac2eff47ca2ccb470b460c (patch)
treeea1895b33480484bbc44771efdff33c7e5b6dd25 /rtic-monotonics/src/rp2040.rs
parent7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b (diff)
rtic-monotonics: Add interrupt tokens to make sure users bind interrupts
Diffstat (limited to 'rtic-monotonics/src/rp2040.rs')
-rw-r--r--rtic-monotonics/src/rp2040.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/rtic-monotonics/src/rp2040.rs b/rtic-monotonics/src/rp2040.rs
index e42c148..039b117 100644
--- a/rtic-monotonics/src/rp2040.rs
+++ b/rtic-monotonics/src/rp2040.rs
@@ -4,14 +4,18 @@ use super::Monotonic;
pub use super::{TimeoutError, TimerQueue};
use core::future::Future;
pub use fugit::ExtU64;
-use rp2040_pac::{timer, Interrupt, RESETS, TIMER};
+use rp2040_pac::{timer, Interrupt, NVIC, RESETS, TIMER};
/// Timer implementing `rtic_monotonic::Monotonic` which runs at 1 MHz.
pub struct Timer;
impl Timer {
/// Start a `Monotonic` based on RP2040's Timer.
- pub fn start(timer: TIMER, resets: &mut RESETS) {
+ pub fn start(
+ timer: TIMER,
+ resets: &mut RESETS,
+ _interrupt_token: impl crate::InterruptToken<Self>,
+ ) {
resets.reset.modify(|_, w| w.timer().clear_bit());
while resets.reset_done.read().timer().bit_is_clear() {}
timer.inte.modify(|_, w| w.alarm_0().set_bit());
@@ -134,10 +138,21 @@ impl embedded_hal_async::delay::DelayUs for Timer {
#[macro_export]
macro_rules! make_rp2040_monotonic_handler {
() => {
+ {
#[no_mangle]
#[allow(non_snake_case)]
unsafe extern "C" fn TIMER_IRQ_0() {
rtic_monotonics::rp2040::Timer::__tq().on_monotonic_interrupt();
}
+
+ pub struct Rp2040Token;
+
+ unsafe impl rtic_monotonics::InterruptToken<rtic_monotonics::rp2040::Timer>
+ for Rp2040Token
+ {
+ }
+
+ Rp2040Token
+ }
};
}