mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-05 12:25:03 +02:00
Merge branch 'master' into feature/btdm_controller
* master: (32 commits) components/nghttp: rename Makefile to component.mk components/nghttp: add HTTP2.0 protocol feature compoenents/esp32: don't alias start_cpu1 to start_cpu0_default components/freertos: fix a bug with an uninitialised return value Change application entry point name back to app_main gitlab-ci: build SSC with matching branch name, if available components/spi_flash: remove stray level of indentation components/nvs: fix broken sentences in comment blocks components/esp32: fix renaming of esp_event_set_cb, minor clean up components/esp32: remove "_user" part from entry points, weaken start_cpu0/1 Fix a spelling mistake in panic message, add carriage return to stack canary message components/lwip,esp32: fixes for C++ components/bt: fix compilation, remove ./ from makefile components/esp32: clarify type of queue in wifi_init_config_t, add default init macro components/esp32: add ESP_ERROR_CHECK Event handling refactoring clean up warnings components/esp32,bt: fix typos in comments Startup flow refactoring Roll back submodule version ...
This commit is contained in:
@@ -80,33 +80,22 @@ config WIFI_ENABLED
|
||||
|
||||
Temporarily, this option is not compatible with BT stack.
|
||||
|
||||
config WIFI_AUTO_STARTUP
|
||||
bool "Start WiFi with system startup"
|
||||
default "y"
|
||||
depends on WIFI_ENABLED
|
||||
help
|
||||
By default, WiFi is started with system startup, you can turn off this
|
||||
feature and start by yourself.
|
||||
|
||||
config WIFI_AUTO_CONNECT
|
||||
bool "Enable auto connect"
|
||||
default "y"
|
||||
depends on WIFI_ENABLED
|
||||
help
|
||||
If station is enabled, and station config is set, this will enable WiFi
|
||||
station auto connect when WiFi startup.
|
||||
|
||||
config SYSTEM_EVENT_QUEUE_SIZE
|
||||
int "system event queue size"
|
||||
int "System event queue size"
|
||||
default 32
|
||||
depends on WIFI_ENABLED
|
||||
help
|
||||
Config system event queue size in different application.
|
||||
|
||||
config SYSTEM_EVENT_TASK_STACK_SIZE
|
||||
int "system event task stack size"
|
||||
int "Event loop task stack size"
|
||||
default 2048
|
||||
depends on WIFI_ENABLED
|
||||
help
|
||||
Config system event task stack size in different application.
|
||||
|
||||
|
||||
config MAIN_TASK_STACK_SIZE
|
||||
int "Main task stack size"
|
||||
default 4096
|
||||
help
|
||||
Config system event task stack size in different application.
|
||||
|
||||
|
||||
@@ -43,14 +43,19 @@
|
||||
#include "esp_ipc.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static void IRAM_ATTR user_start_cpu0(void);
|
||||
static void IRAM_ATTR call_user_start_cpu1();
|
||||
static void IRAM_ATTR user_start_cpu1(void);
|
||||
void start_cpu0(void) __attribute__((weak, alias("start_cpu0_default")));
|
||||
void start_cpu0_default(void) IRAM_ATTR;
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
static void IRAM_ATTR call_start_cpu1();
|
||||
void start_cpu1(void) __attribute__((weak, alias("start_cpu1_default")));
|
||||
void start_cpu1_default(void) IRAM_ATTR;
|
||||
static bool app_cpu_started = false;
|
||||
#endif //!CONFIG_FREERTOS_UNICORE
|
||||
|
||||
static void do_global_ctors(void);
|
||||
static void main_task(void* args);
|
||||
extern void ets_setup_syscalls(void);
|
||||
extern esp_err_t app_main(void *ctx);
|
||||
#if CONFIG_BT_ENABLED
|
||||
extern void bt_app_main(void *param);
|
||||
#endif
|
||||
extern int app_main(void);
|
||||
|
||||
extern int _bss_start;
|
||||
extern int _bss_end;
|
||||
@@ -60,14 +65,13 @@ extern void (*__init_array_end)(void);
|
||||
extern volatile int port_xSchedulerRunning[2];
|
||||
|
||||
static const char* TAG = "cpu_start";
|
||||
static bool app_cpu_started = false;
|
||||
|
||||
/*
|
||||
* We arrive here after the bootloader finished loading the program from flash. The hardware is mostly uninitialized,
|
||||
* and the app CPU is in reset. We do have a stack, so we can do the initialization in C.
|
||||
*/
|
||||
|
||||
void IRAM_ATTR call_user_start_cpu0()
|
||||
void IRAM_ATTR call_start_cpu0()
|
||||
{
|
||||
//Kill wdt
|
||||
REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN);
|
||||
@@ -90,14 +94,14 @@ void IRAM_ATTR call_user_start_cpu0()
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "Pro cpu up.");
|
||||
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
ESP_EARLY_LOGI(TAG, "Starting app cpu, entry point is %p", call_user_start_cpu1);
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
ESP_EARLY_LOGI(TAG, "Starting app cpu, entry point is %p", call_start_cpu1);
|
||||
|
||||
SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN);
|
||||
CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL);
|
||||
SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING);
|
||||
CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING);
|
||||
ets_set_appcpu_boot_addr((uint32_t)call_user_start_cpu1);
|
||||
ets_set_appcpu_boot_addr((uint32_t)call_start_cpu1);
|
||||
|
||||
while (!app_cpu_started) {
|
||||
ets_delay_us(100);
|
||||
@@ -107,11 +111,11 @@ void IRAM_ATTR call_user_start_cpu0()
|
||||
CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN);
|
||||
#endif
|
||||
ESP_EARLY_LOGI(TAG, "Pro cpu start user code");
|
||||
user_start_cpu0();
|
||||
start_cpu0();
|
||||
}
|
||||
|
||||
|
||||
void IRAM_ATTR call_user_start_cpu1()
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
void IRAM_ATTR call_start_cpu1()
|
||||
{
|
||||
asm volatile (\
|
||||
"wsr %0, vecbase\n" \
|
||||
@@ -121,10 +125,27 @@ void IRAM_ATTR call_user_start_cpu1()
|
||||
|
||||
ESP_EARLY_LOGI(TAG, "App cpu up.");
|
||||
app_cpu_started = 1;
|
||||
user_start_cpu1();
|
||||
start_cpu1();
|
||||
}
|
||||
#endif //!CONFIG_FREERTOS_UNICORE
|
||||
|
||||
void start_cpu0_default(void)
|
||||
{
|
||||
esp_set_cpu_freq(); // set CPU frequency configured in menuconfig
|
||||
uart_div_modify(0, (APB_CLK_FREQ << 4) / 115200);
|
||||
ets_setup_syscalls();
|
||||
do_global_ctors();
|
||||
esp_ipc_init();
|
||||
spi_flash_init();
|
||||
xTaskCreatePinnedToCore(&main_task, "main",
|
||||
ESP_TASK_MAIN_STACK, NULL,
|
||||
ESP_TASK_MAIN_PRIO, NULL, 0);
|
||||
ESP_LOGI(TAG, "Starting scheduler on PRO CPU.");
|
||||
vTaskStartScheduler();
|
||||
}
|
||||
|
||||
void IRAM_ATTR user_start_cpu1(void)
|
||||
#if !CONFIG_FREERTOS_UNICORE
|
||||
void start_cpu1_default(void)
|
||||
{
|
||||
// Wait for FreeRTOS initialization to finish on PRO CPU
|
||||
while (port_xSchedulerRunning[0] == 0) {
|
||||
@@ -133,46 +154,19 @@ void IRAM_ATTR user_start_cpu1(void)
|
||||
ESP_LOGI(TAG, "Starting scheduler on APP CPU.");
|
||||
xPortStartScheduler();
|
||||
}
|
||||
#endif //!CONFIG_FREERTOS_UNICORE
|
||||
|
||||
static void do_global_ctors(void)
|
||||
{
|
||||
void (**p)(void);
|
||||
for (p = &__init_array_start; p != &__init_array_end; ++p) {
|
||||
for (p = &__init_array_end - 1; p >= &__init_array_start; --p) {
|
||||
(*p)();
|
||||
}
|
||||
}
|
||||
|
||||
void user_start_cpu0(void)
|
||||
static void main_task(void* args)
|
||||
{
|
||||
esp_set_cpu_freq(); // set CPU frequency configured in menuconfig
|
||||
uart_div_modify(0, (APB_CLK_FREQ << 4) / 115200);
|
||||
ets_setup_syscalls();
|
||||
do_global_ctors();
|
||||
esp_ipc_init();
|
||||
spi_flash_init();
|
||||
|
||||
#if CONFIG_WIFI_ENABLED
|
||||
esp_err_t ret = nvs_flash_init(5, 3);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "nvs_flash_init failed, ret=%d", ret);
|
||||
}
|
||||
|
||||
system_init();
|
||||
esp_event_init(NULL, NULL);
|
||||
tcpip_adapter_init();
|
||||
#endif
|
||||
|
||||
#if CONFIG_WIFI_ENABLED && CONFIG_WIFI_AUTO_STARTUP
|
||||
#include "esp_wifi.h"
|
||||
esp_wifi_startup(app_main, NULL);
|
||||
#elif CONFIG_BT_ENABLED
|
||||
#include "bt.h"
|
||||
esp_bt_startup(bt_app_main, NULL);
|
||||
#else
|
||||
app_main(NULL);
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Starting scheduler on PRO CPU.");
|
||||
vTaskStartScheduler();
|
||||
app_main();
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_task.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
@@ -27,22 +28,15 @@
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#define ESP32_WORKAROUND 1
|
||||
const char* TAG = "event";
|
||||
|
||||
#if CONFIG_WIFI_ENABLED
|
||||
static bool event_init_flag = false;
|
||||
static xQueueHandle g_event_handler = NULL;
|
||||
|
||||
static system_event_cb_t g_event_handler_cb;
|
||||
static void *g_event_ctx;
|
||||
|
||||
#define WIFI_DEBUG(...)
|
||||
#define WIFI_API_CALL_CHECK(info, api_call, ret) \
|
||||
do{\
|
||||
esp_err_t __err = (api_call);\
|
||||
if ((ret) != __err) {\
|
||||
WIFI_DEBUG("%s %d %s ret=%d\n", __FUNCTION__, __LINE__, (info), __err);\
|
||||
ESP_LOGE(TAG, "%s %d %s ret=%d", __FUNCTION__, __LINE__, (info), __err);\
|
||||
return __err;\
|
||||
}\
|
||||
} while(0)
|
||||
@@ -71,7 +65,7 @@ static system_event_handle_t g_system_event_handle_table[] = {
|
||||
{SYSTEM_EVENT_STA_CONNECTED, system_event_sta_connected_handle_default},
|
||||
{SYSTEM_EVENT_STA_DISCONNECTED, system_event_sta_disconnected_handle_default},
|
||||
{SYSTEM_EVENT_STA_AUTHMODE_CHANGE, NULL},
|
||||
{SYSTEM_EVENT_STA_GOT_IP, system_event_sta_got_ip_default},
|
||||
{SYSTEM_EVENT_STA_GOT_IP, system_event_sta_got_ip_default},
|
||||
{SYSTEM_EVENT_AP_START, system_event_ap_start_handle_default},
|
||||
{SYSTEM_EVENT_AP_STOP, system_event_ap_stop_handle_default},
|
||||
{SYSTEM_EVENT_AP_STACONNECTED, NULL},
|
||||
@@ -85,7 +79,7 @@ static esp_err_t system_event_sta_got_ip_default(system_event_t *event)
|
||||
extern esp_err_t esp_wifi_set_sta_ip(void);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK);
|
||||
|
||||
printf("ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR "\n",
|
||||
ESP_LOGI(TAG, "ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip),
|
||||
IP2STR(&event->event_info.got_ip.ip_info.netmask),
|
||||
IP2STR(&event->event_info.got_ip.ip_info.gw));
|
||||
@@ -161,7 +155,7 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
|
||||
|
||||
esp_event_send(&evt);
|
||||
} else {
|
||||
WIFI_DEBUG("invalid static ip\n");
|
||||
ESP_LOGE(TAG, "invalid static ip");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,104 +169,89 @@ esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_wifi_post_event_to_user(system_event_t *event)
|
||||
{
|
||||
if (g_event_handler_cb) {
|
||||
return (*g_event_handler_cb)(g_event_ctx, event);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_system_event_debug(system_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
printf("Error: event is null!\n");
|
||||
ESP_LOGE(TAG, "event is null!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
WIFI_DEBUG("received event: ");
|
||||
switch (event->event_id) {
|
||||
case SYSTEM_EVENT_WIFI_READY: {
|
||||
WIFI_DEBUG("SYSTEM_EVENT_WIFI_READY\n");
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_WIFI_READY");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_SCAN_DONE: {
|
||||
system_event_sta_scan_done_t *scan_done;
|
||||
scan_done = &event->event_info.scan_done;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_SCAN_DONE\nstatus:%d, number:%d\n", scan_done->status, scan_done->number);
|
||||
system_event_sta_scan_done_t *scan_done = &event->event_info.scan_done;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_SCAN_DONE, status:%d, number:%d", scan_done->status, scan_done->number);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_START: {
|
||||
WIFI_DEBUG("SYSTEM_EVENT_STA_START\n");
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_STOP: {
|
||||
WIFI_DEBUG("SYSTEM_EVENT_STA_STOP\n");
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_CONNECTED: {
|
||||
system_event_sta_connected_t *connected;
|
||||
connected = &event->event_info.connected;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_STA_CONNECTED\nssid:%s, ssid_len:%d, bssid:%02x:%02x:%02x:%02x:%02x:%02x, channel:%d, authmode:%d\n", \
|
||||
system_event_sta_connected_t *connected = &event->event_info.connected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_CONNECTED, ssid:%s, ssid_len:%d, bssid:%02x:%02x:%02x:%02x:%02x:%02x, channel:%d, authmode:%d", \
|
||||
connected->ssid, connected->ssid_len, connected->bssid[0], connected->bssid[0], connected->bssid[1], \
|
||||
connected->bssid[3], connected->bssid[4], connected->bssid[5], connected->channel, connected->authmode);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
||||
system_event_sta_disconnected_t *disconnected;
|
||||
disconnected = &event->event_info.disconnected;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_STA_DISCONNECTED\nssid:%s, ssid_len:%d, bssid:%02x:%02x:%02x:%02x:%02x:%02x, reason:%d\n", \
|
||||
system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED, ssid:%s, ssid_len:%d, bssid:%02x:%02x:%02x:%02x:%02x:%02x, reason:%d", \
|
||||
disconnected->ssid, disconnected->ssid_len, disconnected->bssid[0], disconnected->bssid[0], disconnected->bssid[1], \
|
||||
disconnected->bssid[3], disconnected->bssid[4], disconnected->bssid[5], disconnected->reason);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
||||
system_event_sta_authmode_change_t *auth_change;
|
||||
auth_change = &event->event_info.auth_change;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_STA_AUTHMODE_CHNAGE\nold_mode:%d, new_mode:%d\n", auth_change->old_mode, auth_change->new_mode);
|
||||
system_event_sta_authmode_change_t *auth_change = &event->event_info.auth_change;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_AUTHMODE_CHNAGE, old_mode:%d, new_mode:%d", auth_change->old_mode, auth_change->new_mode);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_GOT_IP: {
|
||||
system_event_sta_got_ip_t *got_ip;
|
||||
got_ip = &event->event_info.got_ip;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_STA_GOTIP\n");
|
||||
system_event_sta_got_ip_t *got_ip = &event->event_info.got_ip;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_GOTIP, ip:" IPSTR ", mask:" IPSTR ", gw:" IPSTR,
|
||||
IP2STR(&got_ip->ip_info.ip),
|
||||
IP2STR(&got_ip->ip_info.netmask),
|
||||
IP2STR(&got_ip->ip_info.gw));
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_START: {
|
||||
WIFI_DEBUG("SYSTEM_EVENT_AP_START\n");
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STOP: {
|
||||
WIFI_DEBUG("SYSTEM_EVENT_AP_STOP\n");
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STACONNECTED: {
|
||||
system_event_ap_staconnected_t *staconnected;
|
||||
staconnected = &event->event_info.sta_connected;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_AP_STACONNECTED\nmac:%02x:%02x:%02x:%02x:%02x:%02x, aid:%d\n", \
|
||||
system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:%02x:%02x:%02x:%02x:%02x:%02x, aid:%d", \
|
||||
staconnected->mac[0], staconnected->mac[0], staconnected->mac[1], \
|
||||
staconnected->mac[3], staconnected->mac[4], staconnected->mac[5], staconnected->aid);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STADISCONNECTED: {
|
||||
system_event_ap_stadisconnected_t *stadisconnected;
|
||||
stadisconnected = &event->event_info.sta_disconnected;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_AP_STADISCONNECTED\nmac:%02x:%02x:%02x:%02x:%02x:%02x, aid:%d\n", \
|
||||
system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:%02x:%02x:%02x:%02x:%02x:%02x, aid:%d", \
|
||||
stadisconnected->mac[0], stadisconnected->mac[0], stadisconnected->mac[1], \
|
||||
stadisconnected->mac[3], stadisconnected->mac[4], stadisconnected->mac[5], stadisconnected->aid);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_PROBEREQRECVED: {
|
||||
system_event_ap_probe_req_rx_t *ap_probereqrecved;
|
||||
ap_probereqrecved = &event->event_info.ap_probereqrecved;
|
||||
WIFI_DEBUG("SYSTEM_EVENT_AP_PROBEREQRECVED\nrssi:%d, mac:%02x:%02x:%02x:%02x:%02x:%02x\n", \
|
||||
system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:%02x:%02x:%02x:%02x:%02x:%02x", \
|
||||
ap_probereqrecved->rssi, ap_probereqrecved->mac[0], ap_probereqrecved->mac[0], ap_probereqrecved->mac[1], \
|
||||
ap_probereqrecved->mac[3], ap_probereqrecved->mac[4], ap_probereqrecved->mac[5]);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
printf("Error: no such kind of event!\n");
|
||||
ESP_LOGW(TAG, "no such kind of event!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -280,88 +259,23 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_system_event_handler(system_event_t *event)
|
||||
esp_err_t esp_event_process_default(system_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
printf("Error: event is null!\n");
|
||||
ESP_LOGE(TAG, "Error: event is null!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_system_event_debug(event);
|
||||
if ((event->event_id < SYSTEM_EVENT_MAX) && (event->event_id == g_system_event_handle_table[event->event_id].event_id)) {
|
||||
if (g_system_event_handle_table[event->event_id].event_handle) {
|
||||
WIFI_DEBUG("enter default callback\n");
|
||||
ESP_LOGV(TAG, "enter default callback");
|
||||
g_system_event_handle_table[event->event_id].event_handle(event);
|
||||
WIFI_DEBUG("exit default callback\n");
|
||||
ESP_LOGV(TAG, "exit default callback");
|
||||
}
|
||||
} else {
|
||||
printf("mismatch or invalid event, id=%d\n", event->event_id);
|
||||
}
|
||||
|
||||
return esp_wifi_post_event_to_user(event);
|
||||
}
|
||||
|
||||
static void esp_system_event_task(void *pvParameters)
|
||||
{
|
||||
system_event_t evt;
|
||||
esp_err_t ret;
|
||||
|
||||
while (1) {
|
||||
if (xQueueReceive(g_event_handler, &evt, portMAX_DELAY) == pdPASS) {
|
||||
ret = esp_system_event_handler(&evt);
|
||||
if (ret == ESP_FAIL) {
|
||||
printf("esp wifi post event to user fail!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
system_event_cb_t esp_event_set_cb(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
system_event_cb_t old_cb = g_event_handler_cb;
|
||||
|
||||
g_event_handler_cb = cb;
|
||||
g_event_ctx = ctx;
|
||||
|
||||
return old_cb;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_send(system_event_t *event)
|
||||
{
|
||||
portBASE_TYPE ret;
|
||||
|
||||
ret = xQueueSendToBack((xQueueHandle)g_event_handler, event, 0);
|
||||
|
||||
if (pdPASS != ret) {
|
||||
if (event) {
|
||||
printf("e=%d f\n", event->event_id);
|
||||
} else {
|
||||
printf("e null\n");
|
||||
}
|
||||
ESP_LOGE(TAG, "mismatch or invalid event, id=%d", event->event_id);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void *esp_event_get_handler(void)
|
||||
{
|
||||
return (void *)g_event_handler;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_init(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
if (event_init_flag) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
g_event_handler_cb = cb;
|
||||
g_event_ctx = ctx;
|
||||
|
||||
g_event_handler = xQueueCreate(CONFIG_SYSTEM_EVENT_QUEUE_SIZE, sizeof(system_event_t));
|
||||
|
||||
xTaskCreatePinnedToCore(esp_system_event_task, "eventTask", ESP_TASKD_EVENT_STACK, NULL, ESP_TASKD_EVENT_PRIO, NULL, 0);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_task.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
|
||||
static const char* TAG = "event";
|
||||
static bool s_event_init_flag = false;
|
||||
static QueueHandle_t s_event_queue = NULL;
|
||||
static system_event_cb_t s_event_handler_cb = NULL;
|
||||
static void *s_event_ctx = NULL;
|
||||
|
||||
static esp_err_t esp_event_post_to_user(system_event_t *event)
|
||||
{
|
||||
if (s_event_handler_cb) {
|
||||
return (*s_event_handler_cb)(s_event_ctx, event);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void esp_event_loop_task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
system_event_t evt;
|
||||
if (xQueueReceive(s_event_queue, &evt, portMAX_DELAY) == pdPASS) {
|
||||
esp_err_t ret = esp_event_process_default(&evt);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "default event handler failed!");
|
||||
}
|
||||
ret = esp_event_post_to_user(&evt);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "post event to user fail!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
system_event_cb_t old_cb = s_event_handler_cb;
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
return old_cb;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_send(system_event_t *event)
|
||||
{
|
||||
portBASE_TYPE ret = xQueueSendToBack(s_event_queue, event, 0);
|
||||
if (ret != pdPASS) {
|
||||
if (event) {
|
||||
ESP_LOGE(TAG, "e=%d f", event->event_id);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "e null");
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
QueueHandle_t esp_event_loop_get_queue(void)
|
||||
{
|
||||
return s_event_queue;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
if (s_event_init_flag) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
s_event_queue = xQueueCreate(CONFIG_SYSTEM_EVENT_QUEUE_SIZE, sizeof(system_event_t));
|
||||
|
||||
xTaskCreatePinnedToCore(esp_event_loop_task, "eventTask",
|
||||
ESP_TASKD_EVENT_STACK, NULL, ESP_TASKD_EVENT_PRIO, NULL, 0);
|
||||
|
||||
s_event_init_flag = true;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#define __ESP_ERR_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -31,6 +32,12 @@ typedef int32_t esp_err_t;
|
||||
#define ESP_ERR_INVALID_ARG 0x102
|
||||
#define ESP_ERR_INVALID_STATE 0x103
|
||||
|
||||
/**
|
||||
* Macro which can be used to check the error code,
|
||||
* and terminate the program in case the code is not ESP_OK.
|
||||
* Prints the failed statement to serial output.
|
||||
*/
|
||||
#define ESP_ERROR_CHECK(x) do { esp_err_t rc = (x); if (rc != ESP_OK) { assert(0 && #x);} } while(0);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -101,34 +101,10 @@ typedef union {
|
||||
} system_event_info_t;
|
||||
|
||||
typedef struct {
|
||||
system_event_id_t event_id; /**< even ID */
|
||||
system_event_id_t event_id; /**< event ID */
|
||||
system_event_info_t event_info; /**< event information */
|
||||
} system_event_t;
|
||||
|
||||
/**
|
||||
* @brief Application specified event callback function
|
||||
*
|
||||
* @param void *ctx : reserved for user
|
||||
* @param system_event_t *event : event type defined in this file
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Set application specified event callback function
|
||||
*
|
||||
* @attention 1. If cb is NULL, means application don't need to handle
|
||||
* If cb is not NULL, it will be call when an event is received, after the default event callback is completed
|
||||
*
|
||||
* @param system_event_cb_t cb : callback
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return system_event_cb_t : old callback
|
||||
*/
|
||||
system_event_cb_t esp_event_set_cb(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Send a event to event task
|
||||
*
|
||||
@@ -142,28 +118,20 @@ system_event_cb_t esp_event_set_cb(system_event_cb_t cb, void *ctx);
|
||||
esp_err_t esp_event_send(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Get the event handler
|
||||
* @brief Default event handler for system events
|
||||
*
|
||||
* @attention : currently this API returns event queue handler, by this event queue,
|
||||
* users can notice when WiFi has done something like scanning done, connected to AP or disconnected from AP.
|
||||
* This function performs default handling of system events.
|
||||
* When using esp_event_loop APIs, it is called automatically before invoking the user-provided
|
||||
* callback function.
|
||||
*
|
||||
* @param null
|
||||
* Applications which implement a custom event loop must call this function
|
||||
* as part of event processing.
|
||||
*
|
||||
* @return void * : event queue pointer
|
||||
* @param event pointer to event to be handled
|
||||
* @return ESP_OK if an event was handled successfully
|
||||
*/
|
||||
void *esp_event_get_handler(void);
|
||||
esp_err_t esp_event_process_default(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Init the event module
|
||||
* Create the event handler and task
|
||||
*
|
||||
* @param system_event_cb_t cb : application specified event callback, it can be modified by call esp_event_set_cb
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
esp_err_t esp_event_init(system_event_cb_t cb, void *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __ESP_EVENT_LOOP_H__
|
||||
#define __ESP_EVENT_LOOP_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Application specified event callback function
|
||||
*
|
||||
* @param void *ctx : reserved for user
|
||||
* @param system_event_t *event : event type defined in this file
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Initialize event loop
|
||||
* Create the event handler and task
|
||||
*
|
||||
* @param system_event_cb_t cb : application specified event callback, it can be modified by call esp_event_set_cb
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Set application specified event callback function
|
||||
*
|
||||
* @attention 1. If cb is NULL, means application don't need to handle
|
||||
* If cb is not NULL, it will be call when an event is received, after the default event callback is completed
|
||||
*
|
||||
* @param system_event_cb_t cb : callback
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return system_event_cb_t : old callback
|
||||
*/
|
||||
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Get the queue used by event loop
|
||||
*
|
||||
* @attention : currently this API is used to initialize "q" parameter
|
||||
* of wifi_init structure.
|
||||
*
|
||||
* @return QueueHandle_t : event queue handle
|
||||
*/
|
||||
QueueHandle_t esp_event_loop_get_queue(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_EVENT_LOOP_H__ */
|
||||
@@ -15,10 +15,10 @@
|
||||
/* Notes:
|
||||
* 1. Put all task priority and stack size definition in this file
|
||||
* 2. If the task priority is less than 10, use ESP_TASK_PRIO_MIN + X style,
|
||||
* otherwise use ESP_TASK_PRIO_MIN - X style
|
||||
* 3. If this is a daemon task, the macro prifix is ESP_TASKD_, otherwise
|
||||
* otherwise use ESP_TASK_PRIO_MAX - X style
|
||||
* 3. If this is a daemon task, the macro prefix is ESP_TASKD_, otherwise
|
||||
* it's ESP_TASK_
|
||||
* 4. If the configMAX_PRIORITIES is modified, please make all prority are
|
||||
* 4. If the configMAX_PRIORITIES is modified, please make all priority are
|
||||
* greater than 0
|
||||
* 5. Make sure esp_task.h is consistent between wifi lib and idf
|
||||
*/
|
||||
@@ -51,10 +51,9 @@
|
||||
/* idf task */
|
||||
#define ESP_TASKD_EVENT_PRIO (ESP_TASK_PRIO_MAX - 5)
|
||||
#define ESP_TASKD_EVENT_STACK CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE
|
||||
#define ESP_TASK_WIFI_STARTUP_PRIO (ESP_TASK_PRIO_MAX - 7)
|
||||
#define ESP_TASK_WIFI_STARTUP_STACK 4096
|
||||
#define ESP_TASK_TCPIP_PRIO (ESP_TASK_PRIO_MAX - 7)
|
||||
#define ESP_TASK_TCPIP_STACK 2048
|
||||
#define ESP_TASK_BT_INIT_PRIO (ESP_TASK_PRIO_MAX - 7)
|
||||
#define ESP_TASK_BT_INIT_STACK 2048
|
||||
#define ESP_TASK_MAIN_PRIO (ESP_TASK_PRIO_MIN + 1)
|
||||
#define ESP_TASK_MAIN_STACK CONFIG_MAIN_TASK_STACK_SIZE
|
||||
|
||||
#endif
|
||||
|
||||
@@ -59,7 +59,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "esp_err.h"
|
||||
#include "rom/queue.h"
|
||||
|
||||
@@ -136,36 +137,24 @@ typedef enum {
|
||||
WIFI_SECOND_CHAN_BELOW, /**< the channel width is HT40 and the second channel is below the primary channel */
|
||||
} wifi_second_chan_t;
|
||||
|
||||
/**
|
||||
* @brief startup WiFi driver and register application specific callback function
|
||||
*
|
||||
* @attention 1. This API should be called in application startup code to init WiFi driver
|
||||
* @attention 2. The callback function is used to provide application specific WiFi configuration,
|
||||
* such as, set the WiFi mode, register the event callback, set AP SSID etc before
|
||||
* WiFi is startup
|
||||
* @attention 3. Avoid to create application task in the callback, otherwise you may get wrong behavior
|
||||
* @attention 4. If the callback return is not ESP_OK, the startup will fail!
|
||||
* @attention 5. Before this API can be called, system_init()/esp_event_init()/tcpip_adapter_init() should
|
||||
* be called firstly
|
||||
*
|
||||
* @param wifi_startup_cb_t cb : application specific callback function
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
typedef esp_err_t (* wifi_startup_cb_t)(void *ctx);
|
||||
|
||||
esp_err_t esp_wifi_startup(wifi_startup_cb_t cb, void *ctx);
|
||||
|
||||
typedef struct {
|
||||
void *event_q; /**< WiFi event q handler, it's a freeRTOS queue */
|
||||
QueueHandle_t event_queue; /**< WiFi event queue handle */
|
||||
uint8_t rx_ba_win; /**< TBC */
|
||||
uint8_t tx_ba_win; /**< TBC */
|
||||
uint8_t rx_buf_cnt; /**< TBC */
|
||||
uint8_t tx_buf_cnt; /**< TBC */
|
||||
} wifi_init_config_t;
|
||||
|
||||
|
||||
#define WIFI_INIT_CONFIG_DEFAULT(event_queue_) { \
|
||||
.event_queue = event_queue_, \
|
||||
.rx_ba_win = 0, \
|
||||
.tx_ba_win = 0, \
|
||||
.rx_buf_cnt = 0, \
|
||||
.tx_buf_cnt = 0 \
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Init WiFi
|
||||
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Default entry point: */
|
||||
ENTRY(call_user_start_cpu0);
|
||||
ENTRY(call_start_cpu0);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
@@ -449,7 +449,6 @@ PROVIDE ( _lseek_r = 0x4000bd8c );
|
||||
PROVIDE ( __lshrdi3 = 0x4000c84c );
|
||||
PROVIDE ( __ltdf2 = 0x40063790 );
|
||||
PROVIDE ( __ltsf2 = 0x4006342c );
|
||||
PROVIDE ( main = 0x400076c4 );
|
||||
PROVIDE ( malloc = 0x4000bea0 );
|
||||
PROVIDE ( _malloc_r = 0x4000bbb4 );
|
||||
PROVIDE ( maxSecretKey_256 = 0x3ff97448 );
|
||||
@@ -1382,6 +1381,7 @@ PROVIDE ( rom_iq_est_disable = 0x40005590 );
|
||||
PROVIDE ( rom_iq_est_enable = 0x40005514 );
|
||||
PROVIDE ( rom_linear_to_db = 0x40005f64 );
|
||||
PROVIDE ( rom_loopback_mode_en = 0x400030f8 );
|
||||
PROVIDE ( rom_main = 0x400076c4 );
|
||||
PROVIDE ( rom_meas_tone_pwr_db = 0x40006004 );
|
||||
PROVIDE ( rom_mhz2ieee = 0x4000404c );
|
||||
PROVIDE ( rom_noise_floor_auto_set = 0x40003bdc );
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_task.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#if CONFIG_WIFI_ENABLED
|
||||
|
||||
static bool wifi_startup_flag = false;
|
||||
|
||||
static wifi_startup_cb_t startup_cb;
|
||||
static void *startup_ctx;
|
||||
|
||||
#define WIFI_DEBUG(...)
|
||||
#define WIFI_API_CALL_CHECK(info, api_call, ret) \
|
||||
do{\
|
||||
esp_err_t __err = (api_call);\
|
||||
if ((ret) != __err) {\
|
||||
WIFI_DEBUG("%s %d %s ret=%d\n", __FUNCTION__, __LINE__, (info), __err);\
|
||||
return __err;\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
|
||||
|
||||
static void esp_wifi_task(void *pvParameters)
|
||||
{
|
||||
esp_err_t err;
|
||||
wifi_init_config_t cfg;
|
||||
cfg.event_q = (xQueueHandle)esp_event_get_handler();
|
||||
|
||||
do {
|
||||
err = esp_wifi_init(&cfg);
|
||||
if (err != ESP_OK) {
|
||||
WIFI_DEBUG("esp_wifi_init fail, ret=%d\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
if (startup_cb) {
|
||||
err = (*startup_cb)(startup_ctx);
|
||||
if (err != ESP_OK) {
|
||||
WIFI_DEBUG("startup_cb fail, ret=%d\n", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
err = esp_wifi_start();
|
||||
if (err != ESP_OK) {
|
||||
WIFI_DEBUG("esp_wifi_start fail, ret=%d\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
#if CONFIG_WIFI_AUTO_CONNECT
|
||||
wifi_mode_t mode;
|
||||
bool auto_connect;
|
||||
err = esp_wifi_get_mode(&mode);
|
||||
if (err != ESP_OK) {
|
||||
WIFI_DEBUG("esp_wifi_get_mode fail, ret=%d\n", err);
|
||||
}
|
||||
|
||||
err = esp_wifi_get_auto_connect(&auto_connect);
|
||||
if ((mode == WIFI_MODE_STA || mode == WIFI_MODE_APSTA) && auto_connect) {
|
||||
err = esp_wifi_connect();
|
||||
if (err != ESP_OK) {
|
||||
WIFI_DEBUG("esp_wifi_connect fail, ret=%d\n", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} while (0);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
WIFI_DEBUG("wifi startup fail, deinit\n");
|
||||
esp_wifi_deinit();
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
esp_err_t esp_wifi_startup(wifi_startup_cb_t cb, void *ctx)
|
||||
{
|
||||
if (wifi_startup_flag) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
startup_cb = cb;
|
||||
startup_ctx = ctx;
|
||||
|
||||
xTaskCreatePinnedToCore(esp_wifi_task, "wifiTask", ESP_TASK_WIFI_STARTUP_STACK, NULL, ESP_TASK_WIFI_STARTUP_PRIO, NULL, 0);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user