cortex_m_log/
modes.rs

1//! Crate configuration modes
2use cortex_m::interrupt;
3
4///Trait to configure interrupt mode.
5pub trait InterruptModer {
6    #[doc(hidden)]
7    fn critical_section<R, F: FnOnce(&interrupt::CriticalSection) -> R>(f: F) -> R;
8}
9
10///Ensures that interrupt free execution.
11pub struct InterruptFree;
12impl InterruptModer for InterruptFree {
13    #[inline]
14    #[doc(hidden)]
15    fn critical_section<R, F: FnOnce(&interrupt::CriticalSection) -> R>(f: F) -> R {
16        interrupt::free(f)
17    }
18}
19
20///No control of interrupts is made.
21pub struct InterruptOk;
22impl InterruptModer for InterruptOk {
23    #[inline]
24    #[doc(hidden)]
25    fn critical_section<R, F: FnOnce(&interrupt::CriticalSection) -> R>(f: F) -> R {
26        f(&unsafe { interrupt::CriticalSection::new() })
27    }
28}