use crate::asm;
pub use critical_section::{CriticalSection, Mutex};
#[inline(always)]
pub fn disable() {
match () {
#[cfg(target_arch = "msp430")]
() => unsafe {
asm!("dint {{ nop", options(nostack));
},
#[cfg(not(target_arch = "msp430"))]
() => {}
}
}
#[inline(always)]
pub unsafe fn enable() {
match () {
#[cfg(target_arch = "msp430")]
() => {
asm!("nop {{ eint {{ nop", options(nostack));
}
#[cfg(not(target_arch = "msp430"))]
() => {}
}
}
#[deprecated(since = "0.4.0", note = "critical_section::with() allows alternate implementations; interrupt:free() is a hardcoded implementation of critical_section::with() with a different type signature.")]
pub fn free<F, R>(f: F) -> R
where
F: for<'a> FnOnce(&'a CriticalSection<'a>) -> R,
{
let status = unsafe { acquire() };
let cs = unsafe { CriticalSection::new() };
let r = f(&cs);
unsafe { release(status); }
r
}
#[cfg_attr(feature = "outline-cs-acq", inline(never))]
#[cfg_attr(not(feature="outline-cs-acq"), inline)]
unsafe fn acquire() -> crate::register::sr::Sr {
let status = crate::register::sr::read();
disable();
status
}
#[cfg_attr(feature = "outline-cs-rel", inline(never))]
#[cfg_attr(not(feature="outline-cs-rel"), inline)]
unsafe fn release(sr: crate::register::sr::Sr) {
if sr.gie() {
enable()
}
}