esp_hal

Module interrupt

Source
Expand description

§Interrupt support

§Overview

This module routes one or more peripheral interrupt sources to any one of the CPU’s peripheral interrupts.

§Configuration

Usually peripheral drivers offer a mechanism to register your interrupt handler. e.g. the systimer offers set_interrupt_handler to register a handler for a specific alarm. Other drivers might take an interrupt handler as an optional parameter to their constructor.

This is the preferred way to register handlers.

There are additional ways to register interrupt handlers which are generally only meant to be used in very special situations (mostly internal to the HAL or the supporting libraries). Those are outside the scope of this documentation.

It is even possible, but not recommended, to bind an interrupt directly to a CPU interrupt. This can offer lower latency, at the cost of more complexity in the interrupt handler. See the direct_vectoring.rs example

We reserve a number of CPU interrupts, which cannot be used; see RESERVED_INTERRUPTS.

§Example

§Using the peripheral driver to register an interrupt handler

let mut sw_int =
    SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
critical_section::with(|cs| {
    sw_int
        .software_interrupt0
        .set_interrupt_handler(swint0_handler);
    SWINT0
        .borrow_ref_mut(cs)
        .replace(sw_int.software_interrupt0);
});

critical_section::with(|cs| {
    SWINT0.borrow_ref(cs).as_ref().unwrap().raise();
});

static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> =
    Mutex::new(RefCell::new(None));

#[handler(priority = Priority::Priority1)]
fn swint0_handler() {
    // esp_println::println!("SW interrupt0");
    critical_section::with(|cs| {
        SWINT0.borrow_ref(cs).as_ref().unwrap().reset();
    });
}

Modules§

Structs§

Enums§

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

Statics§

Functions§

  • Binds the given interrupt to the given handler.
  • Returns the currently bound interrupt handler.
  • Clear a CPU interrupt
  • Disable the given peripheral interrupt.
  • Enables a interrupt at a given priority
  • Enable a CPU interrupt
  • Enable an interrupt by directly binding it to a available CPU interrupt
  • map
    Assign a peripheral interrupt to an CPU interrupt.
  • Set the interrupt kind (i.e. level or edge) of an CPU interrupt
  • Set the priority level of an CPU interrupt
  • Get status of peripheral interrupts