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>
impl<'d, const RX: usize, const TX: usize, const BUF: usize> EmacDriver<'d, RX, TX, BUF>
Sourcepub fn new(emac: &'d mut Emac<RX, TX, BUF>, state: &'d EmacDriverState) -> Self
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.
Sourcepub fn state(&self) -> &EmacDriverState
pub fn state(&self) -> &EmacDriverState
Borrow the shared state.
Sourcepub const fn effective_mtu() -> usize
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.