#channel #raspberry-pi #bare-metal #async #ruspiro

no-std ruspiro-channel

Bare Metal Channel implementations for no-std environments, only requiring an allocator to be provided

2 releases

0.1.1 Apr 27, 2021
0.1.0 Jan 31, 2021

#2099 in Embedded development

Download history 2/week @ 2023-12-11 6/week @ 2023-12-18 2/week @ 2023-12-25 9/week @ 2024-01-08 5/week @ 2024-02-05 15/week @ 2024-02-12 17/week @ 2024-02-19 35/week @ 2024-02-26 30/week @ 2024-03-04 23/week @ 2024-03-11 25/week @ 2024-03-18 36/week @ 2024-03-25

114 downloads per month
Used in 5 crates (via ruspiro-interrupt)

MIT/Apache

16KB
200 lines

RusPiRo Channel

CI Latest Version Documentation License

Usage

To use this crate simply add the dependency to your Cargo.toml file:

[dependencies]
ruspiro-channel = "0.1.1"

The crate actually implements a multi producer - multi consumer (mpmc) channel only. The channel itself is non blocking but uses atomic operations. When used in a bare metal Raspberry Pi project it has to ensured that atomic operations can be used (configured and enabled MMU - see ruspiro-mmu crate).

The creation of a channel provides the sender and the receiver part of it. Both can be cloned if required.

use ruspiro_channel::mpmc;

fn main() {
  let (tx, rx) = mpmc::channel();

  tx.send(50u32);
  // this is non-blocking and returns `Err` if the channel has no more data
  if let Ok(value) = tx.recv() {
    assert_eq!(value, 50);
  }
}

With the async feature activated an async-channel can be created and the receiver is able to await available messages.

// it's assumed the crate is compiled with features = ["async"]
use ruspiro_channel::mpmc;

async fn foo() {
  let (tx, mut rx) = mpmc::async_channel();

  tx.send(42u32);
  while let Some(value) = rx.next().await {
    assert_eq!(value, 42);
  }
}

Features

Feature Description
async Enables the async version of the channel implementation.

Dependencies

~84–255KB