Skip to content

Commit 40a60d3

Browse files
committed
add NVIC::{mask,unmask}
these are the "static method" (methods that don't take `self`) versions of NVIC::{enable,disable} in the same vein as the existing NVIC::{pend,unpend} this commit also deprecates the existing NVIC::{enable,disable} methods and notes that NVIC::enable is unsound because it should be an `unsafe` method (like interrupt::enable and basepri::write, it can break critical sections) but it's marked as safe. Its replacement, NVIC::unmask, has the correct unsafety setting: it's an `unsafe` function.
1 parent e1a3d7a commit 40a60d3

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

src/peripheral/nvic.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,44 @@ impl NVIC {
104104
}
105105

106106
/// Disables `interrupt`
107-
pub fn disable<I>(&mut self, interrupt: I)
107+
pub fn mask<I>(interrupt: I)
108108
where
109109
I: Nr,
110110
{
111111
let nr = interrupt.nr();
112-
113-
unsafe { self.icer[usize::from(nr / 32)].write(1 << (nr % 32)) }
112+
// NOTE(unsafe) this is a write to a stateless register
113+
unsafe { (*Self::ptr()).icer[usize::from(nr / 32)].write(1 << (nr % 32)) }
114114
}
115115

116116
/// Enables `interrupt`
117-
pub fn enable<I>(&mut self, interrupt: I)
117+
///
118+
/// This function is `unsafe` because it can break mask-based critical sections
119+
pub unsafe fn unmask<I>(interrupt: I)
118120
where
119121
I: Nr,
120122
{
121123
let nr = interrupt.nr();
124+
// NOTE(ptr) this is a write to a stateless register
125+
(*Self::ptr()).iser[usize::from(nr / 32)].write(1 << (nr % 32))
126+
}
127+
128+
/// Disables `interrupt`
129+
#[deprecated(since = "0.6.1", note = "Use `NVIC::mask`")]
130+
pub fn disable<I>(&mut self, interrupt: I)
131+
where
132+
I: Nr,
133+
{
134+
Self::mask(interrupt)
135+
}
122136

123-
unsafe { self.iser[usize::from(nr / 32)].write(1 << (nr % 32)) }
137+
/// **WARNING** This method is a soundness hole in the API; it should actually be an `unsafe`
138+
/// function. Use `NVIC::unmask` which has the right unsafety.
139+
#[deprecated(since = "0.6.1", note = "Use `NVIC::unmask`")]
140+
pub fn enable<I>(&mut self, interrupt: I)
141+
where
142+
I: Nr,
143+
{
144+
unsafe { Self::unmask(interrupt) }
124145
}
125146

126147
/// Returns the NVIC priority of `interrupt`

0 commit comments

Comments
 (0)