mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ethernet_examples: use esp_netif instead of tcpip-adapter
This commit is contained in:
parent
19e24fe61e
commit
7f4c8a0b4f
@ -10,7 +10,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "tcpip_adapter.h"
|
#include "esp_netif.h"
|
||||||
#include "esp_eth.h"
|
#include "esp_eth.h"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
@ -52,7 +52,7 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
|||||||
int32_t event_id, void *event_data)
|
int32_t event_id, void *event_data)
|
||||||
{
|
{
|
||||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
|
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
|
||||||
const tcpip_adapter_ip_info_t *ip_info = &event->ip_info;
|
const esp_netif_ip_info_t *ip_info = &event->ip_info;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Ethernet Got IP Address");
|
ESP_LOGI(TAG, "Ethernet Got IP Address");
|
||||||
ESP_LOGI(TAG, "~~~~~~~~~~~");
|
ESP_LOGI(TAG, "~~~~~~~~~~~");
|
||||||
@ -64,10 +64,12 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base,
|
|||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
tcpip_adapter_init();
|
esp_netif_init();
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
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();
|
||||||
|
esp_netif_t* 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(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));
|
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL));
|
||||||
|
|
||||||
@ -112,4 +114,5 @@ void app_main(void)
|
|||||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||||
esp_eth_handle_t eth_handle = NULL;
|
esp_eth_handle_t eth_handle = NULL;
|
||||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
||||||
|
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, eth_handle));
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,6 @@ static void initialize_wifi(void)
|
|||||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL));
|
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, wifi_event_handler, NULL));
|
||||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
ESP_ERROR_CHECK(tcpip_adapter_clear_default_wifi_handlers());
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||||
wifi_config_t wifi_config = {
|
wifi_config_t wifi_config = {
|
||||||
.ap = {
|
.ap = {
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/event_groups.h"
|
#include "freertos/event_groups.h"
|
||||||
#include "tcpip_adapter.h"
|
#include "esp_netif.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_console.h"
|
#include "esp_console.h"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
@ -19,11 +19,12 @@
|
|||||||
#include "iperf.h"
|
#include "iperf.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
static tcpip_adapter_ip_info_t ip;
|
static esp_netif_ip_info_t ip;
|
||||||
static bool started = false;
|
static bool started = false;
|
||||||
static EventGroupHandle_t eth_event_group;
|
static EventGroupHandle_t eth_event_group;
|
||||||
static const int GOTIP_BIT = BIT0;
|
static const int GOTIP_BIT = BIT0;
|
||||||
static esp_eth_handle_t eth_handle = NULL;
|
static esp_eth_handle_t eth_handle = NULL;
|
||||||
|
static esp_netif_t* eth_netif = NULL;
|
||||||
|
|
||||||
/* "ethernet" command */
|
/* "ethernet" command */
|
||||||
static struct {
|
static struct {
|
||||||
@ -43,7 +44,7 @@ static int eth_cmd_control(int argc, char **argv)
|
|||||||
uint8_t mac_addr[6];
|
uint8_t mac_addr[6];
|
||||||
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
|
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr);
|
||||||
printf("HW ADDR: " MACSTR "\r\n", MAC2STR(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("ETHIP: " IPSTR "\r\n", IP2STR(&ip.ip));
|
||||||
printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask));
|
printf("ETHMASK: " IPSTR "\r\n", IP2STR(&ip.netmask));
|
||||||
printf("ETHGW: " IPSTR "\r\n", IP2STR(&ip.gw));
|
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)
|
void register_ethernet(void)
|
||||||
{
|
{
|
||||||
eth_event_group = xEventGroupCreate();
|
eth_event_group = xEventGroupCreate();
|
||||||
tcpip_adapter_init();
|
esp_netif_init();
|
||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
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(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));
|
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
|
#endif
|
||||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
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.control = arg_str1(NULL, NULL, "<info>", "Get info of Ethernet");
|
||||||
eth_control_args.end = arg_end(1);
|
eth_control_args.end = arg_end(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user