Skip to content

Commit

Permalink
fix(eth): Attach ETH events at the correct place (#9658)
Browse files Browse the repository at this point in the history
This is to ensure that stack events are called before ours, because callbacks are called in order of attaching
  • Loading branch information
me-no-dev authored May 21, 2024
1 parent 82c36a2 commit f2e064d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions libraries/Ethernet/src/ETH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i

Network.begin();
_ethernets[_eth_index] = this;
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
log_e("event_handler_instance_register for ETH_EVENT Failed!");
return false;
}

eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
Expand Down Expand Up @@ -286,6 +282,11 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
return false;
}

if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
log_e("event_handler_instance_register for ETH_EVENT Failed!");
return false;
}

/* attach to receive events */
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));

Expand Down Expand Up @@ -550,10 +551,6 @@ bool ETHClass::beginSPI(

Network.begin();
_ethernets[_eth_index] = this;
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
log_e("event_handler_instance_register for ETH_EVENT Failed!");
return false;
}

// Install GPIO ISR handler to be able to service SPI Eth modules interrupts
ret = gpio_install_isr_service(0);
Expand Down Expand Up @@ -717,6 +714,11 @@ bool ETHClass::beginSPI(
return false;
}

if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
log_e("event_handler_instance_register for ETH_EVENT Failed!");
return false;
}

/* attach to receive events */
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));

Expand Down

0 comments on commit f2e064d

Please sign in to comment.