aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/hsem/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/hsem/mod.rs')
-rw-r--r--embassy-stm32/src/hsem/mod.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/embassy-stm32/src/hsem/mod.rs b/embassy-stm32/src/hsem/mod.rs
index b5fa3c897..e5c68acbd 100644
--- a/embassy-stm32/src/hsem/mod.rs
+++ b/embassy-stm32/src/hsem/mod.rs
@@ -94,17 +94,14 @@ pub struct HardwareSemaphoreInterruptHandler<T: Instance> {
94impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for HardwareSemaphoreInterruptHandler<T> { 94impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for HardwareSemaphoreInterruptHandler<T> {
95 unsafe fn on_interrupt() { 95 unsafe fn on_interrupt() {
96 let core_id = CoreId::current(); 96 let core_id = CoreId::current();
97 let isr = T::regs().isr(core_id.to_index()).read();
97 98
98 for number in 0..5 { 99 for number in 0..5 {
99 if T::regs().isr(core_id.to_index()).read().isf(number as usize) { 100 if isr.isf(number as usize) {
100 T::regs() 101 T::regs()
101 .icr(core_id.to_index()) 102 .icr(core_id.to_index())
102 .write(|w| w.set_isc(number as usize, true)); 103 .write(|w| w.set_isc(number as usize, true));
103 104
104 T::regs()
105 .ier(core_id.to_index())
106 .modify(|w| w.set_ise(number as usize, false));
107
108 T::state().waker_for(number).wake(); 105 T::state().waker_for(number).wake();
109 } 106 }
110 } 107 }
@@ -120,6 +117,18 @@ pub struct HardwareSemaphoreMutex<'a, T: Instance> {
120 117
121impl<'a, T: Instance> Drop for HardwareSemaphoreMutex<'a, T> { 118impl<'a, T: Instance> Drop for HardwareSemaphoreMutex<'a, T> {
122 fn drop(&mut self) { 119 fn drop(&mut self) {
120 let core_id = CoreId::current();
121
122 T::regs()
123 .icr(core_id.to_index())
124 .write(|w| w.set_isc(self.index as usize, true));
125
126 critical_section::with(|_| {
127 T::regs()
128 .ier(core_id.to_index())
129 .modify(|w| w.set_ise(self.index as usize, false));
130 });
131
123 HardwareSemaphoreChannel::<'a, T> { 132 HardwareSemaphoreChannel::<'a, T> {
124 index: self.index, 133 index: self.index,
125 _lifetime: PhantomData, 134 _lifetime: PhantomData,
@@ -156,9 +165,11 @@ impl<'a, T: Instance> HardwareSemaphoreChannel<'a, T> {
156 165
157 compiler_fence(Ordering::SeqCst); 166 compiler_fence(Ordering::SeqCst);
158 167
159 T::regs() 168 critical_section::with(|_| {
160 .ier(core_id.to_index()) 169 T::regs()
161 .modify(|w| w.set_ise(self.index as usize, true)); 170 .ier(core_id.to_index())
171 .modify(|w| w.set_ise(self.index as usize, true));
172 });
162 173
163 match self.try_lock(process_id) { 174 match self.try_lock(process_id) {
164 Some(mutex) => Poll::Ready(mutex), 175 Some(mutex) => Poll::Ready(mutex),