1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Crate configuration modes
use cortex_m::interrupt;

///Trait to configure interrupt mode.
pub trait InterruptModer {
    #[doc(hidden)]
    fn critical_section<R, F: FnOnce(&interrupt::CriticalSection) -> R>(f: F) -> R;
}

///Ensures that interrupt free execution.
pub struct InterruptFree;
impl InterruptModer for InterruptFree {
    #[inline]
    #[doc(hidden)]
    fn critical_section<R, F: FnOnce(&interrupt::CriticalSection) -> R>(f: F) -> R {
        interrupt::free(f)
    }
}

///No control of interrupts is made.
pub struct InterruptOk;
impl InterruptModer for InterruptOk {
    #[inline]
    #[doc(hidden)]
    fn critical_section<R, F: FnOnce(&interrupt::CriticalSection) -> R>(f: F) -> R {
        f(&unsafe { interrupt::CriticalSection::new() })
    }
}