diff --git a/components/esp_eth/include/esp_eth.h b/components/esp_eth/include/esp_eth.h index 5d7d6d66dd..48f364f8b4 100644 --- a/components/esp_eth/include/esp_eth.h +++ b/components/esp_eth/include/esp_eth.h @@ -116,6 +116,21 @@ typedef struct { */ esp_err_t esp_eth_driver_install(const esp_eth_config_t *config, esp_eth_handle_t *out_hdl); +/** +* @brief Start ethernet driver **ONLY** in standalone mode, i.e. without TCP/IP stack +* +* Note that ethernet driver is typically started as soon as it is attached to esp-netif. +* This API should only be called if ethernet is used separately without esp-netif, for example +* when esp_eth_config_t.stack_input is not NULL. +* +* @param[in] eth_handle handle of Ethernet driver +* +* @return +* - ESP_OK: starts ethernet driver +* - ESP_ERR_INVALID_STATE: if event loop hasn't been initialized +*/ +esp_err_t esp_eth_driver_start(esp_eth_handle_t eth_handle); + /** * @brief Uninstall Ethernet driver * diff --git a/components/esp_eth/src/esp_eth.c b/components/esp_eth/src/esp_eth.c index 475becb45f..dd4f369a25 100644 --- a/components/esp_eth/src/esp_eth.c +++ b/components/esp_eth/src/esp_eth.c @@ -151,16 +151,9 @@ static void eth_check_link_timer_cb(TimerHandle_t xTimer) phy->get_link(phy); } -////////////////////////////////User face APIs//////////////////////////////////////////////// -// User has to pass the handle of Ethernet driver to each API. -// Different Ethernet driver instance is identified with a unique handle. -// It's helpful for us to support multiple Ethernet port on ESP32. -////////////////////////////////////////////////////////////////////////////////////////////// - -static esp_err_t esp_eth_driver_start(esp_netif_t * esp_netif, void * args) +static esp_err_t esp_eth_post_attach_driver_start(esp_netif_t * esp_netif, void * args) { uint8_t eth_mac[6]; - esp_err_t ret = ESP_OK; esp_eth_driver_t *eth_driver = args; eth_driver->base.netif = esp_netif; @@ -177,6 +170,18 @@ static esp_err_t esp_eth_driver_start(esp_netif_t * esp_netif, void * args) esp_netif_set_mac(esp_netif, eth_mac); ESP_LOGI(TAG, "ETH netif started"); + return esp_eth_driver_start(eth_driver); +} + +////////////////////////////////User face APIs//////////////////////////////////////////////// +// User has to pass the handle of Ethernet driver to each API. +// Different Ethernet driver instance is identified with a unique handle. +// It's helpful for us to support multiple Ethernet port on ESP32. +////////////////////////////////////////////////////////////////////////////////////////////// +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(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); @@ -216,7 +221,7 @@ esp_err_t esp_eth_driver_install(const esp_eth_config_t *config, esp_eth_handle_ 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_driver_start; + eth_driver->base.post_attach = esp_eth_post_attach_driver_start; *out_hdl = (esp_eth_handle_t)eth_driver; tcpip_adapter_start_eth(eth_driver); return ESP_OK; diff --git a/examples/ethernet/eth2ap/main/ethernet_example_main.c b/examples/ethernet/eth2ap/main/ethernet_example_main.c index 7d65a5bff2..78c04b1e8b 100644 --- a/examples/ethernet/eth2ap/main/ethernet_example_main.c +++ b/examples/ethernet/eth2ap/main/ethernet_example_main.c @@ -185,6 +185,7 @@ static void initialize_ethernet(void) config.stack_input = pkt_eth2wifi; ESP_ERROR_CHECK(esp_eth_driver_install(&config, &s_eth_handle)); esp_eth_ioctl(s_eth_handle, ETH_CMD_S_PROMISCUOUS, (void *)true); + esp_eth_driver_start(s_eth_handle); } static void initialize_wifi(void)