Loading...
Searching...
No Matches

Driver for the EFM32 Ethernet peripheral. More...

Detailed Description

Driver for the EFM32 Ethernet peripheral.

Link State Events

To enable Link Events, use the (pseudo) module efm32_eth_link_up. This module will monitor the link state, and will emit events when the link goes up or down.

Link Auto Negotiation

To enable Link Auto Negotiation, use the (pseudo) module efm32_eth_auto.

In general, it is highly recommended to use auto-negotiation, as this can avoid various communication issues on the PHY layer due to configuration mismatch of the link partners.

This feature depends on the link state events feature.

Files

file  efm32_eth_netdev.h
 Setup for netdev for the EFM32 ethernet peripheral.
 
file  eth.h
 Low-level Ethernet driver interface for the EFM32.
 

Functions

void efm32_eth_netdev_setup (netdev_t *netdev)
 Bind the given netdev to the EFM32 ethernet driver.
 
int efm32_eth_init (const uint8_t *mac)
 Initialize the ETH peripheral and PHY.
 
int efm32_eth_send (const iolist_t *iolist)
 Submit a frame for transmission.
 
int efm32_eth_recv (void *buf, size_t max_len)
 Receive a frame from the RX ring.
 
void efm32_eth_get_mac (uint8_t out[6])
 Read the currently programmed MAC address.
 
void efm32_eth_set_mac (const uint8_t mac[6])
 Program a new MAC address.
 
bool efm32_eth_link_up (void)
 Read the PHY link status (BMSR.LINK)
 
bool efm32_eth_rx_pending (void)
 Return true if the RX ring contains at least one unconsumed frame.
 
int efm32_eth_tx_status (void)
 Query the completion status of the most recent transmission.
 
void efm32_eth_set_promiscuous (bool enable)
 Enable or disable promiscuous mode.
 
bool efm32_eth_get_promiscuous (void)
 Return the current promiscuous mode setting.
 
void efm32_eth_set_link_speed (uint16_t speed)
 Configure the MAC for a given link speed and duplex.
 
int efm32_eth_start_auto_negotiation (void)
 Start PHY auto-negotiation.
 
void efm32_eth_complete_auto_negotiation (void)
 Complete auto-negotiation and apply speed/duplex to the MAC.
 

Variables

const netdev_driver_t efm32_eth_driver
 The netdev driver for the EFM32 ethernet peripheral.
 

Function Documentation

◆ efm32_eth_complete_auto_negotiation()

void efm32_eth_complete_auto_negotiation ( void )

Complete auto-negotiation and apply speed/duplex to the MAC.

Waits until the PHY reports auto-negotiation complete, then derives the negotiated speed and duplex from the advertised and link-partner capability registers and programs ETH->NETWORKCFG accordingly.

◆ efm32_eth_get_mac()

void efm32_eth_get_mac ( uint8_t out[6])

Read the currently programmed MAC address.

Parameters
[out]outDestination buffer of at least 6 bytes

◆ efm32_eth_get_promiscuous()

bool efm32_eth_get_promiscuous ( void )

Return the current promiscuous mode setting.

Returns
true if promiscuous mode is enabled, false otherwise

◆ efm32_eth_init()

int efm32_eth_init ( const uint8_t * mac)

Initialize the ETH peripheral and PHY.

Parameters
[in]mac6-byte MAC address to program into SPECADDR1{TOP,BOTTOM}
Return values
0on success
-ENODEVif the PHY could not be detected
-EIOif the PHY could not be initialized

◆ efm32_eth_link_up()

bool efm32_eth_link_up ( void )

Read the PHY link status (BMSR.LINK)

Return values
trueif the link is up
falseif the link is down

◆ efm32_eth_netdev_setup()

void efm32_eth_netdev_setup ( netdev_t * netdev)

Bind the given netdev to the EFM32 ethernet driver.

Does not touch hardware. The netdev init callback performs the actual peripheral initialization.

Parameters
[in,out]netdevnetdev to bind

◆ efm32_eth_recv()

int efm32_eth_recv ( void * buf,
size_t max_len )

Receive a frame from the RX ring.

Behaviour mirrors the netdev recv() contract:

  • buf == NULL && max_len == 0: return the length of the frame at head.
  • buf == NULL && max_len > 0: drop the head frame, return its length.
  • buf != NULL: copy min(len, max_len) bytes into buf, advance the ring, return the number of bytes copied.
Parameters
[out]bufDestination buffer (may be NULL)
[in]max_lenCapacity of buf
Return values
>0number of bytes successfully received
-ENODATAif the ring is empty

◆ efm32_eth_rx_pending()

bool efm32_eth_rx_pending ( void )

Return true if the RX ring contains at least one unconsumed frame.

Return values
trueif at least one frame is pending in the RX ring
falseif the RX ring is empty

◆ efm32_eth_send()

int efm32_eth_send ( const iolist_t * iolist)

Submit a frame for transmission.

The frame data is gathered from the iolist into the next available TX buffer.

Parameters
[in]iolistIO vector list to send
Return values
>0number of bytes queued for transmission on success
-EBUSYon TX descriptor timeout
-EOVERFLOWif the gathered frame exceeds the MTU

◆ efm32_eth_set_link_speed()

void efm32_eth_set_link_speed ( uint16_t speed)

Configure the MAC for a given link speed and duplex.

Programs the ETH->NETWORKCFG SPEED and FULLDUPLEX bits to match the requested speed and duplex. Used both to apply a statically configured link speed and to apply the result of auto-negotiation.

Parameters
[in]speedbitmask of MII BMCR speed/duplex bits (MII_BMCR_SPEED_100, MII_BMCR_FULL_DPLX)

◆ efm32_eth_set_mac()

void efm32_eth_set_mac ( const uint8_t mac[6])

Program a new MAC address.

Parameters
[in]mac6-byte MAC address to program into SPECADDR1{TOP,BOTTOM}

◆ efm32_eth_set_promiscuous()

void efm32_eth_set_promiscuous ( bool enable)

Enable or disable promiscuous mode.

Parameters
[in]enabletrue to enable promiscuous mode, false to disable

◆ efm32_eth_start_auto_negotiation()

int efm32_eth_start_auto_negotiation ( void )

Start PHY auto-negotiation.

Advertises all 10/100 Mbps half- and full-duplex capabilities and restarts auto-negotiation on the PHY. The negotiation runs asynchronously: call efm32_eth_complete_auto_negotiation once the link is up to apply the negotiated parameters to the MAC.

Return values
0on success
-EOPNOTSUPPif the PHY does not support auto-negotiation

◆ efm32_eth_tx_status()

int efm32_eth_tx_status ( void )

Query the completion status of the most recent transmission.

Checks whether the descriptor queued by the most recent efm32_eth_send has been consumed by the EMAC and, if so, inspects its transmit status word.

This method must only be called after a transmission was started by efm32_eth_send. The return value is only valid for the most recent transmission.

Return values
>0number of bytes successfully transmitted
-EAGAINif the frame is still being transmitted
-EBUSYif the frame was aborted due to a collision
-EIOif the frame failed for any other reason