pub use bare_metal::{CriticalSection, Mutex};
#[inline(always)]
pub fn disable() {
match () {
#[cfg(target_arch = "msp430")]
() => unsafe {
asm!("dint { nop"
:
:
: "memory"
: "volatile");
},
#[cfg(not(target_arch = "msp430"))]
() => {}
}
}
#[inline(always)]
pub unsafe fn enable() {
match () {
#[cfg(target_arch = "msp430")]
() => {
asm!("nop { eint { nop"
:
:
: "memory"
: "volatile");
}
#[cfg(not(target_arch = "msp430"))]
() => {}
}
}
pub fn free<F, R>(f: F) -> R
where
F: FnOnce(&CriticalSection) -> R,
{
let status = ::register::sr::read();
disable();
let r = f(unsafe { &CriticalSection::new() });
if status.gie() {
unsafe { enable() }
}
r
}