From 8a9d2f59af004902d3978a2922843833b98bcce0 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 23 Jul 2022 01:29:35 +0200 Subject: Update embassy-stm32 --- embassy-cortex-m/src/peripheral.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'embassy-cortex-m/src') diff --git a/embassy-cortex-m/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs index 6a03bfb9f..c5fa20e71 100644 --- a/embassy-cortex-m/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs @@ -1,9 +1,9 @@ //! Peripheral interrupt handling specific to cortex-m devices. -use core::marker::PhantomData; use core::mem::MaybeUninit; use cortex_m::peripheral::scb::VectActive; use cortex_m::peripheral::{NVIC, SCB}; +use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; use crate::interrupt::{Interrupt, InterruptExt, Priority}; @@ -33,8 +33,7 @@ impl StateStorage { /// a safe way. pub struct PeripheralMutex<'a, S: PeripheralState> { state: *mut S, - _phantom: PhantomData<&'a mut S>, - irq: S::Interrupt, + irq: Unborrowed<'a, S::Interrupt>, } /// Whether `irq` can be preempted by the current interrupt. @@ -62,8 +61,14 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state. /// /// Registers `on_interrupt` as the `irq`'s handler, and enables it. - pub fn new(irq: S::Interrupt, storage: &'a mut StateStorage, init: impl FnOnce() -> S) -> Self { - if can_be_preempted(&irq) { + pub fn new( + irq: impl Unborrow + 'a, + storage: &'a mut StateStorage, + init: impl FnOnce() -> S, + ) -> Self { + unborrow!(irq); + + if can_be_preempted(&*irq) { panic!( "`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps" ); @@ -88,11 +93,7 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { irq.set_handler_context(state_ptr as *mut ()); irq.enable(); - Self { - irq, - state: state_ptr, - _phantom: PhantomData, - } + Self { irq, state: state_ptr } } /// Access the peripheral state ensuring interrupts are disabled so that the state can be -- cgit From 4901c34d9c4cd326ab9bca02dd099a663da2567f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 23 Jul 2022 14:00:19 +0200 Subject: Rename Unborrowed -> PeripheralRef, Unborrow -> Peripheral --- embassy-cortex-m/src/interrupt.rs | 4 ++-- embassy-cortex-m/src/peripheral.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'embassy-cortex-m/src') diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index 715f00381..7358caa46 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs @@ -3,7 +3,7 @@ use core::{mem, ptr}; use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; use cortex_m::peripheral::NVIC; -use embassy_hal_common::Unborrow; +use embassy_hal_common::Peripheral; pub use embassy_macros::cortex_m_interrupt_take as take; /// Implementation detail, do not use outside embassy crates. @@ -32,7 +32,7 @@ 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: Unborrow { +pub unsafe trait Interrupt: Peripheral

{ /// Return the NVIC interrupt number for this interrupt. fn number(&self) -> u16; /// Steal an instance of this interrupt diff --git a/embassy-cortex-m/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs index c5fa20e71..e2f295579 100644 --- a/embassy-cortex-m/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs @@ -3,7 +3,7 @@ use core::mem::MaybeUninit; use cortex_m::peripheral::scb::VectActive; use cortex_m::peripheral::{NVIC, SCB}; -use embassy_hal_common::{unborrow, Unborrow, Unborrowed}; +use embassy_hal_common::{into_ref, Peripheral, PeripheralRef}; use crate::interrupt::{Interrupt, InterruptExt, Priority}; @@ -33,7 +33,7 @@ impl StateStorage { /// a safe way. pub struct PeripheralMutex<'a, S: PeripheralState> { state: *mut S, - irq: Unborrowed<'a, S::Interrupt>, + irq: PeripheralRef<'a, S::Interrupt>, } /// Whether `irq` can be preempted by the current interrupt. @@ -62,11 +62,11 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { /// /// Registers `on_interrupt` as the `irq`'s handler, and enables it. pub fn new( - irq: impl Unborrow + 'a, + irq: impl Peripheral

+ 'a, storage: &'a mut StateStorage, init: impl FnOnce() -> S, ) -> Self { - unborrow!(irq); + into_ref!(irq); if can_be_preempted(&*irq) { panic!( -- cgit