pub struct Interrupt { /* private fields */ }
Expand description
A hardware interrupt object.
This object provides functionalities to handle hardware interrupts from devices in device drivers:
- Enable interrupts by acquiring the object (
Interrupt::create
). - Acknowledge the interrupt (
Interrupt::acknowledge
). - Wait for interrupts in an event loop (
Mainloop::add_interrupt
)
§Example
use starina_api::interrupt::Interrupt;
use starina_api::types::interrupt::Irq;
// Ideally, you should get the IRQ from the device tree.
let irq = Irq::new(1);
// Acquire the ownership of the interrupt.
let interrupt = Interrupt::create(irq).unwrap();
// Register the interrupt to the mainloop.
let mut mainloop = Mainloop::new().unwrap();
mainloop
.add_interrupt(interrupt, Context::Interrupt)
.unwrap();
// Wait for interrupts in the mainloop...
loop {
match mainloop.next() {
Event::Interrupt { ctx: Context::Interrupt, .. } => {
// Handle the interrupt.
do_something();
// Tell the kernel that we have handled the interrupt and are
// ready for the next one.
interrupt.acknowledge().unwrap();
}
ev => {
warn!("unexpected event: {:?}", ev);
}
}
}
Implementations§
Source§impl Interrupt
impl Interrupt
Sourcepub fn create(irq: Irq) -> Result<Interrupt, FtlError>
pub fn create(irq: Irq) -> Result<Interrupt, FtlError>
Creates a new interrupt object for the given IRQ.
Sourcepub fn from_handle(handle: OwnedHandle) -> Interrupt
pub fn from_handle(handle: OwnedHandle) -> Interrupt
Instantiates the object from the given handle.
Sourcepub fn handle(&self) -> &OwnedHandle
pub fn handle(&self) -> &OwnedHandle
Returns the handle.
Sourcepub fn acknowledge(&self) -> Result<(), FtlError>
pub fn acknowledge(&self) -> Result<(), FtlError>
Acknowledges the interrupt.
This tells the CPU (or the interrupt controller) that the interrupt has been handled and we are ready to receive the next one.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Interrupt
impl RefUnwindSafe for Interrupt
impl Send for Interrupt
impl Sync for Interrupt
impl Unpin for Interrupt
impl UnwindSafe for Interrupt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more