diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index 3a82726df..0e790eaaf 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs @@ -1,10 +1,8 @@ //! Interrupt handling for cortex-m devices. -use core::{mem, ptr}; +use core::mem; +use core::sync::atomic::{compiler_fence, Ordering}; -use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; use cortex_m::peripheral::NVIC; -use embassy_hal_common::Peripheral; -pub use embassy_macros::cortex_m_interrupt_take as take; /// Do not use. Used for macros and HALs only. Not covered by semver guarantees. #[doc(hidden)] @@ -43,22 +41,6 @@ pub trait Handler { /// This allows drivers to check bindings at compile-time. pub unsafe trait Binding> {} -/// Implementation detail, do not use outside embassy crates. -#[doc(hidden)] -pub struct DynHandler { - pub func: AtomicPtr<()>, - pub ctx: AtomicPtr<()>, -} - -impl DynHandler { - pub const fn new() -> Self { - Self { - func: AtomicPtr::new(ptr::null_mut()), - ctx: AtomicPtr::new(ptr::null_mut()), - } - } -} - #[derive(Clone, Copy)] pub(crate) struct NrWrap(pub(crate) u16); unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { @@ -69,144 +51,68 @@ unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { /// Represents an interrupt type that can be configured by embassy to handle /// interrupts. -pub unsafe trait Interrupt: Peripheral

