pub struct InterruptPoller { /* private fields */ }
Expand description
A mechanism for synchronously managing and polling x86 interrupts.
Tock uses synchronous polling to service interrupts. This means that the kernel’s main loop will periodically call some function to detect and service interrupts. The reasoning for this approach (as opposed to doing work directly within ISRs) is so we can lean on Rust’s borrow checker to avoid race conditions.
The InterruptPoller
type provides a somewhat higher-level API for working with x86 interrupts
that fits well with Tock’s synchronous lifecycle. It is modeled after the Plic
API from the
e310x
chip crate.
Internally, it maintains a large bitfield with a separate flag for every possible interrupt
vector (total of NUM_VECTORS
). When an interrupt occurs, a very lightweight ISR is
responsible for setting the corresponding flag. To poll for pending interrupts from within the
kernel loop, we simply need to iterate over this bitfield and return the index of each active
bit.
Note that for reasons of safety, InterruptPoller
is a singleton. You cannot create an instance
directly. Instead, you must access the singleton instance using InterruptPoller::access
.
Implementations§
Source§impl InterruptPoller
impl InterruptPoller
Sourcepub fn access<F, R>(f: F) -> Rwhere
F: FnOnce(&InterruptPoller) -> R,
pub fn access<F, R>(f: F) -> Rwhere
F: FnOnce(&InterruptPoller) -> R,
Provides safe access to the singleton instance of InterruptPoller
.
The given closure f
is executed with interrupts disabled (using support::atomic
) and
passed a reference to the singleton.
Sourcepub unsafe fn set_pending(num: u32)
pub unsafe fn set_pending(num: u32)
Marks that the specified interrupt as pending.
§Safety
Interrupts must be disabled when this function is called. This function is intended to be called from within an ISR, so hopefully this is already true.
Sourcepub fn next_pending(&self) -> Option<u32>
pub fn next_pending(&self) -> Option<u32>
Polls for the next pending interrupt.
If multiple interrupts are currently pending, then the highest priority (i.e. numerically lowest) is returned.
Once handled, interrupts should call clear_pending
to clear the interrupt’s pending status
so that lower-priority interrupts can be serviced.
Sourcepub fn clear_pending(&self, num: u32)
pub fn clear_pending(&self, num: u32)
Clears the pending status of the specified interrupt, allowing lower priority interrupts to be serviced.
Don’t forget to call this method after servicing an interrupt.