Go to the documentation of this file.
32 #define TRACE_LEVEL NIC_TRACE_LEVEL
35 #include "esp_intr_alloc.h"
36 #include "soc/dport_reg.h"
37 #include "soc/dport_access.h"
38 #include "soc/io_mux_reg.h"
39 #include "soc/gpio_sig_map.h"
40 #include "driver/gpio.h"
42 #include "esp_private/periph_ctrl.h"
102 TRACE_INFO(
"Initializing ESP32 Ethernet MAC...\r\n");
105 periph_module_enable(PERIPH_EMAC_MODULE);
108 DPORT_SET_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG, DPORT_WIFI_CLK_EMAC_EN);
124 if(interface->phyDriver != NULL)
127 error = interface->phyDriver->init(interface);
129 else if(interface->switchDriver != NULL)
132 error = interface->switchDriver->init(interface);
211 #if defined(ESP32_ETHERNET_KIT)
221 gpio_set_direction(0, GPIO_MODE_INPUT);
224 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
226 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
228 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
231 gpio_set_direction(25, GPIO_MODE_INPUT);
233 gpio_set_direction(26, GPIO_MODE_INPUT);
235 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV);
238 gpio_matrix_out(23, EMAC_MDC_O_IDX, 0, 0);
241 gpio_matrix_out(18, EMAC_MDO_O_IDX, 0, 0);
242 gpio_matrix_in(18, EMAC_MDI_I_IDX, 0);
245 gpio_pad_select_gpio(5);
246 gpio_set_direction(5, GPIO_MODE_OUTPUT);
249 gpio_set_level(5, 0);
251 gpio_set_level(5, 1);
255 #elif defined(EVK_NINA_W10)
265 gpio_set_direction(0, GPIO_MODE_INPUT);
268 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
270 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
272 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
275 gpio_set_direction(25, GPIO_MODE_INPUT);
277 gpio_set_direction(26, GPIO_MODE_INPUT);
279 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV);
282 gpio_matrix_out(2, EMAC_MDC_O_IDX, 0, 0);
285 gpio_matrix_out(4, EMAC_MDO_O_IDX, 0, 0);
286 gpio_matrix_in(4, EMAC_MDI_I_IDX, 0);
289 #elif defined(ESP32_EVB) || defined(ESP32_GATEWAY)
299 gpio_set_direction(0, GPIO_MODE_INPUT);
302 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO19_U, FUNC_GPIO19_EMAC_TXD0);
304 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO21_U, FUNC_GPIO21_EMAC_TX_EN);
306 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO22_U, FUNC_GPIO22_EMAC_TXD1);
309 gpio_set_direction(25, GPIO_MODE_INPUT);
311 gpio_set_direction(26, GPIO_MODE_INPUT);
313 PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO27_U, FUNC_GPIO27_EMAC_RX_DV);
316 gpio_matrix_out(23, EMAC_MDC_O_IDX, 0, 0);
319 gpio_matrix_out(18, EMAC_MDO_O_IDX, 0, 0);
320 gpio_matrix_in(18, EMAC_MDI_I_IDX, 0);
402 if(interface->phyDriver != NULL)
405 interface->phyDriver->tick(interface);
407 else if(interface->switchDriver != NULL)
410 interface->switchDriver->tick(interface);
427 esp_intr_enable_source(ETS_ETH_MAC_INTR_SOURCE);
430 if(interface->phyDriver != NULL)
433 interface->phyDriver->enableIrq(interface);
435 else if(interface->switchDriver != NULL)
438 interface->switchDriver->enableIrq(interface);
455 esp_intr_disable_source(ETS_ETH_MAC_INTR_SOURCE);
458 if(interface->phyDriver != NULL)
461 interface->phyDriver->disableIrq(interface);
463 else if(interface->switchDriver != NULL)
466 interface->switchDriver->disableIrq(interface);
519 interface->nicEvent =
TRUE;
712 acceptMulticast =
FALSE;
719 entry = &interface->macAddrFilter[i];
728 acceptMulticast =
TRUE;
736 unicastMacAddr[j++] = entry->
addr;
bool_t osSetEventFromIsr(OsEvent *event)
Set an event object to the signaled state from an interrupt service routine.
void esp32EthInitDmaDesc(NetInterface *interface)
Initialize DMA descriptor lists.
#define EMAC_ADDR0LOW_REG
#define EMAC_CONFIG_EMACMII
#define EMAC_ADDR2HIGH_ADDRESS_ENABLE2
#define EMAC_ADDR0HIGH_REG
Enhanced RX DMA descriptor.
#define EMAC_DMASTATUS_RECV_INT
#define EMAC_DMAOPERATION_MODE_START_STOP_TX
size_t netBufferRead(void *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Read data from a multi-part buffer.
#define EMAC_ADDR1LOW_REG
#define EMAC_DMABUSMODE_SW_RST
Structure describing a buffer that spans multiple chunks.
#define MAC_ADDR_FILTER_SIZE
error_t esp32EthUpdateMacAddrFilter(NetInterface *interface)
Configure MAC address filtering.
uint_t refCount
Reference count for the current entry.
#define ESP32_ETH_RX_BUFFER_COUNT
#define EMAC_DMASTATUS_NORM_INT_SUMM
#define EMAC_MIIADDR_MIICSRCLK
#define EMAC_DMAOPERATION_MODE_TX_STORE_FORWARD
ESP32 Ethernet MAC driver.
void esp32EthEventHandler(NetInterface *interface)
ESP32 Ethernet MAC event handler.
#define EMAC_MIIADDR_MIIWRITE
void nicProcessPacket(NetInterface *interface, uint8_t *packet, size_t length, NetRxAncillary *ancillary)
Handle a packet received by the network controller.
#define macIsMulticastAddr(macAddr)
#define EMAC_INTMASK_PMTINTMASK
#define EMAC_MIIDATA_MII_DATA
#define EMAC_EX_PHYINF_CONF_REG
error_t esp32EthUpdateMacConfig(NetInterface *interface)
Adjust MAC configuration parameters for proper operation.
#define EMAC_EX_OSCCLK_CONF_EMAC_OSC_CLK_SEL
#define EMAC_EX_PHYINF_CONF_EMAC_PHY_INTF_SEL_RMII
#define EMAC_ADDR3LOW_REG
const NetRxAncillary NET_DEFAULT_RX_ANCILLARY
@ ERROR_FAILURE
Generic error code.
__weak_func void esp32EthInitGpio(NetInterface *interface)
GPIO configuration.
error_t esp32EthReceivePacket(NetInterface *interface)
Receive a packet.
error_t esp32EthSendPacket(NetInterface *interface, const NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a packet.
#define EMAC_ADDR1HIGH_REG
uint16_t esp32EthReadPhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr)
Read PHY register.
#define EMAC_DMAIN_EN_DMAIN_RIE
#define ESP32_ETH_TX_BUFFER_COUNT
#define EMAC_ADDR2LOW_REG
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
#define EMAC_EX_CLK_CTRL_REG
void esp32EthTick(NetInterface *interface)
ESP32 Ethernet MAC timer handler.
#define EMAC_MIIADDR_MIIBUSY
#define EMAC_EX_OSCCLK_CONF_REG
#define EMAC_DMAOPERATION_MODE_REG
#define EMAC_DMATXPOLLDEMAND_REG
#define EMAC_CONFIG_EMACRXOWN
#define ESP32_ETH_IRQ_FLAGS
#define EMAC_DMASTATUS_TRANS_INT
#define EMAC_MIIADDR_MIIREG
#define EMAC_DMAIN_EN_DMAIN_TIE
void IRAM_ATTR esp32EthIrqHandler(void *arg)
ESP32 Ethernet MAC interrupt service routine.
#define EMAC_DMAIN_EN_REG
#define EMAC_DMAOPERATION_MODE_RX_STORE_FORWARD
#define ESP32_ETH_RX_BUFFER_SIZE
#define EMAC_DMABUSMODE_REG
void esp32EthWritePhyReg(uint8_t opcode, uint8_t phyAddr, uint8_t regAddr, uint16_t data)
Write PHY register.
#define EMAC_MIIADDR_MIICSRCLK_DIV_62
void esp32EthDisableIrq(NetInterface *interface)
Disable interrupts.
#define EMAC_ADDR3HIGH_ADDRESS_ENABLE3
#define EMAC_DMASTATUS_REG
#define EMAC_DMABUSMODE_PROG_BURST_LEN_32
#define EMAC_ADDR2HIGH_REG
#define EMAC_DMARXPOLLDEMAND_REG
#define EMAC_ADDR1HIGH_ADDRESS_ENABLE1
#define EMAC_DMATXBASEADDR_REG
#define EMAC_DMAIN_EN_DMAIN_NISE
#define EMAC_DMARXBASEADDR_REG
#define EMAC_DMASTATUS_TRANS_BUF_UNAVAIL
#define EMAC_CONFIG_EMACRX
#define EMAC_DMABUSMODE_RX_DMA_PBL_32
void osSetEvent(OsEvent *event)
Set the specified event object to the signaled state.
#define EMAC_DMAOPERATION_MODE_START_STOP_RX
error_t esp32EthInit(NetInterface *interface)
ESP32 Ethernet MAC initialization.
#define EMAC_DMABUSMODE_ALT_DESC_SIZE
#define ESP32_ETH_TX_BUFFER_SIZE
const NicDriver esp32EthDriver
ESP32 Ethernet MAC driver.
Enhanced TX DMA descriptor.
#define EMAC_CONFIG_EMACFESPEED
#define EMAC_CONFIG_EMACTX
#define EMAC_CONFIG_EMACDUPLEX
const MacAddr MAC_UNSPECIFIED_ADDR
#define EMAC_DMASTATUS_RECV_BUF_UNAVAIL
__attribute__((naked))
AVR32 Ethernet MAC interrupt wrapper.
#define EMAC_INTMASK_LPIINTMASK
#define EMAC_MIIADDR_MIIDEV
#define EMAC_ADDR3HIGH_REG
#define EMAC_EX_CLK_CTRL_EMAC_EXT_OSC_EN
@ NIC_TYPE_ETHERNET
Ethernet interface.
void esp32EthEnableIrq(NetInterface *interface)
Enable interrupts.