irq

Crates.ioirq
lib.rsirq
version0.2.3
sourcesrc
created_at2020-01-19 18:59:41.552866
updated_at2020-03-08 13:18:51.618677
descriptionScoped interrupt handlers and interrupt locks for sharing data
homepage
repositoryhttps://github.com/jonas-schievink/irq.git
max_upload_size
id200208
size38,229
Jonas Schievink (jonas-schievink)

documentation

https://docs.rs/irq/

README

IRQ – Utilities for writing Interrupt Handlers

crates.io docs.rs Build Status

This crate provides utilities for handling interrupts on embedded devices.

Please refer to the changelog to see what changed in the last releases.

Features

  • Dynamically and atomically registered, zero-allocation interrupt handlers.
  • Allows moving data into interrupt handlers, and sharing data between handlers.
  • Completely platform agnostic, does not require atomic swap operations (works on eg. thumbv6 targets).

Usage

Add an entry to your Cargo.toml:

[dependencies]
irq = "0.2.3"

Check the API Documentation for how to use the crate's functionality. A small example showcasing the Scoped Interrupts API is provided below:

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 interrupts stay registered for the duration of this closure.
        // This is a good place for the application's idle loop.
    });
}

Rust version support

This crate targets stable Rust. No guarantees are made beyond that, so the minimum supported version might be bumped as needed.

The MSRV is also explicitly tested against in .travis.yml.

Commit count: 35

cargo fmt