Skip to main content

EmacDriver

Struct EmacDriver 

Source
pub struct EmacDriver<'d, const RX: usize, const TX: usize, const BUF: usize> { /* private fields */ }
Expand description

embassy-net driver for the ESP32 EMAC.

The driver holds a raw pointer to a previously-initialized Emac together with a reference to a shared EmacDriverState.

§Concurrent ownership

At most one EmacDriver can hold the &'d mut Emac<...> at a time. The borrow checker enforces that through the &'d mut argument to Self::new — concurrent aliasing is impossible. Sequential reuse is fine: once a driver is dropped, the same Emac can be paired with a fresh driver again. The unit tests in this module exercise that pattern.

The companion EmacDriverState is not a strict singleton — see the module-level Lifetime alignment section. The constraint is that whichever instance the EMAC ISR’s EmacDriverState::handle_emac_interrupt runs against must be the same one passed here as state.

For the default ring sizing the EmacDefaultDriver<'d> alias removes the need to repeat the const generics in embassy_executor::task signatures.

§Safety

The pointer is dereferenced in Driver impl methods. The lifetime 'd ensures the underlying Emac outlives the driver, but the raw pointer means mutable aliasing would be unsound. The at-most-one-concurrent-driver invariant above is what keeps that aliasing impossible in practice.

Implementations§

Source§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> EmacDriver<'d, RX, TX, BUF>

Source

pub fn new(emac: &'d mut Emac<RX, TX, BUF>, state: &'d EmacDriverState) -> Self

Create a new embassy-net driver.

emac must be already initialized and started; state must be the same instance whose [on_interrupt_status] is called from the EMAC ISR.

Source

pub fn state(&self) -> &EmacDriverState

Borrow the shared state.

Source

pub const fn effective_mtu() -> usize

Effective MTU advertised to embassy-net and used as the readiness threshold in Driver::transmit.

Capped by the physical TX ring capacity (TX * BUF) so the driver never advertises — and never gates on — a frame size the engine couldn’t actually push. On normal rings (e.g. TX=10, BUF=1600) this returns the standard Ethernet MTU of 1514. On undersized rings (TX * BUF < 1514) it shrinks to TX * BUF, so small frames still flow even though full-MTU frames are physically impossible.

Trait Implementations§

Source§

impl<const RX: usize, const TX: usize, const BUF: usize> Driver for EmacDriver<'_, RX, TX, BUF>

Source§

type RxToken<'a> = EmacRxToken<'a, RX, TX, BUF> where Self: 'a

A token to receive a single network packet.
Source§

type TxToken<'a> = EmacTxToken<'a, RX, TX, BUF> where Self: 'a

A token to transmit a single network packet.
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. Read more
Source§

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

Construct a transmit token. Read more
Get the link state. Read more
Source§

fn capabilities(&self) -> Capabilities

Get a description of device capabilities.
Source§

fn hardware_address(&self) -> HardwareAddress

Get the device’s hardware address. Read more
Source§

impl<const RX: usize, const TX: usize, const BUF: usize> Send for EmacDriver<'_, RX, TX, BUF>
where Emac<RX, TX, BUF>: Send,

Auto Trait Implementations§

§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> Freeze for EmacDriver<'d, RX, TX, BUF>

§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> !RefUnwindSafe for EmacDriver<'d, RX, TX, BUF>

§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> !Sync for EmacDriver<'d, RX, TX, BUF>

§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> Unpin for EmacDriver<'d, RX, TX, BUF>

§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> UnsafeUnpin for EmacDriver<'d, RX, TX, BUF>

§

impl<'d, const RX: usize, const TX: usize, const BUF: usize> !UnwindSafe for EmacDriver<'d, RX, TX, BUF>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.