Expand description
Utilities for interrupt handling.
This crate provides:
-
An API to register scoped interrupts, inspired by
crossbeam::scope
.After registering interrupts using the
scoped_interrupts!
macro, thescope
function can be used to enter an “interrupt scope”, in which interrupt handlers can be registered for the duration of the scope. This allows them to make use of data defined in the calling function. -
A
PriorityLock
that allows sharing mutable data between interrupts at different priorities.
§Examples
Here is an example of how to use the Scoped Interrupts API with interrupts provided by an svd2rust-generated Peripheral Access Crate:
use irq::{scoped_interrupts, handler, scope};
use mock_pac::interrupt;
// Hook `INT0` and `INT1` using the `#[interrupt]` attribute imported above.
scoped_interrupts! {
enum Interrupt {
INT0,
INT1,
}
use #[interrupt];
}
fn main() {
// Define data to be used (via move or borrow) by the interrupt handlers.
let mut i = 0;
let shared = [0, 1, 2];
// Define handlers using the `handler!` macro.
handler!(int0 = || i += shared[1]);
handler!(int1 = || println!("{}", shared[2]));
// Create a scope and register the handlers.
scope(|scope| {
scope.register(Interrupt::INT0, int0);
scope.register(Interrupt::INT1, int1);
// The handlers stay registered as long as this closure executes.
// This is a good place for the application's main/idle loop.
loop {
// Do stuff.
}
});
// Now all handlers are deregistered again.
}
Macros§
- handler
- Defines a closure-based interrupt handler that can use stack-local data.
- scoped_
interrupts - Hooks interrupts and makes them available to the
scope
API.
Structs§
- Deadlock
- Error indicating that a lock could not be acquired in a high-priority context.
- Handler
- Wraps a closure used as an interrupt handler.
- Lock
Guard - A guard keeping a lock acquired until it is dropped.
- Lock
Half - One half of a
PriorityLock
. - Priority
Lock - A lock that allows sharing data between two interrupts at different priorities.
- Scope
- An interrupt scope created by the
scope
function.
Enums§
- PHigh
- Type marker indicating the high-priority half of a
PriorityLock
. - PLow
- Type marker indicating the low-priority half of a
PriorityLock
.
Traits§
- Interrupt
- Trait for interrupt enums generated by
scoped_interrupts!
. - Lock
Priority - Trait implemented by the lock priority types
PHigh
andPLow
.
Functions§
- scope
- Creates a scope in which interrupt handlers using stack-local data can be registered.