Skip to content

Instantly share code, notes, and snippets.

@jamesmunns
Created July 19, 2022 22:46
Show Gist options
  • Save jamesmunns/e25b618fd25e785f0839ae72b1e59e96 to your computer and use it in GitHub Desktop.
Save jamesmunns/e25b618fd25e785f0839ae72b1e59e96 to your computer and use it in GitHub Desktop.
//! A basic loop-back task on port 100
//!
//! Using https://github.com/tosc-rs/mnemos/pull/25
// Holds the types and uuid constant
use drivers::SerialPorts;
// Get the serial port mux interface, taking a read
// lock on the registry. We don't know the kind or
// implementor of the SerialPorts driver, just its'
// messaging interface. Like "traits via message passing".
//
// Returns Ok if there is a runtime-registered serial
// port driver available.
let ports = SerialPorts::new(
&kernel.registry().await,
).await?;
// Open up port 0, gives us back a bidirectional
// bbq stream interface. Under the hood, this sends
// a message to the driver, and waits for the response.
let port_0 = ports.open(100).await?;
// Spawn a "loopback port" task
kernel.spawn(async move {
// We communicate with the driver regarding the port
// exclusively through the stream interface.
loop {
let mut rgr = port_0.reader().read_grant().await;
let len = rgr.len();
port_0.send(&rgr).await;
rgr.release(len);
}
}).await;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment