aboutsummaryrefslogtreecommitdiff
path: root/embassy-extras
diff options
context:
space:
mode:
authorLiam Murphy <[email protected]>2021-07-28 21:39:31 +1000
committerLiam Murphy <[email protected]>2021-07-28 21:39:31 +1000
commit4d9514cbcb97343c3a75bfa565d753c44c2a0e27 (patch)
treec277793926b77ff6f87953f0330f6434891dc6c3 /embassy-extras
parent68c93256bcab8dfe0f65c694fa5fadb890fd3f00 (diff)
Don't allow disabling interrupts wrapped by `PeripheralMutex`
Diffstat (limited to 'embassy-extras')
-rw-r--r--embassy-extras/src/peripheral.rs21
-rw-r--r--embassy-extras/src/peripheral_shared.rs16
2 files changed, 1 insertions, 36 deletions
diff --git a/embassy-extras/src/peripheral.rs b/embassy-extras/src/peripheral.rs
index 396ab5432..725a58a46 100644
--- a/embassy-extras/src/peripheral.rs
+++ b/embassy-extras/src/peripheral.rs
@@ -140,36 +140,17 @@ impl<S: PeripheralStateUnchecked> PeripheralMutex<S> {
140 pub fn with<R>(self: Pin<&mut Self>, f: impl FnOnce(&mut S) -> R) -> R { 140 pub fn with<R>(self: Pin<&mut Self>, f: impl FnOnce(&mut S) -> R) -> R {
141 let this = unsafe { self.get_unchecked_mut() }; 141 let this = unsafe { self.get_unchecked_mut() };
142 142
143 let was_enabled = this.irq.is_enabled();
144 this.irq.disable(); 143 this.irq.disable();
145 144
146 // Safety: it's OK to get a &mut to the state, since the irq is disabled. 145 // Safety: it's OK to get a &mut to the state, since the irq is disabled.
147 let state = unsafe { &mut *this.state.get() }; 146 let state = unsafe { &mut *this.state.get() };
148 let r = f(state); 147 let r = f(state);
149 148
150 if was_enabled { 149 this.irq.enable();
151 this.irq.enable();
152 }
153 150
154 r 151 r
155 } 152 }
156 153
157 /// Enables the wrapped interrupt.
158 pub fn enable(&self) {
159 // This is fine to do before initialization, because we haven't set the handler yet.
160 self.irq.enable()
161 }
162
163 /// Disables the wrapped interrupt.
164 pub fn disable(&self) {
165 self.irq.disable()
166 }
167
168 /// Returns whether the wrapped interrupt is enabled.
169 pub fn is_enabled(&self) -> bool {
170 self.irq.is_enabled()
171 }
172
173 /// Returns whether the wrapped interrupt is currently in a pending state. 154 /// Returns whether the wrapped interrupt is currently in a pending state.
174 pub fn is_pending(&self) -> bool { 155 pub fn is_pending(&self) -> bool {
175 self.irq.is_pending() 156 self.irq.is_pending()
diff --git a/embassy-extras/src/peripheral_shared.rs b/embassy-extras/src/peripheral_shared.rs
index ae9ae6935..788ac3f96 100644
--- a/embassy-extras/src/peripheral_shared.rs
+++ b/embassy-extras/src/peripheral_shared.rs
@@ -79,22 +79,6 @@ impl<S: PeripheralStateUnchecked> Peripheral<S> {
79 &self.into_ref().get_ref().state 79 &self.into_ref().get_ref().state
80 } 80 }
81 81
82 /// Enables the wrapped interrupt.
83 pub fn enable(&self) {
84 // This is fine to do before initialization, because we haven't set the handler yet.
85 self.irq.enable()
86 }
87
88 /// Disables the wrapped interrupt.
89 pub fn disable(&self) {
90 self.irq.disable()
91 }
92
93 /// Returns whether the wrapped interrupt is enabled.
94 pub fn is_enabled(&self) -> bool {
95 self.irq.is_enabled()
96 }
97
98 /// Returns whether the wrapped interrupt is currently in a pending state. 82 /// Returns whether the wrapped interrupt is currently in a pending state.
99 pub fn is_pending(&self) -> bool { 83 pub fn is_pending(&self) -> bool {
100 self.irq.is_pending() 84 self.irq.is_pending()