aboutsummaryrefslogtreecommitdiff
path: root/embassy-cortex-m/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 01:29:35 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 02:40:13 +0200
commit8a9d2f59af004902d3978a2922843833b98bcce0 (patch)
tree27a435fe0bc81d344472b76a6cd3666edbb83889 /embassy-cortex-m/src
parente0521ea249d375097c9d62c602b8f598e6b65292 (diff)
Update embassy-stm32
Diffstat (limited to 'embassy-cortex-m/src')
-rw-r--r--embassy-cortex-m/src/peripheral.rs21
1 files changed, 11 insertions, 10 deletions
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 @@
1//! Peripheral interrupt handling specific to cortex-m devices. 1//! Peripheral interrupt handling specific to cortex-m devices.
2use core::marker::PhantomData;
3use core::mem::MaybeUninit; 2use core::mem::MaybeUninit;
4 3
5use cortex_m::peripheral::scb::VectActive; 4use cortex_m::peripheral::scb::VectActive;
6use cortex_m::peripheral::{NVIC, SCB}; 5use cortex_m::peripheral::{NVIC, SCB};
6use embassy_hal_common::{unborrow, Unborrow, Unborrowed};
7 7
8use crate::interrupt::{Interrupt, InterruptExt, Priority}; 8use crate::interrupt::{Interrupt, InterruptExt, Priority};
9 9
@@ -33,8 +33,7 @@ impl<S> StateStorage<S> {
33/// a safe way. 33/// a safe way.
34pub struct PeripheralMutex<'a, S: PeripheralState> { 34pub struct PeripheralMutex<'a, S: PeripheralState> {
35 state: *mut S, 35 state: *mut S,
36 _phantom: PhantomData<&'a mut S>, 36 irq: Unborrowed<'a, S::Interrupt>,
37 irq: S::Interrupt,
38} 37}
39 38
40/// Whether `irq` can be preempted by the current interrupt. 39/// Whether `irq` can be preempted by the current interrupt.
@@ -62,8 +61,14 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> {
62 /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state. 61 /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state.
63 /// 62 ///
64 /// Registers `on_interrupt` as the `irq`'s handler, and enables it. 63 /// Registers `on_interrupt` as the `irq`'s handler, and enables it.
65 pub fn new(irq: S::Interrupt, storage: &'a mut StateStorage<S>, init: impl FnOnce() -> S) -> Self { 64 pub fn new(
66 if can_be_preempted(&irq) { 65 irq: impl Unborrow<Target = S::Interrupt> + 'a,
66 storage: &'a mut StateStorage<S>,
67 init: impl FnOnce() -> S,
68 ) -> Self {
69 unborrow!(irq);
70
71 if can_be_preempted(&*irq) {
67 panic!( 72 panic!(
68 "`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps" 73 "`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps"
69 ); 74 );
@@ -88,11 +93,7 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> {
88 irq.set_handler_context(state_ptr as *mut ()); 93 irq.set_handler_context(state_ptr as *mut ());
89 irq.enable(); 94 irq.enable();
90 95
91 Self { 96 Self { irq, state: state_ptr }
92 irq,
93 state: state_ptr,
94 _phantom: PhantomData,
95 }
96 } 97 }
97 98
98 /// Access the peripheral state ensuring interrupts are disabled so that the state can be 99 /// Access the peripheral state ensuring interrupts are disabled so that the state can be