以太网

应用程序示例

以太网示例 ethernet/ethernet.

API 参考手册

PHY 接口

PHY 模块通过配置所给 PHY 的结构体 eth_config_t 进行配置。

头部包含一个默认的配置结构体。这些默认配置中的某些成员在被用于一个特殊的 PHY 硬件配置之前需要被覆盖或重置。查看以太网的示例代码可以了解这是如何完成的。

类型定义

typedef void (*eth_phy_check_init_func)(void)
typedef eth_speed_mode_t (*eth_phy_get_speed_mode_func)(void)
typedef eth_duplex_mode_t (*eth_phy_get_duplex_mode_func)(void)
typedef void (*eth_phy_func)(void)
typedef esp_err_t (*eth_tcpip_input_func)(void *buffer, uint16_t len, void *eb)
typedef void (*eth_gpio_config_func)(void)
typedef bool (*eth_phy_get_partner_pause_enable_func)(void)

枚举

enum eth_mode_t

Values:

ETH_MODE_RMII = 0
ETH_MODE_MII
enum eth_speed_mode_t

Values:

ETH_SPEED_MODE_10M = 0
ETH_SPEED_MODE_100M
enum eth_duplex_mode_t

Values:

ETH_MODE_HALFDUPLEX = 0
ETH_MODE_FULLDUPLEX
enum eth_phy_base_t

Values:

PHY0 = 0
PHY1
PHY2
PHY3
PHY4
PHY5
PHY6
PHY7
PHY8
PHY9
PHY10
PHY11
PHY12
PHY13
PHY14
PHY15
PHY16
PHY17
PHY18
PHY19
PHY20
PHY21
PHY22
PHY23
PHY24
PHY25
PHY26
PHY27
PHY28
PHY29
PHY30
PHY31

结构体

struct eth_config_t

ethernet configuration

Public Members

eth_phy_base_t phy_addr

phy base addr (0~31)

eth_mode_t mac_mode

mac mode only support RMII now

eth_tcpip_input_func tcpip_input

tcpip input func

eth_phy_func phy_init

phy init func

eth_phy_check_link_func phy_check_link

phy check link func

eth_phy_check_init_func phy_check_init

phy check init func

eth_phy_get_speed_mode_func phy_get_speed_mode

phy check init func

eth_phy_get_duplex_mode_func phy_get_duplex_mode

phy check init func

eth_gpio_config_func gpio_config

gpio config func

bool flow_ctrl_enable

flag of flow ctrl enable

eth_phy_get_partner_pause_enable_func phy_get_partner_pause_enable

get partner pause enable

eth_phy_power_enable_func phy_power_enable

enable or disable phy power

函数

esp_err_t esp_eth_init(eth_config_t *config)

Init ethernet mac.

Note
config can not be NULL,and phy chip must be suitable to phy init func.
Return
  • ESP_OK
  • ESP_FAIL
Parameters
  • config: mac init data.

esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size)

Send packet from tcp/ip to mac.

Note
buf can not be NULL,size must be less than 1580
Return
  • ESP_OK
  • ESP_FAIL
Parameters
  • buf: start address of packet data.
  • size: size (byte) of packet data.

esp_err_t esp_eth_enable(void)

Enable ethernet interface.

Note
Shout be called after esp_eth_init
Return
  • ESP_OK
  • ESP_FAIL

esp_err_t esp_eth_disable(void)

Disable ethernet interface.

Note
Shout be called after esp_eth_init
Return
  • ESP_OK
  • ESP_FAIL

void esp_eth_get_mac(uint8_t mac[6])

Get mac addr.

Note
mac addr must be a valid unicast address
Parameters
  • mac: start address of mac address.

void esp_eth_smi_write(uint32_t reg_num, uint16_t value)

Read phy reg with smi interface.

Note
phy base addr must be right.
Parameters
  • reg_num: phy reg num.
  • value: value which write to phy reg.

uint16_t esp_eth_smi_read(uint32_t reg_num)

Read phy reg with smi interface.

Note
phy base addr must be right.
Return
value what read from phy reg
Parameters
  • reg_num: phy reg num.

esp_err_t esp_eth_smi_wait_value(uint32_t reg_num, uint16_t value, uint16_t value_mask, int timeout_ms)

Continuously read a PHY register over SMI interface, wait until the register has the desired value.

Note
PHY base address must be right.
Return
ESP_OK if desired value matches, ESP_ERR_TIMEOUT if timed out.
Parameters
  • reg_num: PHY register number
  • value: Value to wait for (masked with value_mask)
  • value_mask: Mask of bits to match in the register.
  • timeout_ms: Timeout to wait for this value (milliseconds). 0 means never timeout.

static esp_err_t esp_eth_smi_wait_set(uint32_t reg_num, uint16_t value_mask, int timeout_ms)

Continuously read a PHY register over SMI interface, wait until the register has all bits in a mask set.

Note
PHY base address must be right.
Return
ESP_OK if desired value matches, ESP_ERR_TIMEOUT if timed out.
Parameters
  • reg_num: PHY register number
  • value_mask: Value mask to wait for (all bits in this mask must be set)
  • timeout_ms: Timeout to wait for this value (milliseconds). 0 means never timeout.

void esp_eth_free_rx_buf(void *buf)

Free emac rx buf.

Note
buf can not be null,and it is tcpip input buf.
Parameters
  • buf: start address of recevie packet data.

PHY 配置常量

警告

doxygenvariable: Cannot find variable “phy_tlk110_default_ethernet_config” in doxygen xml output for project “esp32-idf” from directory: xml/

警告

doxygenvariable: Cannot find variable “phy_lan8720_default_ethernet_config” in doxygen xml output for project “esp32-idf” from directory: xml/