From e4d9284e258a34b10cac2eff47ca2ccb470b460c Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 11 Mar 2023 20:47:39 +0100 Subject: rtic-monotonics: Add interrupt tokens to make sure users bind interrupts --- rtic-monotonics/src/rp2040.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'rtic-monotonics/src/rp2040.rs') 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, + ) { 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 + for Rp2040Token + { + } + + Rp2040Token + } }; } -- cgit v1.2.3