{ +pub unsafe trait Interrupt { /// Return the NVIC interrupt number for this interrupt. - fn number(&self) -> u16; - /// Steal an instance of this interrupt - /// - /// # Safety - /// - /// This may panic if the interrupt has already been stolen and configured. - unsafe fn steal() -> Self; + fn number() -> u16; - /// Implementation detail, do not use outside embassy crates. - #[doc(hidden)] - unsafe fn __handler(&self) -> &'static DynHandler; -} - -/// Represents additional behavior for all interrupts. -pub trait InterruptExt: Interrupt { - /// Configure the interrupt handler for this interrupt. - /// - /// # Safety - /// - /// It is the responsibility of the caller to ensure the handler - /// points to a valid handler as long as interrupts are enabled. - fn set_handler(&self, func: unsafe fn(*mut ())); - - /// Remove the interrupt handler for this interrupt. - fn remove_handler(&self); - - /// Set point to a context that is passed to the interrupt handler when - /// an interrupt is pending. - /// - /// # Safety - /// - /// It is the responsibility of the caller to ensure the context - /// points to a valid handler as long as interrupts are enabled. - fn set_handler_context(&self, ctx: *mut ()); - - /// Enable the interrupt. Once enabled, the interrupt handler may - /// be called "any time". - fn enable(&self); + /// Enable the interrupt. + #[inline] + unsafe fn enable() { + compiler_fence(Ordering::SeqCst); + NVIC::unmask(NrWrap(Self::number())) + } /// Disable the interrupt. - fn disable(&self); + #[inline] + fn disable() { + NVIC::mask(NrWrap(Self::number())); + compiler_fence(Ordering::SeqCst); + } /// Check if interrupt is being handled. + #[inline] #[cfg(not(armv6m))] - fn is_active(&self) -> bool; + fn is_active() -> bool { + NVIC::is_active(NrWrap(Self::number())) + } /// Check if interrupt is enabled. - fn is_enabled(&self) -> bool; + #[inline] + fn is_enabled() -> bool { + NVIC::is_enabled(NrWrap(Self::number())) + } /// Check if interrupt is pending. - fn is_pending(&self) -> bool; + #[inline] + fn is_pending() -> bool { + NVIC::is_pending(NrWrap(Self::number())) + } /// Set interrupt pending. - fn pend(&self); + #[inline] + fn pend() { + NVIC::pend(NrWrap(Self::number())) + } /// Unset interrupt pending. - fn unpend(&self); + #[inline] + fn unpend() { + NVIC::unpend(NrWrap(Self::number())) + } /// Get the priority of the interrupt. - fn get_priority(&self) -> Priority; + #[inline] + fn get_priority() -> Priority { + Priority::from(NVIC::get_priority(NrWrap(Self::number()))) + } /// Set the interrupt priority. - fn set_priority(&self, prio: Priority); -} - -impl InterruptExt for T { - fn set_handler(&self, func: unsafe fn(*mut ())) { - compiler_fence(Ordering::SeqCst); - let handler = unsafe { self.__handler() }; - handler.func.store(func as *mut (), Ordering::Relaxed); - compiler_fence(Ordering::SeqCst); - } - - fn remove_handler(&self) { - compiler_fence(Ordering::SeqCst); - let handler = unsafe { self.__handler() }; - handler.func.store(ptr::null_mut(), Ordering::Relaxed); - compiler_fence(Ordering::SeqCst); - } - - fn set_handler_context(&self, ctx: *mut ()) { - let handler = unsafe { self.__handler() }; - handler.ctx.store(ctx, Ordering::Relaxed); - } - #[inline] - fn enable(&self) { - compiler_fence(Ordering::SeqCst); - unsafe { - NVIC::unmask(NrWrap(self.number())); - } - } - - #[inline] - fn disable(&self) { - NVIC::mask(NrWrap(self.number())); - compiler_fence(Ordering::SeqCst); - } - - #[inline] - #[cfg(not(armv6m))] - fn is_active(&self) -> bool { - NVIC::is_active(NrWrap(self.number())) - } - - #[inline] - fn is_enabled(&self) -> bool { - NVIC::is_enabled(NrWrap(self.number())) - } - - #[inline] - fn is_pending(&self) -> bool { - NVIC::is_pending(NrWrap(self.number())) - } - - #[inline] - fn pend(&self) { - NVIC::pend(NrWrap(self.number())) - } - - #[inline] - fn unpend(&self) { - NVIC::unpend(NrWrap(self.number())) - } - - #[inline] - fn get_priority(&self) -> Priority { - Priority::from(NVIC::get_priority(NrWrap(self.number()))) - } - - #[inline] - fn set_priority(&self, prio: Priority) { - unsafe { + fn set_priority(prio: Priority) { + critical_section::with(|_| unsafe { let mut nvic: cortex_m::peripheral::NVIC = mem::transmute(()); - nvic.set_priority(NrWrap(self.number()), prio.into()) - } + nvic.set_priority(NrWrap(Self::number()), prio.into()) + }) } } diff --git a/embassy-lora/src/iv.rs b/embassy-lora/src/iv.rs index d515bc365..8d521040f 100644 --- a/embassy-lora/src/iv.rs +++ b/embassy-lora/src/iv.rs @@ -22,7 +22,7 @@ pub struct InterruptHandler {} #[cfg(feature = "stm32wl")] impl interrupt::Handler for InterruptHandler { unsafe fn on_interrupt() { - unsafe { SUBGHZ_RADIO::steal() }.disable(); + interrupt::SUBGHZ_RADIO::disable(); IRQ_SIGNAL.signal(()); } } @@ -49,7 +49,7 @@ where rf_switch_rx: Option, rf_switch_tx: Option, ) -> Result { - unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable(); + interrupt::SUBGHZ_RADIO::disable(); Ok(Self { board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board rf_switch_rx, @@ -95,7 +95,7 @@ where } async fn await_irq(&mut self) -> Result<(), RadioError> { - unsafe { interrupt::SUBGHZ_RADIO::steal() }.enable(); + unsafe { interrupt::SUBGHZ_RADIO::enable() }; IRQ_SIGNAL.wait().await; Ok(()) } diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index dc5b519ff..d7ca1f69c 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -169,14 +169,3 @@ pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { let name = syn::parse_macro_input!(item as syn::Ident); cortex_m_interrupt_declare::run(name).unwrap_or_else(|x| x).into() } - -/// # interrupt_take procedural macro -/// -/// core::panic! is used as a default way to panic in this macro as there is no sensible way of enabling/disabling defmt for macro generation. -/// We are aware that this brings bloat in the form of core::fmt, but the bloat is already included with e.g. array indexing panics. -/// To get rid of this bloat, use the compiler flags `-Zbuild-std=core -Zbuild-std-features=panic_immediate_abort`. -#[proc_macro] -pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { - let name = syn::parse_macro_input!(item as syn::Ident); - cortex_m_interrupt_take::run(name).unwrap_or_else(|x| x).into() -} diff --git a/embassy-macros/src/macros/cortex_m_interrupt_declare.rs b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs index 699883efa..b317482f5 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt_declare.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs @@ -3,32 +3,19 @@ use quote::{format_ident, quote}; pub fn run(name: syn::Ident) -> Result { let name = format_ident!("{}", name); - let name_interrupt = format_ident!("{}", name); - let name_handler = format!("__EMBASSY_{}_HANDLER", name); - - let doc = format!("{} interrupt singleton.", name); + let doc = format!("{} interrupt.", name); let result = quote! { #[doc = #doc] #[allow(non_camel_case_types)] - pub struct #name_interrupt(()); - unsafe impl ::embassy_cortex_m::interrupt::Interrupt for #name_interrupt { - fn number(&self) -> u16 { + pub enum #name{} + unsafe impl ::embassy_cortex_m::interrupt::Interrupt for #name { + fn number() -> u16 { use cortex_m::interrupt::InterruptNumber; let irq = InterruptEnum::#name; irq.number() as u16 } - unsafe fn steal() -> Self { - Self(()) - } - unsafe fn __handler(&self) -> &'static ::embassy_cortex_m::interrupt::DynHandler { - #[export_name = #name_handler] - static HANDLER: ::embassy_cortex_m::interrupt::DynHandler = ::embassy_cortex_m::interrupt::DynHandler::new(); - &HANDLER - } } - - ::embassy_hal_common::impl_peripheral!(#name_interrupt); }; Ok(result) } diff --git a/embassy-macros/src/macros/cortex_m_interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs deleted file mode 100644 index 4806d1c12..000000000 --- a/embassy-macros/src/macros/cortex_m_interrupt_take.rs +++ /dev/null @@ -1,57 +0,0 @@ -use proc_macro2::TokenStream; -use quote::{format_ident, quote}; - -pub fn run(name: syn::Ident) -> Result { - let name = format!("{}", name); - let name_interrupt = format_ident!("{}", name); - let name_handler = format!("__EMBASSY_{}_HANDLER", name); - - #[cfg(feature = "rtos-trace-interrupt")] - let (isr_enter, isr_exit) = ( - quote! { - ::embassy_executor::rtos_trace_interrupt! { - ::embassy_executor::_export::trace::isr_enter(); - } - }, - quote! { - ::embassy_executor::rtos_trace_interrupt! { - ::embassy_executor::_export::trace::isr_exit(); - } - }, - ); - - #[cfg(not(feature = "rtos-trace-interrupt"))] - let (isr_enter, isr_exit) = (quote! {}, quote! {}); - - let result = quote! { - { - #[allow(non_snake_case)] - #[export_name = #name] - pub unsafe extern "C" fn trampoline() { - extern "C" { - #[link_name = #name_handler] - static HANDLER: interrupt::DynHandler; - } - - let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed); - let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed); - let func: fn(*mut ()) = ::core::mem::transmute(func); - #isr_enter - - func(ctx); - #isr_exit - - } - - static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false); - - if TAKEN.compare_exchange(false, true, interrupt::_export::atomic::Ordering::AcqRel, interrupt::_export::atomic::Ordering::Acquire).is_err() { - core::panic!("IRQ Already taken"); - } - - let irq: interrupt::#name_interrupt = unsafe { ::core::mem::transmute(()) }; - irq - } - }; - Ok(result) -} diff --git a/embassy-macros/src/macros/mod.rs b/embassy-macros/src/macros/mod.rs index e547736fc..a5e7a50e6 100644 --- a/embassy-macros/src/macros/mod.rs +++ b/embassy-macros/src/macros/mod.rs @@ -1,5 +1,4 @@ pub mod cortex_m_interrupt; pub mod cortex_m_interrupt_declare; -pub mod cortex_m_interrupt_take; pub mod main; pub mod task; diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 4d053c023..b4fe2d874 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -24,7 +24,7 @@ pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Pari use crate::gpio::sealed::Pin; use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; -use crate::interrupt::{self, InterruptExt}; +use crate::interrupt::{self}; use crate::ppi::{ self, AnyConfigurableChannel, AnyGroup, Channel, ConfigurableChannel, Event, Group, Ppi, PpiGroup, Task, }; @@ -362,8 +362,8 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { ppi_ch2.disable(); ppi_group.add_channel(&ppi_ch2); - unsafe { U::Interrupt::steal() }.pend(); - unsafe { U::Interrupt::steal() }.enable(); + U::Interrupt::pend(); + unsafe { U::Interrupt::enable() }; Self { _peri: peri, @@ -375,7 +375,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarte<'d, U, T> { } fn pend_irq() { - unsafe { ::steal() }.pend() + U::Interrupt::pend() } /// Adjust the baud rate to the provided value. diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 66c682b43..2ec5220a7 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -9,7 +9,7 @@ use embassy_sync::waitqueue::AtomicWaker; use crate::gpio::sealed::Pin as _; use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin}; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::ppi::{Event, Task}; use crate::{interrupt, pac, peripherals}; @@ -74,42 +74,38 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) { } // Enable interrupts - cfg_if::cfg_if! { - if #[cfg(any(feature="nrf5340-app-s", feature="nrf9160-s"))] { - let irq = unsafe { interrupt::GPIOTE0::steal() }; - } else if #[cfg(any(feature="nrf5340-app-ns", feature="nrf9160-ns"))] { - let irq = unsafe { interrupt::GPIOTE1::steal() }; - } else { - let irq = unsafe { interrupt::GPIOTE::steal() }; - } - } + #[cfg(any(feature = "nrf5340-app-s", feature = "nrf9160-s"))] + type Irq = interrupt::GPIOTE0; + #[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))] + type Irq = interrupt::GPIOTE1; + #[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))] + type Irq = interrupt::GPIOTE; - irq.unpend(); - irq.set_priority(irq_prio); - irq.enable(); + Irq::unpend(); + Irq::set_priority(irq_prio); + unsafe { Irq::enable() }; let g = regs(); g.events_port.write(|w| w); g.intenset.write(|w| w.port().set()); } -cfg_if::cfg_if! { - if #[cfg(any(feature="nrf5340-app-s", feature="nrf9160-s"))] { - #[interrupt] - fn GPIOTE0() { - unsafe { handle_gpiote_interrupt() }; - } - } else if #[cfg(any(feature="nrf5340-app-ns", feature="nrf9160-ns"))] { - #[interrupt] - fn GPIOTE1() { - unsafe { handle_gpiote_interrupt() }; - } - } else { - #[interrupt] - fn GPIOTE() { - unsafe { handle_gpiote_interrupt() }; - } - } +#[cfg(any(feature = "nrf5340-app-s", feature = "nrf9160-s"))] +#[interrupt] +fn GPIOTE0() { + unsafe { handle_gpiote_interrupt() }; +} + +#[cfg(any(feature = "nrf5340-app-ns", feature = "nrf9160-ns"))] +#[interrupt] +fn GPIOTE1() { + unsafe { handle_gpiote_interrupt() }; +} + +#[cfg(any(feature = "_nrf52", feature = "nrf5340-net"))] +#[interrupt] +fn GPIOTE() { + unsafe { handle_gpiote_interrupt() }; } unsafe fn handle_gpiote_interrupt() { diff --git a/embassy-nrf/src/i2s.rs b/embassy-nrf/src/i2s.rs index 8a1188ce4..13db77d3b 100644 --- a/embassy-nrf/src/i2s.rs +++ b/embassy-nrf/src/i2s.rs @@ -9,7 +9,6 @@ use core::ops::{Deref, DerefMut}; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy_cortex_m::interrupt::InterruptExt; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; @@ -564,8 +563,8 @@ impl<'d, T: Instance> I2S<'d, T> { } fn setup_interrupt(&self) { - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let device = Device::::new(); device.disable_tx_ptr_interrupt(); diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index d4d7a1cad..6b57c2545 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -96,7 +96,7 @@ mod chip; pub mod interrupt { //! Interrupt definitions and macros to bind them. pub use cortex_m::interrupt::{CriticalSection, Mutex}; - pub use embassy_cortex_m::interrupt::{Binding, Handler, Interrupt, InterruptExt, Priority}; + pub use embassy_cortex_m::interrupt::{Binding, Handler, Interrupt, Priority}; pub use crate::chip::irqs::*; diff --git a/embassy-nrf/src/pdm.rs b/embassy-nrf/src/pdm.rs index 8815bb316..9df685a26 100644 --- a/embassy-nrf/src/pdm.rs +++ b/embassy-nrf/src/pdm.rs @@ -14,7 +14,7 @@ use futures::future::poll_fn; use crate::chip::EASY_DMA_SIZE; use crate::gpio::sealed::Pin; use crate::gpio::{AnyPin, Pin as GpioPin}; -use crate::interrupt::{self, InterruptExt}; +use crate::interrupt::{self}; use crate::Peripheral; /// Interrupt handler. @@ -94,8 +94,8 @@ impl<'d, T: Instance> Pdm<'d, T> { r.gainr.write(|w| w.gainr().default_gain()); // IRQ - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; r.enable.write(|w| w.enable().set_bit()); diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index c845492fc..5761d04e1 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs @@ -6,12 +6,11 @@ use core::future::poll_fn; use core::marker::PhantomData; use core::task::Poll; -use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{into_ref, PeripheralRef}; use crate::gpio::sealed::Pin as _; use crate::gpio::{AnyPin, Pin as GpioPin}; -use crate::interrupt::InterruptExt; +use crate::interrupt::Interrupt; use crate::{interrupt, Peripheral}; /// Quadrature decoder driver. @@ -134,8 +133,8 @@ impl<'d, T: Instance> Qdec<'d, T> { SamplePeriod::_131ms => w.sampleper()._131ms(), }); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; // Enable peripheral r.enable.write(|w| w.enable().set_bit()); diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 2e16c2ff5..3f48568b3 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -12,7 +12,7 @@ use embassy_hal_common::{into_ref, PeripheralRef}; use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; use crate::gpio::{self, Pin as GpioPin}; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; pub use crate::pac::qspi::ifconfig0::{ ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode, }; @@ -207,8 +207,8 @@ impl<'d, T: Instance> Qspi<'d, T> { w }); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; // Enable it r.enable.write(|w| w.enable().enabled()); diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index a5602248d..7e9b35481 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs @@ -8,12 +8,11 @@ use core::ptr; use core::sync::atomic::{AtomicPtr, Ordering}; use core::task::Poll; -use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; -use crate::interrupt::InterruptExt; +use crate::interrupt::Interrupt; use crate::{interrupt, Peripheral}; /// Interrupt handler. @@ -99,8 +98,8 @@ impl<'d, T: Instance> Rng<'d, T> { this.stop(); this.disable_irq(); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; this } diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 8aff7df16..39764e380 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -6,7 +6,7 @@ use core::future::poll_fn; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; @@ -189,8 +189,8 @@ impl<'d, const N: usize> Saadc<'d, N> { // Disable all events interrupts r.intenclr.write(|w| unsafe { w.bits(0x003F_FFFF) }); - unsafe { interrupt::SAADC::steal() }.unpend(); - unsafe { interrupt::SAADC::steal() }.enable(); + interrupt::SAADC::unpend(); + unsafe { interrupt::SAADC::enable() }; Self { _p: saadc } } diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 89cbdfee9..bb9cda323 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -15,7 +15,7 @@ pub use pac::spim0::frequency::FREQUENCY_A as Frequency; use crate::chip::FORCE_COPY_BUFFER_SIZE; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; use crate::{pac, Peripheral}; @@ -207,8 +207,8 @@ impl<'d, T: Instance> Spim<'d, T> { // Disable all events interrupts r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { _p: spim } } diff --git a/embassy-nrf/src/spis.rs b/embassy-nrf/src/spis.rs index 55b5e060e..a1d6803ed 100644 --- a/embassy-nrf/src/spis.rs +++ b/embassy-nrf/src/spis.rs @@ -13,7 +13,7 @@ pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MO use crate::chip::FORCE_COPY_BUFFER_SIZE; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, AnyPin, Pin as GpioPin}; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; use crate::{pac, Peripheral}; @@ -214,8 +214,8 @@ impl<'d, T: Instance> Spis<'d, T> { // Disable all events interrupts. r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { _p: spis } } diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index 0653710af..8a127efc5 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs @@ -3,13 +3,12 @@ use core::future::poll_fn; use core::task::Poll; -use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; use fixed::types::I30F2; -use crate::interrupt::InterruptExt; +use crate::interrupt::Interrupt; use crate::peripherals::TEMP; use crate::{interrupt, pac, Peripheral}; @@ -42,8 +41,8 @@ impl<'d> Temp<'d> { into_ref!(_peri); // Enable interrupt that signals temperature values - unsafe { interrupt::TEMP::steal() }.unpend(); - unsafe { interrupt::TEMP::steal() }.enable(); + interrupt::TEMP::unpend(); + unsafe { interrupt::TEMP::enable() }; Self { _peri } } diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index c82c238cc..4feff8a75 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs @@ -7,7 +7,7 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::blocking_mutex::CriticalSectionMutex as Mutex; use embassy_time::driver::{AlarmHandle, Driver}; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::{interrupt, pac}; fn rtc() -> &'static pac::rtc0::RegisterBlock { @@ -142,9 +142,8 @@ impl RtcDriver { // Wait for clear while r.counter.read().bits() != 0 {} - let irq = unsafe { interrupt::RTC1::steal() }; - irq.set_priority(irq_prio); - irq.enable(); + interrupt::RTC1::set_priority(irq_prio); + unsafe { interrupt::RTC1::enable() }; } fn on_interrupt(&self) { diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index cab36884f..dea398a67 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -16,7 +16,7 @@ use embassy_time::{Duration, Instant}; use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; use crate::gpio::Pin as GpioPin; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::util::{slice_in_ram, slice_in_ram_or}; use crate::{gpio, pac, Peripheral}; @@ -174,8 +174,8 @@ impl<'d, T: Instance> Twim<'d, T> { // Disable all events interrupts r.intenclr.write(|w| unsafe { w.bits(0xFFFF_FFFF) }); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { _p: twim } } diff --git a/embassy-nrf/src/twis.rs b/embassy-nrf/src/twis.rs index f68a9940a..752a8c046 100644 --- a/embassy-nrf/src/twis.rs +++ b/embassy-nrf/src/twis.rs @@ -15,7 +15,7 @@ use embassy_time::{Duration, Instant}; use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; use crate::gpio::Pin as GpioPin; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::util::slice_in_ram_or; use crate::{gpio, pac, Peripheral}; @@ -204,8 +204,8 @@ impl<'d, T: Instance> Twis<'d, T> { // Generate suspend on read event r.shorts.write(|w| w.read_suspend().enabled()); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { _p: twis } } diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 032089635..6c6941ee8 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -27,7 +27,7 @@ pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Pari use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; use crate::timer::{Frequency, Instance as TimerInstance, Timer}; use crate::util::slice_in_ram_or; @@ -168,8 +168,8 @@ impl<'d, T: Instance> Uarte<'d, T> { } r.psel.rts.write(|w| unsafe { w.bits(rts.psel_bits()) }); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let hardware_flow_control = match (rts.is_some(), cts.is_some()) { (false, false) => false, @@ -358,8 +358,8 @@ impl<'d, T: Instance> UarteTx<'d, T> { let hardware_flow_control = cts.is_some(); configure(r, config, hardware_flow_control); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let s = T::state(); s.tx_rx_refcount.store(1, Ordering::Relaxed); @@ -551,8 +551,8 @@ impl<'d, T: Instance> UarteRx<'d, T> { r.psel.txd.write(|w| w.connect().disconnected()); r.psel.cts.write(|w| w.connect().disconnected()); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let hardware_flow_control = rts.is_some(); configure(r, config, hardware_flow_control); diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs index c1f3f48cb..3c62b4452 100644 --- a/embassy-nrf/src/usb/mod.rs +++ b/embassy-nrf/src/usb/mod.rs @@ -18,7 +18,7 @@ use embassy_usb_driver::{Direction, EndpointAddress, EndpointError, EndpointInfo use pac::usbd::RegisterBlock; use self::vbus_detect::VbusDetect; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::util::slice_in_ram; use crate::{pac, Peripheral}; @@ -103,8 +103,8 @@ impl<'d, T: Instance, V: VbusDetect> Driver<'d, T, V> { ) -> Self { into_ref!(usb); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { _p: usb, diff --git a/embassy-nrf/src/usb/vbus_detect.rs b/embassy-nrf/src/usb/vbus_detect.rs index cecd4c595..a6a959905 100644 --- a/embassy-nrf/src/usb/vbus_detect.rs +++ b/embassy-nrf/src/usb/vbus_detect.rs @@ -7,7 +7,7 @@ use core::task::Poll; use embassy_sync::waitqueue::AtomicWaker; use super::BUS_WAKER; -use crate::interrupt::{self, Interrupt, InterruptExt}; +use crate::interrupt::{self, Interrupt}; use crate::pac; /// Trait for detecting USB VBUS power. @@ -80,8 +80,8 @@ impl HardwareVbusDetect { pub fn new(_irq: impl interrupt::Binding + 'static) -> Self { let regs = unsafe { &*UsbRegPeri::ptr() }; - unsafe { UsbRegIrq::steal() }.unpend(); - unsafe { UsbRegIrq::steal() }.enable(); + UsbRegIrq::unpend(); + unsafe { UsbRegIrq::enable() }; regs.intenset .write(|w| w.usbdetected().set().usbremoved().set().usbpwrrdy().set()); diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index 59c7a47ce..86a353670 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs @@ -8,7 +8,7 @@ use embassy_sync::waitqueue::AtomicWaker; use embedded_hal_02::adc::{Channel, OneShot}; use crate::gpio::Pin; -use crate::interrupt::{self, InterruptExt, ADC_IRQ_FIFO}; +use crate::interrupt::{self, ADC_IRQ_FIFO}; use crate::peripherals::ADC; use crate::{pac, peripherals, Peripheral}; static WAKER: AtomicWaker = AtomicWaker::new(); @@ -63,8 +63,8 @@ impl<'d> Adc<'d> { // Setup IRQ unsafe { - ADC_IRQ_FIFO::steal().unpend(); - ADC_IRQ_FIFO::steal().enable(); + ADC_IRQ_FIFO::unpend(); + ADC_IRQ_FIFO::enable(); }; Self { phantom: PhantomData } diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index ba07a88df..74f4e6998 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs @@ -4,7 +4,7 @@ use core::pin::Pin; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::{Context, Poll}; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; use pac::dma::vals::DataSize; @@ -29,13 +29,12 @@ unsafe fn DMA_IRQ_0() { } pub(crate) unsafe fn init() { - let irq = interrupt::DMA_IRQ_0::steal(); - irq.disable(); - irq.set_priority(interrupt::Priority::P3); + interrupt::DMA_IRQ_0::disable(); + interrupt::DMA_IRQ_0::set_priority(interrupt::Priority::P3); pac::DMA.inte0().write(|w| w.set_inte0(0xFFFF)); - irq.enable(); + interrupt::DMA_IRQ_0::enable(); } pub unsafe fn read<'a, C: Channel, W: Word>( diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index da8efba91..f213bfeab 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -3,7 +3,7 @@ use core::future::Future; use core::pin::Pin as FuturePin; use core::task::{Context, Poll}; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{impl_peripheral, into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; @@ -137,10 +137,9 @@ pub enum InterruptTrigger { } pub(crate) unsafe fn init() { - let irq = interrupt::IO_IRQ_BANK0::steal(); - irq.disable(); - irq.set_priority(interrupt::Priority::P3); - irq.enable(); + interrupt::IO_IRQ_BANK0::disable(); + interrupt::IO_IRQ_BANK0::set_priority(interrupt::Priority::P3); + interrupt::IO_IRQ_BANK0::enable(); } #[interrupt] diff --git a/embassy-rp/src/i2c.rs b/embassy-rp/src/i2c.rs index 6ce77f073..124f1c00a 100644 --- a/embassy-rp/src/i2c.rs +++ b/embassy-rp/src/i2c.rs @@ -2,7 +2,7 @@ use core::future; use core::marker::PhantomData; use core::task::Poll; -use embassy_cortex_m::interrupt::{self, Binding, Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::{self, Binding, Interrupt}; use embassy_hal_common::{into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; use pac::i2c; @@ -82,14 +82,12 @@ impl<'d, T: Instance> I2c<'d, T, Async> { let i2c = Self::new_inner(peri, scl.map_into(), sda.map_into(), config); - unsafe { - let i2c = T::regs(); + let r = T::regs(); - // mask everything initially - i2c.ic_intr_mask().write_value(i2c::regs::IcIntrMask(0)); - T::Interrupt::steal().unpend(); - T::Interrupt::steal().enable(); - } + // mask everything initially + unsafe { r.ic_intr_mask().write_value(i2c::regs::IcIntrMask(0)) } + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; i2c } diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index 1db13deef..c9298644d 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs @@ -1,7 +1,7 @@ //! Interrupt definitions and macros to bind them. pub use cortex_m::interrupt::{CriticalSection, Mutex}; use embassy_cortex_m::interrupt::_export::declare; -pub use embassy_cortex_m::interrupt::{Binding, Handler, Interrupt, InterruptExt, Priority}; +pub use embassy_cortex_m::interrupt::{Binding, Handler, Interrupt, Priority}; use crate::pac::Interrupt as InterruptEnum; declare!(TIMER_IRQ_0); diff --git a/embassy-rp/src/multicore.rs b/embassy-rp/src/multicore.rs index a13209f74..807fda57b 100644 --- a/embassy-rp/src/multicore.rs +++ b/embassy-rp/src/multicore.rs @@ -50,7 +50,7 @@ use core::mem::ManuallyDrop; use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::peripherals::CORE1; use crate::{gpio, interrupt, pac}; @@ -156,8 +156,7 @@ where IS_CORE1_INIT.store(true, Ordering::Release); // Enable fifo interrupt on CORE1 for `pause` functionality. - let irq = unsafe { interrupt::SIO_IRQ_PROC1::steal() }; - irq.enable(); + unsafe { interrupt::SIO_IRQ_PROC1::enable() }; entry() } diff --git a/embassy-rp/src/pio.rs b/embassy-rp/src/pio.rs index cbe45334a..93e5bd34b 100644 --- a/embassy-rp/src/pio.rs +++ b/embassy-rp/src/pio.rs @@ -5,7 +5,7 @@ use core::sync::atomic::{compiler_fence, Ordering}; use core::task::{Context, Poll}; use atomic_polyfill::{AtomicU32, AtomicU8}; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; use fixed::types::extra::U8; @@ -110,17 +110,15 @@ unsafe fn PIO1_IRQ_0() { } pub(crate) unsafe fn init() { - let irq = interrupt::PIO0_IRQ_0::steal(); - irq.disable(); - irq.set_priority(interrupt::Priority::P3); + interrupt::PIO0_IRQ_0::disable(); + interrupt::PIO0_IRQ_0::set_priority(interrupt::Priority::P3); pac::PIO0.irqs(0).inte().write(|m| m.0 = 0); - irq.enable(); + interrupt::PIO0_IRQ_0::enable(); - let irq = interrupt::PIO1_IRQ_0::steal(); - irq.disable(); - irq.set_priority(interrupt::Priority::P3); + interrupt::PIO1_IRQ_0::disable(); + interrupt::PIO1_IRQ_0::set_priority(interrupt::Priority::P3); pac::PIO1.irqs(0).inte().write(|m| m.0 = 0); - irq.enable(); + interrupt::PIO1_IRQ_0::enable(); } /// Future that waits for TX-FIFO to become writable diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index 80efd779f..68793950f 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs @@ -6,7 +6,7 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::blocking_mutex::Mutex; use embassy_time::driver::{AlarmHandle, Driver}; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::{interrupt, pac}; struct AlarmState { @@ -145,10 +145,10 @@ pub unsafe fn init() { w.set_alarm(2, true); w.set_alarm(3, true); }); - interrupt::TIMER_IRQ_0::steal().enable(); - interrupt::TIMER_IRQ_1::steal().enable(); - interrupt::TIMER_IRQ_2::steal().enable(); - interrupt::TIMER_IRQ_3::steal().enable(); + interrupt::TIMER_IRQ_0::enable(); + interrupt::TIMER_IRQ_1::enable(); + interrupt::TIMER_IRQ_2::enable(); + interrupt::TIMER_IRQ_3::enable(); } #[interrupt] diff --git a/embassy-rp/src/uart/buffered.rs b/embassy-rp/src/uart/buffered.rs index 12d6b8d91..bb808c467 100644 --- a/embassy-rp/src/uart/buffered.rs +++ b/embassy-rp/src/uart/buffered.rs @@ -3,7 +3,7 @@ use core::slice; use core::task::Poll; use atomic_polyfill::{AtomicU8, Ordering}; -use embassy_cortex_m::interrupt::{self, Binding, Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::{self, Binding, Interrupt}; use embassy_hal_common::atomic_ring_buffer::RingBuffer; use embassy_sync::waitqueue::AtomicWaker; use embassy_time::{Duration, Timer}; @@ -80,8 +80,8 @@ pub(crate) fn init_buffers<'d, T: Instance + 'd>( w.set_txim(true); }); - T::Interrupt::steal().unpend(); - T::Interrupt::steal().enable(); + T::Interrupt::unpend(); + T::Interrupt::enable(); }; } @@ -362,7 +362,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { // FIFO and the number of bytes drops below a threshold. When the // FIFO was empty we have to manually pend the interrupt to shovel // TX data from the buffer into the FIFO. - unsafe { T::Interrupt::steal() }.pend(); + T::Interrupt::pend(); Poll::Ready(Ok(n)) }) } @@ -398,7 +398,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> { // FIFO and the number of bytes drops below a threshold. When the // FIFO was empty we have to manually pend the interrupt to shovel // TX data from the buffer into the FIFO. - unsafe { T::Interrupt::steal() }.pend(); + T::Interrupt::pend(); return Ok(n); } } @@ -460,7 +460,7 @@ impl<'d, T: Instance> Drop for BufferedUartRx<'d, T> { // TX is inactive if the the buffer is not available. // We can now unregister the interrupt handler if state.tx_buf.len() == 0 { - T::Interrupt::steal().disable(); + T::Interrupt::disable(); } } } @@ -475,7 +475,7 @@ impl<'d, T: Instance> Drop for BufferedUartTx<'d, T> { // RX is inactive if the the buffer is not available. // We can now unregister the interrupt handler if state.rx_buf.len() == 0 { - T::Interrupt::steal().disable(); + T::Interrupt::disable(); } } } diff --git a/embassy-rp/src/uart/mod.rs b/embassy-rp/src/uart/mod.rs index 44e0ca0f6..a83d94e49 100644 --- a/embassy-rp/src/uart/mod.rs +++ b/embassy-rp/src/uart/mod.rs @@ -3,7 +3,7 @@ use core::marker::PhantomData; use core::task::Poll; use atomic_polyfill::{AtomicU16, Ordering}; -use embassy_cortex_m::interrupt::{self, Binding, Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::{self, Binding, Interrupt}; use embassy_futures::select::{select, Either}; use embassy_hal_common::{into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; @@ -245,12 +245,10 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> { fn new_inner(has_irq: bool, rx_dma: Option>) -> Self { debug_assert_eq!(has_irq, rx_dma.is_some()); if has_irq { - unsafe { - // disable all error interrupts initially - T::regs().uartimsc().write(|w| w.0 = 0); - T::Interrupt::steal().unpend(); - T::Interrupt::steal().enable(); - } + // disable all error interrupts initially + unsafe { T::regs().uartimsc().write(|w| w.0 = 0) } + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; } Self { rx_dma, @@ -295,7 +293,7 @@ impl<'d, T: Instance, M: Mode> Drop for UartRx<'d, T, M> { fn drop(&mut self) { if let Some(_) = self.rx_dma { unsafe { - T::Interrupt::steal().disable(); + T::Interrupt::disable(); // clear dma flags. irq handlers use these to disambiguate among themselves. T::regs().uartdmacr().write_clear(|reg| { reg.set_rxdmae(true); diff --git a/embassy-rp/src/usb.rs b/embassy-rp/src/usb.rs index fada2790f..cc88226df 100644 --- a/embassy-rp/src/usb.rs +++ b/embassy-rp/src/usb.rs @@ -11,7 +11,7 @@ use embassy_usb_driver::{ Direction, EndpointAddress, EndpointAllocError, EndpointError, EndpointInfo, EndpointType, Event, Unsupported, }; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::{pac, peripherals, Peripheral, RegExt}; pub(crate) mod sealed { @@ -106,10 +106,8 @@ pub struct Driver<'d, T: Instance> { impl<'d, T: Instance> Driver<'d, T> { pub fn new(_usb: impl Peripheral

+ 'd, _irq: impl Binding>) -> Self { - unsafe { - T::Interrupt::steal().unpend(); - T::Interrupt::steal().enable(); - } + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let regs = T::regs(); unsafe { diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index 5f3fc6a93..c13915a1b 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs @@ -8,7 +8,7 @@ use embassy_sync::waitqueue::AtomicWaker; use crate::dma::Transfer; use crate::gpio::sealed::AFType; use crate::gpio::Speed; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::{interrupt, Peripheral}; /// Interrupt handler. @@ -346,8 +346,8 @@ where }); } - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { inner: peri, dma } } diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 9dafa26d0..7a1ecda35 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -14,7 +14,7 @@ use super::ringbuffer::{DmaCtrl, DmaRingBuffer, OverrunError}; use super::word::{Word, WordSize}; use super::Dir; use crate::_generated::BDMA_CHANNEL_COUNT; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::pac; use crate::pac::bdma::{regs, vals}; @@ -70,9 +70,8 @@ static STATE: State = State::new(); pub(crate) unsafe fn init(irq_priority: Priority) { foreach_interrupt! { ($peri:ident, bdma, $block:ident, $signal_name:ident, $irq:ident) => { - let irq = crate::interrupt::$irq::steal(); - irq.set_priority(irq_priority); - irq.enable(); + crate::interrupt::$irq::set_priority(irq_priority); + crate::interrupt::$irq::enable(); }; } crate::_generated::init_bdma(); diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 47b749ece..3b602b991 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -13,7 +13,7 @@ use super::ringbuffer::{DmaCtrl, DmaRingBuffer, OverrunError}; use super::word::{Word, WordSize}; use super::Dir; use crate::_generated::DMA_CHANNEL_COUNT; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::pac::dma::{regs, vals}; use crate::{interrupt, pac}; @@ -149,9 +149,8 @@ static STATE: State = State::new(); pub(crate) unsafe fn init(irq_priority: Priority) { foreach_interrupt! { ($peri:ident, dma, $block:ident, $signal_name:ident, $irq:ident) => { - let irq = interrupt::$irq::steal(); - irq.set_priority(irq_priority); - irq.enable(); + interrupt::$irq::set_priority(irq_priority); + interrupt::$irq::enable(); }; } crate::_generated::init_dma(); diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index 5a516ccda..7f8b82b46 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs @@ -12,7 +12,7 @@ use embassy_sync::waitqueue::AtomicWaker; use super::word::{Word, WordSize}; use super::Dir; use crate::_generated::GPDMA_CHANNEL_COUNT; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::pac; use crate::pac::gpdma::vals; @@ -56,9 +56,8 @@ static STATE: State = State::new(); pub(crate) unsafe fn init(irq_priority: Priority) { foreach_interrupt! { ($peri:ident, gpdma, $block:ident, $signal_name:ident, $irq:ident) => { - let irq = crate::interrupt::$irq::steal(); - irq.set_priority(irq_priority); - irq.enable(); + crate::interrupt::$irq::set_priority(irq_priority); + crate::interrupt::$irq::enable(); }; } crate::_generated::init_gpdma(); diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 8ef2c3584..a5f1a268d 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -5,7 +5,7 @@ mod tx_desc; use core::sync::atomic::{fence, Ordering}; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{into_ref, PeripheralRef}; use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; @@ -267,8 +267,8 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { P::phy_reset(&mut this); P::phy_init(&mut this); - interrupt::ETH::steal().unpend(); - interrupt::ETH::steal().enable(); + interrupt::ETH::unpend(); + interrupt::ETH::enable(); this } diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index b56c3e8ab..9efa436ac 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -2,7 +2,7 @@ mod descriptors; use core::sync::atomic::{fence, Ordering}; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{into_ref, PeripheralRef}; pub(crate) use self::descriptors::{RDes, RDesRing, TDes, TDesRing}; @@ -238,8 +238,8 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> { P::phy_reset(&mut this); P::phy_init(&mut this); - interrupt::ETH::steal().unpend(); - interrupt::ETH::steal().enable(); + interrupt::ETH::unpend(); + interrupt::ETH::enable(); this } diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index 10109e56a..c2fa31b20 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -354,13 +354,13 @@ impl_exti!(EXTI15, 15); macro_rules! enable_irq { ($e:ident) => { - crate::interrupt::$e::steal().enable(); + crate::interrupt::$e::enable(); }; } /// safety: must be called only once pub(crate) unsafe fn init() { - use crate::interrupt::{Interrupt, InterruptExt}; + use crate::interrupt::Interrupt; foreach_exti_irq!(enable_irq); diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index 3c3ece99a..872614d4e 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs @@ -1,7 +1,7 @@ use core::marker::PhantomData; use atomic_polyfill::{fence, Ordering}; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::into_ref; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; @@ -23,9 +23,8 @@ impl<'d> Flash<'d, Async> { ) -> Self { into_ref!(p); - let flash_irq = unsafe { crate::interrupt::FLASH::steal() }; - flash_irq.unpend(); - flash_irq.enable(); + crate::interrupt::FLASH::unpend(); + unsafe { crate::interrupt::FLASH::enable() }; Self { inner: p, diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 642ddc18c..10f57f700 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -3,7 +3,7 @@ use core::future::poll_fn; use core::marker::PhantomData; use core::task::Poll; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_embedded_hal::SetConfig; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; @@ -133,8 +133,8 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { }); } - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { _peri: peri, diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 6533509eb..75d8af3dd 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -75,7 +75,7 @@ pub(crate) mod _generated { pub mod interrupt { //! Interrupt definitions and macros to bind them. pub use cortex_m::interrupt::{CriticalSection, Mutex}; - pub use embassy_cortex_m::interrupt::{Binding, Handler, Interrupt, InterruptExt, Priority}; + pub use embassy_cortex_m::interrupt::{Binding, Handler, Interrupt, Priority}; pub use crate::_generated::interrupt::*; diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index be03a1bac..3cc17aa68 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -14,7 +14,7 @@ use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, use crate::dma::NoDma; use crate::gpio::sealed::{AFType, Pin}; use crate::gpio::{AnyPin, Pull, Speed}; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::pac::sdmmc::Sdmmc as RegBlock; use crate::rcc::RccPeripheral; use crate::time::Hertz; @@ -447,8 +447,8 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { T::enable(); T::reset(); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let regs = T::regs(); unsafe { @@ -1288,7 +1288,7 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { impl<'d, T: Instance, Dma: SdmmcDma + 'd> Drop for Sdmmc<'d, T, Dma> { fn drop(&mut self) { - unsafe { T::Interrupt::steal() }.disable(); + T::Interrupt::disable(); unsafe { Self::on_drop() }; critical_section::with(|_| unsafe { diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 2236fde28..bab700993 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -11,7 +11,7 @@ use embassy_time::driver::{AlarmHandle, Driver}; use embassy_time::TICK_HZ; use stm32_metapac::timer::regs; -use crate::interrupt::InterruptExt; +use crate::interrupt::Interrupt; use crate::pac::timer::vals; use crate::rcc::sealed::RccPeripheral; use crate::timer::sealed::{Basic16bitInstance as BasicInstance, GeneralPurpose16bitInstance as Instance}; @@ -177,9 +177,8 @@ impl RtcDriver { w.set_ccie(0, true); }); - let irq: ::Interrupt = core::mem::transmute(()); - irq.unpend(); - irq.enable(); + ::Interrupt::unpend(); + ::Interrupt::enable(); r.cr1().modify(|w| w.set_cen(true)); }) diff --git a/embassy-stm32/src/tl_mbox/mod.rs b/embassy-stm32/src/tl_mbox/mod.rs index 616f7dc56..efbbf2d1d 100644 --- a/embassy-stm32/src/tl_mbox/mod.rs +++ b/embassy-stm32/src/tl_mbox/mod.rs @@ -2,7 +2,7 @@ use core::mem::MaybeUninit; use atomic_polyfill::{compiler_fence, Ordering}; use bit_field::BitField; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; use embassy_sync::channel::Channel; @@ -379,11 +379,11 @@ impl<'d> TlMbox<'d> { MemoryManager::enable(); // enable interrupts - unsafe { crate::interrupt::IPCC_C1_RX::steal() }.unpend(); - unsafe { crate::interrupt::IPCC_C1_TX::steal() }.unpend(); + crate::interrupt::IPCC_C1_RX::unpend(); + crate::interrupt::IPCC_C1_TX::unpend(); - unsafe { crate::interrupt::IPCC_C1_RX::steal() }.enable(); - unsafe { crate::interrupt::IPCC_C1_TX::steal() }.enable(); + unsafe { crate::interrupt::IPCC_C1_RX::enable() }; + unsafe { crate::interrupt::IPCC_C1_TX::enable() }; Self { _ipcc: ipcc } } diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 9f1da3583..252e945da 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -216,8 +216,8 @@ impl<'d, T: BasicInstance> BufferedUart<'d, T> { }); } - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; Self { rx: BufferedUartRx { phantom: PhantomData }, @@ -245,7 +245,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> { rx_reader.pop_done(len); if do_pend { - unsafe { T::Interrupt::steal().pend() }; + T::Interrupt::pend(); } return Poll::Ready(Ok(len)); @@ -271,7 +271,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> { rx_reader.pop_done(len); if do_pend { - unsafe { T::Interrupt::steal().pend() }; + T::Interrupt::pend(); } return Ok(len); @@ -301,7 +301,7 @@ impl<'d, T: BasicInstance> BufferedUartRx<'d, T> { let full = state.rx_buf.is_full(); rx_reader.pop_done(amt); if full { - unsafe { T::Interrupt::steal().pend() }; + T::Interrupt::pend(); } } } @@ -324,7 +324,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> { tx_writer.push_done(n); if empty { - unsafe { T::Interrupt::steal() }.pend(); + T::Interrupt::pend(); } Poll::Ready(Ok(n)) @@ -358,7 +358,7 @@ impl<'d, T: BasicInstance> BufferedUartTx<'d, T> { tx_writer.push_done(n); if empty { - unsafe { T::Interrupt::steal() }.pend(); + T::Interrupt::pend(); } return Ok(n); @@ -385,7 +385,7 @@ impl<'d, T: BasicInstance> Drop for BufferedUartRx<'d, T> { // TX is inactive if the the buffer is not available. // We can now unregister the interrupt handler if state.tx_buf.len() == 0 { - T::Interrupt::steal().disable(); + T::Interrupt::disable(); } } } @@ -400,7 +400,7 @@ impl<'d, T: BasicInstance> Drop for BufferedUartTx<'d, T> { // RX is inactive if the the buffer is not available. // We can now unregister the interrupt handler if state.rx_buf.len() == 0 { - T::Interrupt::steal().disable(); + T::Interrupt::disable(); } } } diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 05ccb8749..ef1080153 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -5,7 +5,7 @@ use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; -use embassy_cortex_m::interrupt::{Interrupt, InterruptExt}; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; use futures::future::{select, Either}; @@ -331,8 +331,8 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> { configure(r, &config, T::frequency(), T::KIND, true, false); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; // create state once! let _s = T::state(); @@ -732,8 +732,8 @@ impl<'d, T: BasicInstance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> { configure(r, &config, T::frequency(), T::KIND, true, true); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; // create state once! let _s = T::state(); diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index a9ff284ae..134107978 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -14,7 +14,7 @@ use embassy_usb_driver::{ use super::{DmPin, DpPin, Instance}; use crate::gpio::sealed::AFType; -use crate::interrupt::{Interrupt, InterruptExt}; +use crate::interrupt::Interrupt; use crate::pac::usb::regs; use crate::pac::usb::vals::{EpType, Stat}; use crate::pac::USBRAM; @@ -260,8 +260,8 @@ impl<'d, T: Instance> Driver<'d, T> { dm: impl Peripheral

> + 'd, ) -> Self { into_ref!(dp, dm); - unsafe { T::Interrupt::steal() }.unpend(); - unsafe { T::Interrupt::steal() }.enable(); + T::Interrupt::unpend(); + unsafe { T::Interrupt::enable() }; let regs = T::regs(); diff --git a/embassy-stm32/src/usb_otg/usb.rs b/embassy-stm32/src/usb_otg/usb.rs index 921a73c8b..c7f19f6e9 100644 --- a/embassy-stm32/src/usb_otg/usb.rs +++ b/embassy-stm32/src/usb_otg/usb.rs @@ -3,7 +3,7 @@ use core::marker::PhantomData; use core::task::Poll; use atomic_polyfill::{AtomicBool, AtomicU16, Ordering}; -use embassy_cortex_m::interrupt::InterruptExt; +use embassy_cortex_m::interrupt::Interrupt; use embassy_hal_common::{into_ref, Peripheral}; use embassy_sync::waitqueue::AtomicWaker; use embassy_usb_driver::{ @@ -629,7 +629,7 @@ impl<'d, T: Instance> Bus<'d, T> { } fn disable(&mut self) { - unsafe { T::Interrupt::steal() }.disable(); + T::Interrupt::disable(); ::disable(); @@ -902,8 +902,8 @@ impl<'d, T: Instance> embassy_usb_driver::Bus for Bus<'d, T> { ::enable(); ::reset(); - T::Interrupt::steal().unpend(); - T::Interrupt::steal().enable(); + T::Interrupt::unpend(); + T::Interrupt::enable(); let r = T::regs(); let core_id = r.cid().read().0; diff --git a/examples/boot/bootloader/rp/Cargo.toml b/examples/boot/bootloader/rp/Cargo.toml index 8d60f18be..c1dc99eec 100644 --- a/examples/boot/bootloader/rp/Cargo.toml +++ b/examples/boot/bootloader/rp/Cargo.toml @@ -30,3 +30,4 @@ debug = ["defmt-rtt", "defmt"] [profile.release] debug = true +opt-level = 's' diff --git a/examples/std/src/bin/tcp_accept.rs b/examples/std/src/bin/tcp_accept.rs index d24e218dc..01695baea 100644 --- a/examples/std/src/bin/tcp_accept.rs +++ b/examples/std/src/bin/tcp_accept.rs @@ -108,7 +108,7 @@ async fn main_task(spawner: Spawner) { info!("Closing the connection"); socket.abort(); info!("Flushing the RST out..."); - socket.flush().await; + _ = socket.flush().await; info!("Finished with the socket"); } }