starina_api::interrupt

Struct Interrupt

Source
pub struct Interrupt { /* private fields */ }
Expand description

A hardware interrupt object.

This object provides functionalities to handle hardware interrupts from devices in device drivers:

§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

Source

pub fn create(irq: Irq) -> Result<Interrupt, FtlError>

Creates a new interrupt object for the given IRQ.

Source

pub fn from_handle(handle: OwnedHandle) -> Interrupt

Instantiates the object from the given handle.

Source

pub fn handle(&self) -> &OwnedHandle

Returns the handle.

Source

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§

Source§

impl Debug for Interrupt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.