Skip to main content

Ethernet

Struct Ethernet 

Source
pub struct Ethernet<'d, T: Instance, const TX: usize, const RX: usize, P: Phy> { /* private fields */ }
Expand description

Ethernet MAC driver.

TX and RX are the number of DMA descriptors (and buffers) in each ring.

Implementations§

Source§

impl<'d, T: Instance, const TX: usize, const RX: usize> Ethernet<'d, T, TX, RX, InternalPhy>

Source

pub fn new_internal( peri: Peri<'d, T>, irqs: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, queue: &'d mut PacketQueue<TX, RX>, mac_addr: [u8; 6], ) -> Result<Self, InitError>

Initialize Ethernet using the built-in 10M PHY at its fixed SMI address. No external MII/RMII pins are needed. The PHY is clocked from the HSE through PLL3.

§Errors

Returns an error if PLL3 does not lock, or if DMA reset or a PHY management transaction times out.

Source§

impl<'d, T: Instance, const TX: usize, const RX: usize, P: Phy> Ethernet<'d, T, TX, RX, P>

Source

pub fn new_rmii( peri: Peri<'d, T>, irqs: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, queue: &'d mut PacketQueue<TX, RX>, pins: RmiiPins<'d, impl RefClkPin<T>, impl MdioPin<T>, impl MdcPin<T>, impl CrsDvPin<T>, impl Rxd0Pin<T>, impl Rxd1Pin<T>, impl TxEnPin<T>, impl Txd0Pin<T>, impl Txd1Pin<T>>, phy: P, mac_addr: [u8; 6], ) -> Result<Self, InitError>

Initialize Ethernet using an external PHY connected through RMII. The driver configures and retains the supplied pins using the default mapping.

§Errors

Returns an error if DMA reset or a PHY management transaction times out.

Source

pub fn new_rmii_without_smi( peri: Peri<'d, T>, irqs: impl Binding<T::Interrupt, InterruptHandler<T>> + 'd, queue: &'d mut PacketQueue<TX, RX>, pins: RmiiDataPins<'d, impl RefClkPin<T>, impl CrsDvPin<T>, impl Rxd0Pin<T>, impl Rxd1Pin<T>, impl TxEnPin<T>, impl Txd0Pin<T>, impl Txd1Pin<T>>, phy: P, mac_addr: [u8; 6], ) -> Result<Self, InitError>

Initialize Ethernet using an external PHY connected through RMII, without MDIO and MDC: the application manages the PHY on a bus of its own (for example MDIO driven by GPIO, as it may need to keep managing the PHY across a MAC reset). The driver configures and retains the seven data pins using the default mapping.

The driver does not configure or retain MDIO and MDC, but still calls every Phy method: the implementation must ignore the Smi it gets and report what the application learnt from the PHY. GenericPhy and InternalPhy are not suitable.

§Errors

Returns an error if DMA reset times out or a phy method returns an error.

Source

pub fn smi(&mut self) -> &mut Smi

Get the SMI interface for direct PHY register access.

Source

pub fn mac_addr(&self) -> [u8; 6]

Get the configured MAC address.

Source

pub fn set_promiscuous(&mut self, on: bool)

Receive frames for every destination address, not only this MAC’s, its multicast and broadcast: what a bridge needs. The setting survives the driver’s own MAC/DMA resets.

Source

pub fn receive_frame( &mut self, cx: &mut Context<'_>, ) -> Option<RxToken<'_, 'd, T, RX>>

Receive one frame whatever the transmit ring holds.

receive() of embassy_net_driver::Driver also needs a free transmit descriptor, as the stack may answer at once. A bridge forwards frames to another interface instead: it must keep receiving while its own transmit ring is full. The token tells the frame’s length before it is consumed, so a frame with nowhere to go yet can be left in the ring.

Source

pub fn stats(&self) -> Stats

Counts since initialization, wrapping. This does not read the hardware: the counts are as of the last receive or transmit call.

Trait Implementations§

Source§

impl<'d, T: Instance, const TX: usize, const RX: usize, P: Phy> Driver for Ethernet<'d, T, TX, RX, P>

Source§

type RxToken<'a> = RxToken<'a, 'd, T, RX> where Self: 'a

A token to receive a single network packet.
Source§

type TxToken<'a> = TxToken<'a, 'd, T, TX> 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
Source§

fn capabilities(&self) -> Capabilities

Get a description of device capabilities.
Get the link state. Read more
Source§

fn hardware_address(&self) -> HardwareAddress

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

impl<'d, T: Instance, const TX: usize, const RX: usize, P: Phy> Drop for Ethernet<'d, T, TX, RX, P>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'d, T, const TX: usize, const RX: usize, P> !UnwindSafe for Ethernet<'d, T, TX, RX, P>

§

impl<'d, T, const TX: usize, const RX: usize, P> Freeze for Ethernet<'d, T, TX, RX, P>
where P: Freeze,

§

impl<'d, T, const TX: usize, const RX: usize, P> RefUnwindSafe for Ethernet<'d, T, TX, RX, P>
where P: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'d, T, const TX: usize, const RX: usize, P> Send for Ethernet<'d, T, TX, RX, P>
where P: Send, T: Send,

§

impl<'d, T, const TX: usize, const RX: usize, P> Sync for Ethernet<'d, T, TX, RX, P>
where P: Sync, T: Sync,

§

impl<'d, T, const TX: usize, const RX: usize, P> Unpin for Ethernet<'d, T, TX, RX, P>
where P: Unpin, T: Unpin,

§

impl<'d, T, const TX: usize, const RX: usize, P> UnsafeUnpin for Ethernet<'d, T, TX, RX, P>
where P: UnsafeUnpin,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.