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<B: EthernetPinBundle + 'd, const RX: usize, const TX: usize>( eth: ETH<'d>, storage: &'d mut EthernetDmaStorage<RX, TX>, mac_addr: [u8; 6], phy: P, pins: B, ) -> 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.

The DMA ISR is bound and its interrupts enabled on the first link-up, not here: without a link there is no RX clock and the DMA would only report errors.

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.

The speed must be one the wired interface can carry: MII and RMII top out at 100 Mbps, only RGMII reaches 1000 Mbps.

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 whether 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.

Polls the PHY and tracks the DMA interrupt state with the link.

DMA interrupts are only enabled while the link is up: with no link there is no RX clock, and error interrupts would otherwise fire continuously.

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
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<'d, Dm: DriverMode + 'static, P: Phy> Driver for Ethernet<'d, Dm, P>

Available on crate feature unstable only.
Source§

fn capabilities(&self) -> Capabilities

Get a description of the device’s capabilities.
Source§

fn hardware_address(&self) -> HardwareAddress

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

fn register_waker(&mut self, waker: &Waker) -> Result<(), NotSupported>

Available on crate feature async only.
Register a waker. Read more
Source§

fn receive(&mut self) -> Option<PacketBuf>

Poll for a received frame. Read more
Source§

fn can_transmit(&mut self) -> bool

Whether the device can transmit one frame right now. Read more
Source§

fn transmit(&mut self, buffer: PacketBuf) -> Result<(), PacketBuf>

Queue a frame for transmission, transferring ownership of the buffer to the driver. Read more
Source§

fn set_multicast_filter(&mut self, addrs: &[[u8; 6]])

Set the device’s multicast hardware address filter. 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.