Skip to main content

Ethernet

Struct Ethernet 

Source
pub struct Ethernet<'d, DM: DriverMode, P: Phy> { /* private fields */ }
Expand description

EMAC Ethernet driver.

Implementations§

Source§

impl<'d, P: Phy> Ethernet<'d, Blocking, P>

Source

pub fn new<const RX: usize, const TX: usize>( eth: ETH<'d>, storage: &'d mut EthernetDmaStorage<RX, TX>, mac_addr: [u8; 6], phy: P, pins: impl EthernetPinBundle + 'd, ) -> Result<Self, Error>

Creates an Ethernet driver using RMII (RmiiPinBundle) or MII (MiiPinBundle).

Source

pub fn receive(&mut self) -> Result<&mut [u8], Error>

Returns the received frame data if one is ready.

Call pop_rx after processing the frame.

Source

pub fn pop_rx(&mut self)

Releases the current RX descriptor back to DMA.

Source

pub fn into_async(self) -> Ethernet<'d, Async, P>

Converts to async mode, enabling DMA interrupts and binding the ISR.

Source§

impl<'d, Dm: DriverMode, P: Phy> Ethernet<'d, Dm, P>

Source

pub fn set_speed(&mut self, speed: Speed)

Configures the MAC for the given speed.

Source

pub fn set_duplex(&mut self, duplex: Duplex)

Configures the MAC for the given duplex mode.

Source

pub fn transmit(&mut self, frame: &[u8]) -> Result<(), Error>

Copies frame into the next TX slot and initiates transmission.

Returns the current PHY link state.

Async callers are encouraged to pass the context to allow the PHY driver to wake them when the link state needs to be re-polled.

Source

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

Returns the MAC address configured during construction.

Source§

impl<'d, P: Phy> Ethernet<'d, Async, P>

Source

pub async fn transmit_async(&mut self, frame: &[u8]) -> Result<(), Error>

Asynchronously waits for a TX slot and transmits frame.

Source

pub async fn receive_async(&mut self, buf: &mut [u8]) -> Result<usize, Error>

Asynchronously waits for a frame and copies it into buf.

Source

pub fn into_blocking(self) -> Ethernet<'d, Blocking, P>

Converts back to blocking mode, disabling all DMA interrupts.

Source

pub fn tx_has_capacity(&self) -> bool

Returns true if there is at least one free TX descriptor slot.

Source

pub fn peek_rx(&mut self) -> Option<&mut [u8]>

Peeks at the next received frame without consuming it.

Returns Some(data_slice) if a valid frame is ready, or None. The caller must call release_rx after processing.

Source

pub fn release_rx(&mut self)

Releases the current RX descriptor back to the DMA engine.

Trait Implementations§

Source§

impl<'d, P: Phy> Driver for Ethernet<'d, Async, P>

Available on crate feature unstable only.
Source§

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

A token to receive a single network packet.
Source§

type TxToken<'a> = EthernetTxToken<'a, 'd> 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

Auto Trait Implementations§

§

impl<'d, DM, P> !RefUnwindSafe for Ethernet<'d, DM, P>

§

impl<'d, DM, P> !UnwindSafe for Ethernet<'d, DM, P>

§

impl<'d, DM, P> Freeze for Ethernet<'d, DM, P>
where P: Freeze, PhantomData<DM>: Freeze,

§

impl<'d, DM, P> Send for Ethernet<'d, DM, P>
where P: Send, PhantomData<DM>: Send,

§

impl<'d, DM, P> Sync for Ethernet<'d, DM, P>
where P: Sync, PhantomData<DM>: Sync,

§

impl<'d, DM, P> Unpin for Ethernet<'d, DM, P>
where P: Unpin, PhantomData<DM>: Unpin,

§

impl<'d, DM, P> UnsafeUnpin for Ethernet<'d, DM, P>
where P: UnsafeUnpin, PhantomData<DM>: 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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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.