unstable
only.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
.
§Examples
§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| {
if let Some(swint) = SWINT0.borrow_ref(cs).as_ref(){
swint.raise();
}
});
static SWINT0: Mutex<RefCell<Option<SoftwareInterrupt<0>>>> =
Mutex::new(RefCell::new(None));
#[handler(priority = Priority::Priority1)]
fn swint0_handler() {
println!("SW interrupt0");
critical_section::with(|cs| {
if let Some(swint) = SWINT0.borrow_ref(cs).as_ref() {
swint.reset();
}
});
}
Modules§
- software
- Software Interrupts
Structs§
- Interrupt
Handler - An interrupt handler
- Interrupt
Status - Representation of peripheral-interrupt status bits.
- Interrupt
Status Iterator - Iterator over set interrupt status bits
- Trap
Frame - 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
- Interrupt
Kind - Interrupt kind
- Priority
- Interrupt priority levels.
Constants§
- DEFAULT_
INTERRUPT_ HANDLER - Default (unhandled) interrupt handler
Statics§
- RESERVED_
INTERRUPTS - The interrupts reserved by the HAL
Traits§
- Interrupt
Configurable - Trait implemented by drivers which allow the user to set an InterruptHandler
Functions§
- bind_
interrupt ⚠ - Binds the given interrupt to the given handler.
- bound_
handler - Returns the currently bound interrupt handler.
- 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
- enable_
direct - Enable an interrupt by directly binding it to a available CPU interrupt
- 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
- status
- Get status of peripheral interrupts