mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
ethernet: move netif glue && add ref counter
1. move netif glue into single file 2. add reference counter for Ethernet driver
This commit is contained in:
@@ -65,12 +65,15 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
// Initialize TCP/IP network interface (should be called only once in application)
|
||||
esp_netif_init();
|
||||
|
||||
// Create default event loop that running in background
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
esp_netif_t* eth_netif = esp_netif_new(&cfg);
|
||||
esp_netif_t *eth_netif = esp_netif_new(&cfg);
|
||||
// Set default handlers to process TCP/IP stuffs
|
||||
ESP_ERROR_CHECK(esp_eth_set_default_handlers(eth_netif));
|
||||
// Register user defined event handers
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));
|
||||
|
||||
@@ -120,5 +123,8 @@ void app_main(void)
|
||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||
esp_eth_handle_t eth_handle = NULL;
|
||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
||||
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, eth_handle));
|
||||
/* attach Ethernet driver to TCP/IP stack */
|
||||
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
||||
/* start Ethernet driver state machine */
|
||||
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
||||
}
|
||||
|
Reference in New Issue
Block a user