From cf6ed1cc538d5b20faa0bfe900fda7ff8046892f Mon Sep 17 00:00:00 2001 From: Ondrej Kosta Date: Tue, 3 Aug 2021 13:34:52 +0200 Subject: [PATCH] esp_eth: add support for multiple Ethernets modules at a time Ethernet driver events properly bounded with ESP NETIF actions to support multiple Ethernet modules used at a time. Components using Ethernet updated to conform with new API. Closes https://github.com/espressif/esp-idf/issues/7318 * Original commit: espressif/esp-idf@ef3038490275d02dee46319f9c596d807163213f --- .../protocol_examples_common/connect.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index 3bf58549a..0f2dc3f9c 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -343,7 +343,7 @@ static void on_eth_event(void *esp_netif, esp_event_base_t event_base, switch (event_id) { case ETHERNET_EVENT_CONNECTED: ESP_LOGI(TAG, "Ethernet Link Up"); - esp_netif_create_ip6_linklocal(esp_netif); + ESP_ERROR_CHECK(esp_netif_create_ip6_linklocal(esp_netif)); break; default: break; @@ -355,7 +355,7 @@ static void on_eth_event(void *esp_netif, esp_event_base_t event_base, static esp_eth_handle_t s_eth_handle = NULL; static esp_eth_mac_t *s_mac = NULL; static esp_eth_phy_t *s_phy = NULL; -static void *s_eth_glue = NULL; +static esp_eth_netif_glue_handle_t s_eth_glue = NULL; static esp_netif_t *eth_start(void) { @@ -373,14 +373,7 @@ static esp_netif_t *eth_start(void) esp_netif_t *netif = esp_netif_new(&netif_config); assert(netif); free(desc); - // Set default handlers to process TCP/IP stuffs - ESP_ERROR_CHECK(esp_eth_set_default_handlers(netif)); - // Register user defined event handers - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &on_got_ip, NULL)); -#ifdef CONFIG_EXAMPLE_CONNECT_IPV6 - ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_CONNECTED, &on_eth_event, netif)); - ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &on_got_ipv6, NULL)); -#endif + eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; @@ -460,6 +453,14 @@ static esp_netif_t *eth_start(void) // combine driver with netif s_eth_glue = esp_eth_new_netif_glue(s_eth_handle); esp_netif_attach(netif, s_eth_glue); + + // Register user defined event handers + ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &on_got_ip, NULL)); +#ifdef CONFIG_EXAMPLE_CONNECT_IPV6 + ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_CONNECTED, &on_eth_event, netif)); + ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_GOT_IP6, &on_got_ipv6, NULL)); +#endif + esp_eth_start(s_eth_handle); return netif; } @@ -474,7 +475,6 @@ static void eth_stop(void) #endif ESP_ERROR_CHECK(esp_eth_stop(s_eth_handle)); ESP_ERROR_CHECK(esp_eth_del_netif_glue(s_eth_glue)); - ESP_ERROR_CHECK(esp_eth_clear_default_handlers(eth_netif)); ESP_ERROR_CHECK(esp_eth_driver_uninstall(s_eth_handle)); ESP_ERROR_CHECK(s_phy->del(s_phy)); ESP_ERROR_CHECK(s_mac->del(s_mac));