Module avr_device::interrupt
source · [−]Expand description
Chip-Generic Interrupt Utilities
For the most part, crate::interrupt::free is what you want:
avr_device::interrupt::free(|cs| {
// Interrupts are disabled here
});
To access shared state, Mutex can be used:
use avr_device::interrupt::Mutex;
use core::cell::Cell;
// Use Cell, if the wrapped type is Copy.
// Use RefCell, if the wrapped type is not Copy or if you need a reference to it for other reasons.
static MYGLOBAL: Mutex<Cell<u16>> = Mutex::new(Cell::new(0));
avr_device::interrupt::free(|cs| {
// Interrupts are disabled here
// Acquire mutex to global variable.
let myglobal_ref = MYGLOBAL.borrow(&cs);
// Write to the global variable.
myglobal_ref.set(42);
});
Structs
Critical section token.
Opaque structure for storing the global interrupt flag status.
A “mutex” based on critical sections.
Functions
Disable the global interrupt flag.
Disable the global interrupt flag and return an opaque representation of the previous flag status.
Execute closure f
in an interrupt-free context.
Check whether the global interrupt flag is currently enabled (in SREG).
Restore the global interrupt flag to its previous state before crate::interrupt::disable_save.