Driver for the LPC1768 Ethernet peripheral.
More...
Driver for the LPC1768 Ethernet peripheral.
Link State Events
To enable Link Events, use the (pseudo) module lpc1768_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 lpc1768_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 | lpc1768_eth_netdev.h |
| | Setup for netdev for the LPC1768 ethernet peripheral.
|
| |
| file | eth.h |
| | Low-level Ethernet driver interface for the LPC1768 EMAC.
|
| |
|
|
const netdev_driver_t | lpc1768_eth_driver |
| | The netdev driver for the LPC1768 EMAC.
|
| |
◆ lpc1768_eth_complete_auto_negotiation()
| void lpc1768_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 SUPP, MAC2, Command and IPGT accordingly.
◆ lpc1768_eth_get_mac()
| void lpc1768_eth_get_mac |
( |
uint8_t | out[6] | ) |
|
Read the currently programmed MAC address.
- Parameters
-
| [out] | out | Destination buffer of at least 6 bytes |
◆ lpc1768_eth_get_promiscuous()
| bool lpc1768_eth_get_promiscuous |
( |
void | | ) |
|
Return the current promiscuous mode setting.
- Return values
-
| true | if promiscuous mode is enabled |
| false | if promiscuous mode is disabled |
◆ lpc1768_eth_init()
| int lpc1768_eth_init |
( |
const uint8_t * | mac | ) |
|
Initialize the EMAC peripheral and PHY.
- Parameters
-
| [in] | mac | 6-byte MAC address to program into SA0/SA1/SA2 |
- Return values
-
| 0 | on success |
| -ENODEV | if the PHY could not be detected |
| -EIO | if the PHY could not be initialized |
◆ lpc1768_eth_link_up()
| bool lpc1768_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 |
◆ lpc1768_eth_netdev_setup()
| void lpc1768_eth_netdev_setup |
( |
netdev_t * | netdev | ) |
|
Bind the given netdev to the LPC1768 EMAC driver.
Does not touch hardware. The netdev init callback performs the actual peripheral initialization.
- Parameters
-
| [in,out] | netdev | netdev to bind |
◆ lpc1768_eth_recv()
| int lpc1768_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 |
◆ lpc1768_eth_rx_pending()
| bool lpc1768_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 |
◆ lpc1768_eth_send()
| int lpc1768_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 in AHB SRAM.
- Parameters
-
| [in] | iolist | IO vector list to send |
- Return values
-
| >0 | number of bytes queued for transmission |
| -EBUSY | on TX descriptor timeout |
| -EOVERFLOW | if the gathered frame exceeds the MTU |
◆ lpc1768_eth_set_link_speed()
| void lpc1768_eth_set_link_speed |
( |
uint16_t | speed | ) |
|
Configure the MAC for a given link speed and duplex.
Programs the SUPP, MAC2, Command and IPGT registers 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
-
◆ lpc1768_eth_set_mac()
| void lpc1768_eth_set_mac |
( |
const uint8_t | mac[6] | ) |
|
Program a new MAC address.
- Parameters
-
| [in] | mac | 6-byte MAC address to set |
◆ lpc1768_eth_set_promiscuous()
| void lpc1768_eth_set_promiscuous |
( |
bool | enable | ) |
|
Enable or disable promiscuous mode.
- Parameters
-
| [in] | enable | true to enable promiscuous mode, false to disable |
◆ lpc1768_eth_start_auto_negotiation()
| int lpc1768_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 lpc1768_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 |
◆ lpc1768_eth_tx_status()
| int lpc1768_eth_tx_status |
( |
void | | ) |
|
Query the completion status of the most recent transmission.
Checks whether the descriptor queued by the most recent lpc1768_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 lpc1768_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 |