Skip to content

Commit 01ad516

Browse files
Jason2866me-no-dev
andauthored
fix(eth): Attach ETH events at the correct place (#408)
This is to ensure that stack events are called before ours, because callbacks are called in order of attaching Co-authored-by: me-no-dev <[email protected]>
1 parent fcb8837 commit 01ad516

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Diff for: libraries/Ethernet/src/ETH.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
163163

164164
Network.begin();
165165
_ethernets[_eth_index] = this;
166-
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
167-
log_e("event_handler_instance_register for ETH_EVENT Failed!");
168-
return false;
169-
}
170166

171167
eth_esp32_emac_config_t mac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG();
172168
mac_config.clock_config.rmii.clock_mode = (clock_mode) ? EMAC_CLK_OUT : EMAC_CLK_EXT_IN;
@@ -297,6 +293,11 @@ bool ETHClass::begin(eth_phy_type_t type, int32_t phy_addr, int mdc, int mdio, i
297293
return false;
298294
}
299295

296+
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
297+
log_e("event_handler_instance_register for ETH_EVENT Failed!");
298+
return false;
299+
}
300+
300301
/* attach to receive events */
301302
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));
302303

@@ -561,10 +562,6 @@ bool ETHClass::beginSPI(
561562

562563
Network.begin();
563564
_ethernets[_eth_index] = this;
564-
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
565-
log_e("event_handler_instance_register for ETH_EVENT Failed!");
566-
return false;
567-
}
568565

569566
// Install GPIO ISR handler to be able to service SPI Eth modules interrupts
570567
ret = gpio_install_isr_service(0);
@@ -728,6 +725,11 @@ bool ETHClass::beginSPI(
728725
return false;
729726
}
730727

728+
if (_eth_ev_instance == NULL && esp_event_handler_instance_register(ETH_EVENT, ESP_EVENT_ANY_ID, &_eth_event_cb, NULL, &_eth_ev_instance)) {
729+
log_e("event_handler_instance_register for ETH_EVENT Failed!");
730+
return false;
731+
}
732+
731733
/* attach to receive events */
732734
initNetif((Network_Interface_ID)(ESP_NETIF_ID_ETH + _eth_index));
733735

0 commit comments

Comments
 (0)