pub trait Driver {
    type RxToken<'a>: RxToken
       where Self: 'a;
    type TxToken<'a>: TxToken
       where Self: 'a;

    // Required methods
    fn receive(
        &mut self,
        cx: &mut Context<'_>
    ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>;
    fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>;
    fn link_state(&mut self, cx: &mut Context<'_>) -> LinkState;
    fn capabilities(&self) -> Capabilities;
    fn hardware_address(&self) -> HardwareAddress;
}
Expand description

Main embassy-net driver API.

This is essentially an interface for sending and receiving raw network frames.

The interface is based on tokens, which are types that allow to receive/transmit a single packet. The receive and transmit functions only construct such tokens, the real sending/receiving operation are performed when the tokens are consumed.

Required Associated Types§

source

type RxToken<'a>: RxToken where Self: 'a

A token to receive a single network packet.

source

type TxToken<'a>: TxToken where Self: 'a

A token to transmit a single network packet.

Required Methods§

source

fn receive( &mut self, cx: &mut Context<'_> ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>

Construct a token pair consisting of one receive token and one transmit token.

If there is a packet ready to be received, this function must return Some. If there isn’t, it must return None, and wake cx.waker() when a packet is ready.

The additional transmit token makes it possible to generate a reply packet based on the contents of the received packet. For example, this makes it possible to handle arbitrarily large ICMP echo (“ping”) requests, where the all received bytes need to be sent back, without heap allocation.

source

fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>

Construct a transmit token.

If there is free space in the transmit buffer to transmit a packet, this function must return Some. If there isn’t, it must return None, and wake cx.waker() when space becomes available.

Note that TxToken::consume is infallible, so it is not allowed to return a token if there is no free space and fail later.

Get the link state.

This function must return the current link state of the device, and wake cx.waker() when the link state changes.

source

fn capabilities(&self) -> Capabilities

Get a description of device capabilities.

source

fn hardware_address(&self) -> HardwareAddress

Get the device’s hardware address.

The returned hardware address also determines the “medium” of this driver. This indicates what kind of packet the sent/received bytes are, and determines some behaviors of the interface. For example, ARP/NDISC address resolution is only done for Ethernet mediums.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<T: ?Sized + Driver> Driver for &mut T

§

type RxToken<'a> = <T as Driver>::RxToken<'a> where Self: 'a

§

type TxToken<'a> = <T as Driver>::TxToken<'a> where Self: 'a

source§

fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>

source§

fn receive( &mut self, cx: &mut Context<'_> ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>

source§

fn capabilities(&self) -> Capabilities

source§

fn hardware_address(&self) -> HardwareAddress

Implementors§