Driver for the EFM32 Ethernet peripheral.
More...
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.
|
| file | efm32_eth_netdev.h |
| | Setup for netdev for the EFM32 ethernet peripheral.
|
| |
| file | eth.h |
| | Low-level Ethernet driver interface for the EFM32.
|
| |
|
|
const netdev_driver_t | efm32_eth_driver |
| | The netdev driver for the EFM32 ethernet peripheral.
|
| |
◆ 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] | out | Destination 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] | mac | 6-byte MAC address to program into SPECADDR1{TOP,BOTTOM} |
- Return values
-
| 0 | on success |
| -ENODEV | if the PHY could not be detected |
| -EIO | if 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
-
| true | if the link is up |
| false | if 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] | netdev | netdev 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] | buf | Destination buffer (may be NULL) |
| [in] | max_len | Capacity of buf |
- Return values
-
| >0 | number of bytes successfully received |
| -ENODATA | if 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
-
| true | if at least one frame is pending in the RX ring |
| false | if 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] | iolist | IO vector list to send |
- Return values
-
| >0 | number of bytes queued for transmission on success |
| -EBUSY | on TX descriptor timeout |
| -EOVERFLOW | if 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
-
◆ efm32_eth_set_mac()
| void efm32_eth_set_mac |
( |
const uint8_t | mac[6] | ) |
|
Program a new MAC address.
- Parameters
-
| [in] | mac | 6-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] | enable | true 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
-
| 0 | on success |
| -EOPNOTSUPP | if 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
-
| >0 | number of bytes successfully transmitted |
| -EAGAIN | if the frame is still being transmitted |
| -EBUSY | if the frame was aborted due to a collision |
| -EIO | if the frame failed for any other reason |