mirror of
https://github.com/espressif/esp-idf.git
synced 2026-08-18 06:35:35 +03:00
ethernet_examples: use esp_netif instead of tcpip-adapter
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <string.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "esp_event.h"
|
||||
@@ -19,11 +19,12 @@
|
||||
#include "iperf.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static tcpip_adapter_ip_info_t ip;
|
||||
static esp_netif_ip_info_t ip;
|
||||
static bool started = false;
|
||||
static EventGroupHandle_t eth_event_group;
|
||||
static const int GOTIP_BIT = BIT0;
|
||||
static esp_eth_handle_t eth_handle = NULL;
|
||||
static esp_netif_t* eth_netif = NULL;
|
||||
|
||||
/* "ethernet" command */
|
||||
static struct {
|
||||
@@ -43,7 +44,7 @@ static int eth_cmd_control(int argc, char **argv)
|
||||
uint8_t mac_addr[6];
|
||||
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
|
||||
printf("HW ADDR: " MACSTR "\r\n", MAC2STR(mac_addr));
|
||||
tcpip_adapter_get_ip_info(ESP_IF_ETH, &ip);
|
||||
esp_netif_get_ip_info(eth_netif, &ip);
|
||||
printf("ETHIP: " IPSTR "\r\n", IP2STR(&ip.ip));
|
||||
printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask));
|
||||
printf("ETHGW: " IPSTR "\r\n", IP2STR(&ip.gw));
|
||||
@@ -176,9 +177,11 @@ static void event_handler(void *arg, esp_event_base_t event_base,
|
||||
void register_ethernet(void)
|
||||
{
|
||||
eth_event_group = xEventGroupCreate();
|
||||
tcpip_adapter_init();
|
||||
esp_netif_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
ESP_ERROR_CHECK(tcpip_adapter_set_default_eth_handlers());
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
eth_netif = esp_netif_new(&cfg);
|
||||
ESP_ERROR_CHECK(esp_eth_set_default_handlers(eth_netif));
|
||||
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, &event_handler, NULL));
|
||||
|
||||
@@ -222,6 +225,7 @@ void register_ethernet(void)
|
||||
#endif
|
||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
||||
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, eth_handle));
|
||||
|
||||
eth_control_args.control = arg_str1(NULL, NULL, "<info>", "Get info of Ethernet");
|
||||
eth_control_args.end = arg_end(1);
|
||||
|
||||
Reference in New Issue
Block a user