2 releases

0.1.0-alpha4 Oct 17, 2024

#509 in Hardware support

MIT license

12KB
270 lines

This crate provides "null modem" PHY drivers for smoltcp in both allocating and non-allocating variants.

You can see a null modem as a two-ended in-memory pipe, where both ends are smoltcp::phy::Device and the TX of one is connected directly to the RX of the other (and vice versa).

Example

use smoltcp::{
    phy::{
        Medium,
        Device as _,
        TxToken as _,
        RxToken as _,
    },
    time::Instant,
};

const MTU: usize = 128;
const CAPACITY: usize = 4;

let mut modem = smoltcp_null_modem::noalloc::<CAPACITY, MTU>(Medium::Ethernet);
let (mut phy1, mut phy2) = modem.split();

// Send a frame into the first interface
let tok = phy1.transmit(Instant::now()).unwrap();
tok.consume(10, |buf| {
    buf.copy_from_slice(&[0xa5; 10]);
});

// And it appears on the second
let (tok, _) = phy2.receive(Instant::now()).unwrap();
tok.consume(|buf| {
    assert_eq!(buf, &[0xa5; 10]);
});

Dependencies

~2.5MB
~55K SLoC