Loading...
Searching...
No Matches
eth.h File Reference

Low-level Ethernet driver interface for the LPC1768 EMAC. More...

Detailed Description

Low-level Ethernet driver interface for the LPC1768 EMAC.

Author
Bas Stottelaar basst.nosp@m.otte.nosp@m.laar@.nosp@m.gmai.nosp@m.l.com

Definition in file eth.h.

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "iolist.h"
+ Include dependency graph for eth.h:

Go to the source code of this file.

int lpc1768_eth_init (const uint8_t *mac)
 Initialize the EMAC peripheral and PHY.
 
int lpc1768_eth_send (const iolist_t *iolist)
 Submit a frame for transmission.
 
int lpc1768_eth_recv (void *buf, size_t max_len)
 Receive a frame from the RX ring.
 
void lpc1768_eth_get_mac (uint8_t out[6])
 Read the currently programmed MAC address.
 
void lpc1768_eth_set_mac (const uint8_t mac[6])
 Program a new MAC address.
 
bool lpc1768_eth_link_up (void)
 Read the PHY link status (BMSR.LINK)
 
bool lpc1768_eth_rx_pending (void)
 Return true if the RX ring contains at least one unconsumed frame.
 
int lpc1768_eth_tx_status (void)
 Query the completion status of the most recent transmission.
 
void lpc1768_eth_set_promiscuous (bool enable)
 Enable or disable promiscuous mode.
 
bool lpc1768_eth_get_promiscuous (void)
 Return the current promiscuous mode setting.
 
void lpc1768_eth_set_link_speed (uint16_t speed)
 Configure the MAC for a given link speed and duplex.
 
int lpc1768_eth_start_auto_negotiation (void)
 Start PHY auto-negotiation.
 
void lpc1768_eth_complete_auto_negotiation (void)
 Complete auto-negotiation and apply speed/duplex to the MAC.
 

Function Documentation

◆ 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]outDestination buffer of at least 6 bytes

◆ lpc1768_eth_get_promiscuous()

bool lpc1768_eth_get_promiscuous ( void )

Return the current promiscuous mode setting.

Return values
trueif promiscuous mode is enabled
falseif promiscuous mode is disabled

◆ lpc1768_eth_init()

int lpc1768_eth_init ( const uint8_t * mac)

Initialize the EMAC peripheral and PHY.

Parameters
[in]mac6-byte MAC address to program into SA0/SA1/SA2
Return values
0on success
-ENODEVif the PHY could not be detected
-EIOif 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
trueif the link is up
falseif the link is down

◆ 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]bufDestination buffer (may be NULL)
[in]max_lenCapacity of buf
Return values
>0number of bytes successfully received
-ENODATAif 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
trueif at least one frame is pending in the RX ring
falseif 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]iolistIO vector list to send
Return values
>0number of bytes queued for transmission
-EBUSYon TX descriptor timeout
-EOVERFLOWif 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
[in]speedbitmask of MII BMCR speed/duplex bits (MII_BMCR_SPEED_100, MII_BMCR_FULL_DPLX)

◆ lpc1768_eth_set_mac()

void lpc1768_eth_set_mac ( const uint8_t mac[6])

Program a new MAC address.

Parameters
[in]mac6-byte MAC address to set

◆ lpc1768_eth_set_promiscuous()

void lpc1768_eth_set_promiscuous ( bool enable)

Enable or disable promiscuous mode.

Parameters
[in]enabletrue 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
0on success
-EOPNOTSUPPif 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
>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