Don't allow disabling interrupts wrapped by PeripheralMutex

This commit is contained in:
Liam Murphy 2021-07-28 21:39:31 +10:00
parent 68c93256bc
commit 4d9514cbcb
2 changed files with 1 additions and 36 deletions

View File

@ -140,36 +140,17 @@ impl<S: PeripheralStateUnchecked> PeripheralMutex<S> {
pub fn with<R>(self: Pin<&mut Self>, f: impl FnOnce(&mut S) -> R) -> R { pub fn with<R>(self: Pin<&mut Self>, f: impl FnOnce(&mut S) -> R) -> R {
let this = unsafe { self.get_unchecked_mut() }; let this = unsafe { self.get_unchecked_mut() };
let was_enabled = this.irq.is_enabled();
this.irq.disable(); this.irq.disable();
// Safety: it's OK to get a &mut to the state, since the irq is disabled. // Safety: it's OK to get a &mut to the state, since the irq is disabled.
let state = unsafe { &mut *this.state.get() }; let state = unsafe { &mut *this.state.get() };
let r = f(state); let r = f(state);
if was_enabled { this.irq.enable();
this.irq.enable();
}
r r
} }
/// Enables the wrapped interrupt.
pub fn enable(&self) {
// This is fine to do before initialization, because we haven't set the handler yet.
self.irq.enable()
}
/// Disables the wrapped interrupt.
pub fn disable(&self) {
self.irq.disable()
}
/// Returns whether the wrapped interrupt is enabled.
pub fn is_enabled(&self) -> bool {
self.irq.is_enabled()
}
/// Returns whether the wrapped interrupt is currently in a pending state. /// Returns whether the wrapped interrupt is currently in a pending state.
pub fn is_pending(&self) -> bool { pub fn is_pending(&self) -> bool {
self.irq.is_pending() self.irq.is_pending()

View File

@ -79,22 +79,6 @@ impl<S: PeripheralStateUnchecked> Peripheral<S> {
&self.into_ref().get_ref().state &self.into_ref().get_ref().state
} }
/// Enables the wrapped interrupt.
pub fn enable(&self) {
// This is fine to do before initialization, because we haven't set the handler yet.
self.irq.enable()
}
/// Disables the wrapped interrupt.
pub fn disable(&self) {
self.irq.disable()
}
/// Returns whether the wrapped interrupt is enabled.
pub fn is_enabled(&self) -> bool {
self.irq.is_enabled()
}
/// Returns whether the wrapped interrupt is currently in a pending state. /// Returns whether the wrapped interrupt is currently in a pending state.
pub fn is_pending(&self) -> bool { pub fn is_pending(&self) -> bool {
self.irq.is_pending() self.irq.is_pending()