From d0afdaaf24d4af694ce3735f3dc0e95d68965459 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 30 Oct 2019 20:21:27 +0100 Subject: [PATCH] esp_eth: moved starting link timer to eth driver start --- components/esp_eth/src/esp_eth.c | 6 +++--- components/esp_eth/test/test_emac.c | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/esp_eth/src/esp_eth.c b/components/esp_eth/src/esp_eth.c index 03f7362cee..643a303c03 100644 --- a/components/esp_eth/src/esp_eth.c +++ b/components/esp_eth/src/esp_eth.c @@ -182,10 +182,13 @@ esp_err_t esp_eth_driver_start(esp_eth_handle_t eth_handle) { esp_err_t ret = ESP_OK; esp_eth_driver_t *eth_driver = eth_handle; + ETH_CHECK(xTimerStart(eth_driver->check_link_timer, 0) == pdPASS, "start eth_link_timer failed", err_start_timer, ESP_FAIL); ETH_CHECK(esp_event_post(ETH_EVENT, ETHERNET_EVENT_START, ð_driver, sizeof(eth_driver), 0) == ESP_OK, "send ETHERNET_EVENT_START event failed", err_event, ESP_FAIL); return ret; +err_start_timer: + xTimerDelete(eth_driver->check_link_timer, 0); err_event: esp_eth_driver_uninstall(eth_driver); return ret; @@ -220,13 +223,10 @@ esp_err_t esp_eth_driver_install(const esp_eth_config_t *config, esp_eth_handle_ eth_driver->check_link_timer = xTimerCreate("eth_link_timer", pdMS_TO_TICKS(config->check_link_period_ms), pdTRUE, eth_driver, eth_check_link_timer_cb); ETH_CHECK(eth_driver->check_link_timer, "create eth_link_timer failed", err_create_timer, ESP_FAIL); - ETH_CHECK(xTimerStart(eth_driver->check_link_timer, 0) == pdPASS, "start eth_link_timer failed", err_start_timer, ESP_FAIL); eth_driver->base.post_attach = esp_eth_post_attach_driver_start; *out_hdl = (esp_eth_handle_t)eth_driver; tcpip_adapter_compat_start_eth(eth_driver); return ESP_OK; -err_start_timer: - xTimerDelete(eth_driver->check_link_timer, 0); err_create_timer: phy->deinit(phy); err_init_phy: diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index 3bb6e555d6..96e10c50db 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -228,7 +228,10 @@ TEST_CASE("esp32 ethernet icmp test", "[ethernet][test_env=UT_T2_Ethernet]") TEST_ASSERT(eth_event_group != NULL); test_case_uses_tcpip(); TEST_ESP_OK(esp_event_loop_create_default()); - TEST_ESP_OK(tcpip_adapter_set_default_eth_handlers()); + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); + esp_netif_t* eth_netif = esp_netif_new(&cfg); + TEST_ESP_OK(esp_eth_set_default_handlers(eth_netif)); + TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group)); TEST_ESP_OK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, eth_event_group)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); @@ -238,6 +241,7 @@ TEST_CASE("esp32 ethernet icmp test", "[ethernet][test_env=UT_T2_Ethernet]") esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(mac, phy); esp_eth_handle_t eth_handle = NULL; TEST_ESP_OK(esp_eth_driver_install(ð_config, ð_handle)); + TEST_ESP_OK(esp_netif_attach(eth_netif, eth_handle)); /* wait for IP lease */ bits = xEventGroupWaitBits(eth_event_group, ETH_GOT_IP_BIT, true, true, pdMS_TO_TICKS(ETH_GET_IP_TIMEOUT_MS)); TEST_ASSERT((bits & ETH_GOT_IP_BIT) == ETH_GOT_IP_BIT); @@ -293,9 +297,10 @@ TEST_CASE("esp32 ethernet icmp test", "[ethernet][test_env=UT_T2_Ethernet]") TEST_ESP_OK(phy->del(phy)); TEST_ESP_OK(mac->del(mac)); TEST_ESP_OK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_ETH_GOT_IP, got_ip_event_handler)); - TEST_ESP_OK(tcpip_adapter_clear_default_eth_handlers()); + TEST_ESP_OK(esp_eth_clear_default_handlers(eth_netif)); TEST_ESP_OK(esp_event_loop_delete_default()); vEventGroupDelete(eth_event_group); + esp_netif_destroy(eth_netif); } #if CONFIG_ETH_USE_SPI_ETHERNET