0
0
Fork 0

migrate to idfv5.1.2 (netif, wifi_event)

This commit is contained in:
kerms 2023-12-18 16:48:34 +08:00
parent cc8e819009
commit 24b5f60b34
10 changed files with 78 additions and 50 deletions

View File

@ -1,7 +1,9 @@
#ifndef __SWO_H__
#define __SWO_H__
typedef void * EventGroupHandle_t;
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
// event group bits
#define SWO_GOT_DATA 0x00000001

View File

@ -44,9 +44,7 @@
#include "components/DAP/include/swo.h"
#include "esp_err.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
EventGroupHandle_t kSwoThreadEventGroup;

View File

@ -15,7 +15,7 @@ typedef struct
{
uint32_t el_link_identifier;
uint32_t command;
uint32_t el_proxy_version
uint32_t el_proxy_version;
} __attribute__((packed)) el_request_handshake;
@ -23,7 +23,7 @@ typedef struct
{
uint32_t el_link_identifier;
uint32_t command;
uint32_t el_dap_version
uint32_t el_dap_version;
} __attribute__((packed)) el_response_handshake;

17
main/idf_component.yml Normal file
View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
espressif/mdns: "*"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -21,7 +21,7 @@
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_event.h"
#include "esp_log.h"
@ -157,6 +157,7 @@ void kcp_server_task()
case ACCEPTING:
kState = ATTACHING;
__attribute__((fallthrough));
case ATTACHING:
attach((uint8_t *)kcp_buffer, ret);
break;

View File

@ -26,7 +26,7 @@
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"

View File

