ruspiro-interrupt 0.4.2

Providing a simple and convinient way to implement interrupt handler for Raspberry Pi interrupts.
docs.rs failed to build ruspiro-interrupt-0.4.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: ruspiro-interrupt-0.3.1

Interrupt handler for Raspberry Pi

This crates provides functions and macros (custom attribute) to conviniently implement interrupt handler for Raspberry Pi 3. The possible interrupts a handler can be implemented for are available as enum [irqtypes::Interrupt]

Usage

extern crate ruspiro_interrupt; // <- this kind of usage is VERY IMPORTANT to ensure linking works as expected!
use ruspiro_interrupt::{self as irq, IrqHandler, IsrSender, isr_channel};

#[IrqHandler(ArmTimer)]
fn timer_handler(tx: Option<IsrSender<Box<dyn Any>>>) {
// IMPORTANT: acknowledge the irq !

// implement stuff that shall be executed if the interrupt is raised...
// be careful when this code uses spinlocks as this might lead to dead-locks if the
// executing code interrupted currently helds a lock the code inside this handler tries to aquire the same one
}

In some cases the interrupt type/line is shared between different sources. In those cases a handler need to be implemented for the specific interrupt source. The source is given in the custom attribute like this:

extern crate ruspiro_interrupt; // <- this kind of usage is VERY IMPORTANT to ensure linking works as expected!
use ruspiro_interrupt::*;

#[IrqHandler(Aux, Uart1)]
fn aux_uart1_handler(tx: Option<IsrSender<Box<dyn Any>>>) {
// implement Uart1 interrupt handler here
}

With the actual interrupt handling routines in place they the corresponding interrupts need to be configured and activated like the following.

fn main() {
// as we have an interrupt handler defined we need to enable interrupt handling globally as well
// as the specific interrupt we have a handler implemented for
irq::initialize();
// activate an irq that use a channel to allow notification to flow from the interrupt handler to the "normal"
// processing
let (timer_tx, mut timer_rx) = isr_channel::<()>();
irq::activate(Interrupt::ArmTimer, timer_tx);
// activate an irq that does not use a channel as all processing is done inside it's handler
irq::activate(Interrupt::Aux, None);
});

enable_interrupts();

// wait for the interrupt to send some data along (blocking current execution)
let _ = timer_rx.recv();

// when the crate is used with the feature `async` beeing set, waiting for
// for the data send by the interrupt would look like this:
while let Some(_) = timer_rx.next().await {
// do stuff ...
}
}

Limitations

However, only a limited ammount of shared interrupt lines implementation is available with the current version - which is only the Aux interrupt at the moment.