Skip to main content

Module software

Module software 

Source
Available on crate feature unstable only.
Expand description

§Software Interrupts

SoftwareInterrupt raises or resets software interrupts with raise() and reset(). The HAL reserves FROM_CPU_INTR0 and FROM_CPU_INTR1 for inter-processor call (IPC).

§Examples

// Take the interrupt you want to use.
let mut int0 = SoftwareInterrupt::new(peripherals.FROM_CPU_INTR2);

// 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<2>>>> = 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§

SoftwareInterrupt
A software interrupt can be triggered by software.

Traits§

Instance
A software interrupt instance.