@ -27,7 +27,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include "freertos/queue.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
@ -177,7 +177,7 @@ void tcp_netconn_task()
{
case ACCEPTING:
kState = ATTACHING;
__attribute__((fallthrough));
case ATTACHING:
attach((uint8_t *)buffer, len_buf);
kState = EMULATING;

View File

@ -22,7 +22,7 @@
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
@ -147,7 +147,7 @@ void tcp_server_task(void *pvParameters)
{
case ACCEPTING:
kState = ATTACHING;
__attribute__((fallthrough));
case ATTACHING:
// elaphureLink handshake
if (el_handshake_process(kSock, tcp_rx_buffer, len) == 0) {

View File

@ -38,7 +38,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
#include "freertos/queue.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "driver/uart.h"

View File

@ -1,8 +1,11 @@
#include "sdkconfig.h"
#include <string.h>
#include <stdint.h>
#include <sys/param.h>
#include <lwip/ip4_addr.h>
#ifdef CONFIG_EXAMPLE_IPV6
#include <lwip/ip6_addr.h>
#endif
#include "main/wifi_configuration.h"
#include "main/uart_bridge.h"
@ -14,7 +17,7 @@
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event_loop.h"
#include "esp_event.h"
#include "esp_log.h"
#ifdef CONFIG_IDF_TARGET_ESP8266
@ -28,6 +31,7 @@
#endif
static EventGroupHandle_t wifi_event_group;
static esp_netif_t *sta_netif;
static int ssid_index = 0;
const int IPV4_GOTIP_BIT = BIT0;
@ -37,30 +41,32 @@ const int IPV6_GOTIP_BIT = BIT1;
static void ssid_change();
static esp_err_t event_handler(void *ctx, system_event_t *event) {
/* For accessing reason codes in case of disconnection */
system_event_info_t *info = &event->event_info;
switch (event->event_id) {
case SYSTEM_EVENT_STA_START:
static void event_handler(void *handler_arg __attribute__((unused)),
esp_event_base_t event_base __attribute__((unused)),
int32_t event_id,
void *event_data)
{
switch (event_id) {
case WIFI_EVENT_STA_START:
esp_wifi_connect();
break;
case SYSTEM_EVENT_STA_CONNECTED:
case WIFI_EVENT_STA_CONNECTED:
#ifdef CONFIG_EXAMPLE_IPV6
/* enable ipv6 */
tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_STA);
esp_netif_create_ip6_linklocal(sta_netif);
#endif
break;
case SYSTEM_EVENT_STA_GOT_IP:
case IP_EVENT_STA_GOT_IP: {
ip_event_got_ip_t *event = event_data;
GPIO_SET_LEVEL_HIGH(PIN_LED_WIFI_STATUS);
xEventGroupSetBits(wifi_event_group, IPV4_GOTIP_BIT);
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa(&event->event_info.got_ip.ip_info.ip));
os_printf("SYSTEM EVENT STA GOT IP : %s\r\n", ip4addr_ntoa((const ip4_addr_t *) &event->ip_info.ip));
break;
case SYSTEM_EVENT_STA_DISCONNECTED:
}
case WIFI_EVENT_STA_DISCONNECTED: {
wifi_event_sta_disconnected_t *event = event_data;
GPIO_SET_LEVEL_LOW(PIN_LED_WIFI_STATUS);
os_printf("Disconnect reason : %d\r\n", (int)info->disconnected.reason);
os_printf("Disconnect reason : %d\r\n", event->reason);
#ifdef CONFIG_IDF_TARGET_ESP8266
if (info->disconnected.reason == WIFI_REASON_BASIC_RATE_NOT_SUPPORT) {
@ -79,18 +85,20 @@ static esp_err_t event_handler(void *ctx, system_event_t *event) {
uart_bridge_close();
#endif
break;
case SYSTEM_EVENT_AP_STA_GOT_IP6:
}
case IP_EVENT_GOT_IP6: {
#ifdef CONFIG_EXAMPLE_IPV6
ip_event_got_ip6_t *event = event_data;
xEventGroupSetBits(wifi_event_group, IPV6_GOTIP_BIT);
os_printf("SYSTEM_EVENT_STA_GOT_IP6\r\n");
char *ip6 = ip6addr_ntoa(&event->event_info.got_ip6.ip6_info.ip);
char *ip6 = ip6addr_ntoa((ip6_addr_t *) &event->ip6_info);
os_printf("IPv6: %s\r\n", ip6);
#endif
}
default:
break;
}
return ESP_OK;
}
static void ssid_change() {
@ -127,29 +135,31 @@ void wifi_init(void) {
GPIO_FUNCTION_SET(PIN_LED_WIFI_STATUS);
GPIO_SET_DIRECTION_NORMAL_OUT(PIN_LED_WIFI_STATUS);
tcpip_adapter_init();
#if (USE_STATIC_IP == 1)
tcpip_adapter_dhcps_stop(TCPIP_ADAPTER_IF_STA);
tcpip_adapter_ip_info_t ip_info;
#define MY_IP4_ADDR(...) IP4_ADDR(__VA_ARGS__)
MY_IP4_ADDR(&ip_info.ip, DAP_IP_ADDRESS);
MY_IP4_ADDR(&ip_info.gw, DAP_IP_GATEWAY);
MY_IP4_ADDR(&ip_info.netmask, DAP_IP_NETMASK);
#undef MY_IP4_ADDR
tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info);
#endif // (USE_STATIC_IP == 1)
esp_netif_init();
wifi_event_group = xEventGroupCreate();
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
ESP_ERROR_CHECK(esp_event_loop_create_default());
sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);
#if (USE_STATIC_IP == 1)
esp_netif_dhcpc_stop(sta_netif);
esp_netif_ip_info_t ip_info;
esp_netif_set_ip4_addr(&ip_info.ip, DAP_IP_ADDRESS);
esp_netif_set_ip4_addr(&ip_info.gw, DAP_IP_GATEWAY);
esp_netif_set_ip4_addr(&ip_info.netmask, DAP_IP_NETMASK);
esp_netif_set_ip_info(sta_netif, &ip_info);
#endif // (USE_STATIC_IP == 1)
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
ESP_ERROR_CHECK(esp_event_handler_instance_register(
WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL));
ESP_ERROR_CHECK(esp_event_handler_instance_register(
IP_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
// os_printf("Setting WiFi configuration SSID %s...\r\n", wifi_config.sta.ssid);
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));