diff --git a/esp-hal/src/interrupt/mod.rs b/esp-hal/src/interrupt/mod.rs index f7b92eee38e..5652e0b8b5e 100644 --- a/esp-hal/src/interrupt/mod.rs +++ b/esp-hal/src/interrupt/mod.rs @@ -1,27 +1,18 @@ //! # 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. +//! Interrupt support functionality depends heavily on the features enabled. //! +//! When the `vectored` feature is enabled, the +//! [`enable`] method will map interrupt to a CPU +//! interrupt, and handle the `vector`ing to the peripheral interrupt, for +//! example `UART0`. +//! +//! It is also 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. +//! +//! The `vectored` reserves a number of CPU interrupts, which cannot be used see +//! [`RESERVED_INTERRUPTS`]. //! //! ## Example //! ```no_run @@ -30,12 +21,20 @@ //! ... //! critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); //! +//! // enable the interrupt //! interrupt::enable( //! peripherals::Interrupt::FROM_CPU_INTR0, //! interrupt::Priority::Priority1, //! ) //! .unwrap(); //! +//! // trigger the interrupt +//! SWINT +//! .borrow_ref_mut(cs) +//! .as_mut() +//! .unwrap() +//! .raise(SoftwareInterrupt::SoftwareInterrupt0); +//! //! loop {} //! } //! diff --git a/esp-hal/src/interrupt/riscv.rs b/esp-hal/src/interrupt/riscv.rs index 910bea31a66..dc6337d1c97 100644 --- a/esp-hal/src/interrupt/riscv.rs +++ b/esp-hal/src/interrupt/riscv.rs @@ -781,7 +781,7 @@ mod plic { pub(super) unsafe extern "C" fn _handle_priority() -> u32 { use super::mcause; let plic_mxint_pri_ptr = PLIC_MXINT0_PRI_REG as *mut u32; - let interrupt_id: isize = mcause::read().code().try_into().unwrap(); // MSB is whether its exception or interrupt. + let interrupt_id: isize = unwrap!(mcause::read().code().try_into()); // MSB is whether its exception or interrupt. let interrupt_priority = plic_mxint_pri_ptr.offset(interrupt_id).read_volatile(); let thresh_reg = PLIC_MXINT_THRESH_REG as *mut u32;