Module interrupt

Source
Expand description

§Interrupt support

§Overview

The interrupt driver is a crucial module for ESP chips. Its primary purpose is to manage and handle interrupts, which are asynchronous events requiring immediate attention from the CPU. Interrupts are essential in various applications, such as real-time tasks, I/O communications, and handling external events like hardware signals.

The core functionality of the interrupt driver revolves around the management of interrupts. When an interrupt occurs, it temporarily stops the ongoing CPU operations, saves its current state, and starts executing the corresponding interrupt service routine (ISR). The interrupt service routine is a user-defined function that performs the necessary actions to handle the specific interrupt. Once the ISR is executed, the driver restores the saved CPU state and resumes normal program execution.

In scenarios where multiple interrupts may occur simultaneously, the interrupt driver determines the priority of each interrupt. This prioritization ensures that critical or high-priority tasks are handled first. It helps prevent delays in time-sensitive applications and allows the system to allocate resources efficiently. This functionality is provided and implemented by the priority enum.

§Example

#[entry]
fn main() -> ! {
    ...
    critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int));

    interrupt::enable(
        peripherals::Interrupt::FROM_CPU_INTR0,
        interrupt::Priority::Priority1,
    )
    .unwrap();

    loop {}
}

#[interrupt]
fn FROM_CPU_INTR0() {
    esp_println::println!("SW interrupt0");
    critical_section::with(|cs| {
        SWINT
            .borrow_ref_mut(cs)
            .as_mut()
            .unwrap()
            .reset(SoftwareInterrupt::SoftwareInterrupt0);
    });
}

Structs§

TrapFrame
Registers saved in trap handler

Enums§

CpuInterrupt
Enumeration of available CPU interrupts. It is possible to create a handler for each of the interrupts. (e.g. interrupt3)
Error
Interrupt Error
InterruptKind
Interrupt kind
Priority
Interrupt priority levels.

Functions§

clear
Clear a CPU interrupt
disable
Disable the given peripheral interrupt.
enable
Enables a interrupt at a given priority
enable_cpu_interrupt
Enable a CPU interrupt
get_status
Get status of peripheral interrupts
interrupt1
interrupt2
interrupt3
interrupt4
interrupt5
interrupt6
interrupt7
interrupt8
interrupt9
interrupt10
interrupt11
interrupt12
interrupt13
interrupt14
interrupt15
interrupt16
interrupt17
interrupt18
interrupt19
map
Assign a peripheral interrupt to an CPU interrupt.
set_kind
Set the interrupt kind (i.e. level or edge) of an CPU interrupt
set_priority
Set the priority level of an CPU interrupt