Available on crate feature
unstable only.Expand description
§Software Interrupts
The SoftwareInterrupt struct allows raising or resetting software
interrupts using the raise() and
reset() methods.
§Examples
// Take the interrupt you want to use.
let mut int0 = SoftwareInterrupt::new(peripherals.FROM_CPU_INTR0);
// 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));
#[esp_hal::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.
Traits§
- Instance
- A software interrupt instance.