Available on crate feature
unstable
only.Expand description
§Software Interrupts
The SoftwareInterruptControl
struct gives access to the available
software interrupts.
The SoftwareInterrupt
struct allows raising or resetting software
interrupts using the raise()
and
reset()
methods.
§Examples
let sw_ints =
SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
// Take the interrupt you want to use.
let mut int0 = sw_ints.software_interrupt0;
// Set up the interrupt handler. Do this in a critical section so the global
// contains the interrupt object before the interrupt is triggered.
critical_section::with(|cs| {
int0.set_interrupt_handler(swint0_handler);
SWINT0.borrow_ref_mut(cs).replace(int0);
});
// ... somewhere outside of your main function
// Define a shared handle to the software interrupt.
static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> =
Mutex::new(RefCell::new(None));
#[handler]
fn swint0_handler() {
println!("SW interrupt0 handled");
// Clear the interrupt request.
critical_section::with(|cs| {
if let Some(swint) = SWINT0.borrow_ref(cs).as_ref() {
swint.reset();
}
});
}
Structs§
- Software
Interrupt - A software interrupt can be triggered by software.
- Software
Interrupt Control - This gives access to the available software interrupts.