mirror of
				https://github.com/espressif/esp-idf.git
				synced 2025-11-04 00:51:42 +01:00 
			
		
		
		
	Merge branch 'master' into feature/modem_sleep
Conflicts: components/nvs_flash/src/nvs_api.cpp
This commit is contained in:
		@@ -364,4 +364,43 @@ config ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL
 | 
			
		||||
	depends on DOCUMENTATION_FOR_RTC_CNTL
 | 
			
		||||
endchoice
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
config ESP32_PHY_AUTO_INIT
 | 
			
		||||
	bool "Initialize PHY in startup code"
 | 
			
		||||
	default y
 | 
			
		||||
	help
 | 
			
		||||
		If enabled, PHY will be initialized in startup code, before
 | 
			
		||||
		app_main function runs.
 | 
			
		||||
		If this is undesired, disable this option and call esp_phy_init
 | 
			
		||||
		from the application before enabling WiFi or BT.
 | 
			
		||||
		
 | 
			
		||||
		If this option is enabled, startup code will also initialize 
 | 
			
		||||
		NVS prior to initializing PHY.
 | 
			
		||||
		
 | 
			
		||||
		If unsure, choose 'y'. 
 | 
			
		||||
 | 
			
		||||
config ESP32_PHY_INIT_DATA_IN_PARTITION
 | 
			
		||||
	bool "Use a partition to store PHY init data"
 | 
			
		||||
	default n
 | 
			
		||||
	help
 | 
			
		||||
		If enabled, PHY init data will be loaded from a partition.
 | 
			
		||||
		When using a custom partition table, make sure that PHY data
 | 
			
		||||
		partition is included (type: 'data', subtype: 'phy'). 
 | 
			
		||||
		With default partition tables, this is done automatically. 
 | 
			
		||||
		If PHY init data is stored in a partition, it has to be flashed there,
 | 
			
		||||
		otherwise runtime error will occur.
 | 
			
		||||
		
 | 
			
		||||
		If this option is not enabled, PHY init data will be embedded
 | 
			
		||||
		into the application binary.
 | 
			
		||||
		
 | 
			
		||||
		If unsure, choose 'n'.
 | 
			
		||||
 | 
			
		||||
config ESP32_PHY_MAX_TX_POWER
 | 
			
		||||
	int "Max TX power (dBm)"
 | 
			
		||||
	range 0 20
 | 
			
		||||
	default 20
 | 
			
		||||
	help
 | 
			
		||||
		Set maximum transmit power. Actual transmit power for high
 | 
			
		||||
		data rates may be lower than this setting.
 | 
			
		||||
 | 
			
		||||
endmenu
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										32
									
								
								components/esp32/Makefile.projbuild
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								components/esp32/Makefile.projbuild
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
ifdef CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION
 | 
			
		||||
 | 
			
		||||
PHY_INIT_DATA_OBJ = $(BUILD_DIR_BASE)/phy_init_data.o
 | 
			
		||||
PHY_INIT_DATA_BIN = $(BUILD_DIR_BASE)/phy_init_data.bin
 | 
			
		||||
 | 
			
		||||
# Command to flash PHY init data partition
 | 
			
		||||
PHY_INIT_DATA_FLASH_CMD = $(ESPTOOLPY_SERIAL) write_flash $(CONFIG_PHY_DATA_OFFSET) $(PHY_INIT_DATA_BIN)
 | 
			
		||||
ESPTOOL_ALL_FLASH_ARGS += $(CONFIG_PHY_DATA_OFFSET) $(PHY_INIT_DATA_BIN)
 | 
			
		||||
 | 
			
		||||
ESP32_COMPONENT_PATH := $(COMPONENT_PATH)
 | 
			
		||||
 | 
			
		||||
$(PHY_INIT_DATA_OBJ): $(ESP32_COMPONENT_PATH)/phy_init_data.h $(BUILD_DIR_BASE)/include/sdkconfig.h
 | 
			
		||||
	$(summary) CC $(notdir $@)
 | 
			
		||||
	printf "#include \"phy_init_data.h\"\n" | $(CC) -I $(BUILD_DIR_BASE)/include -I $(ESP32_COMPONENT_PATH) -I $(ESP32_COMPONENT_PATH)/include -c -o $@ -xc -
 | 
			
		||||
 | 
			
		||||
$(PHY_INIT_DATA_BIN): $(PHY_INIT_DATA_OBJ)
 | 
			
		||||
	$(summary) BIN $(notdir $@)
 | 
			
		||||
	$(OBJCOPY) -O binary $< $@
 | 
			
		||||
 | 
			
		||||
phy_init_data: $(PHY_INIT_DATA_BIN)
 | 
			
		||||
 | 
			
		||||
phy_init_data-flash: $(BUILD_DIR_BASE)/phy_init_data.bin
 | 
			
		||||
	@echo "Flashing PHY init data..."
 | 
			
		||||
	$(PHY_INIT_DATA_FLASH_CMD)
 | 
			
		||||
 | 
			
		||||
phy_init_data-clean:
 | 
			
		||||
	rm -f $(PHY_INIT_DATA_BIN) $(PHY_INIT_DATA_OBJ)
 | 
			
		||||
 | 
			
		||||
all: phy_init_data
 | 
			
		||||
flash: phy_init_data
 | 
			
		||||
 | 
			
		||||
endif # CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION
 | 
			
		||||
@@ -17,9 +17,7 @@ COMPONENT_ADD_LDFLAGS := -lesp32 \
 | 
			
		||||
 | 
			
		||||
ALL_LIB_FILES := $(patsubst %,$(COMPONENT_PATH)/lib/lib%.a,$(LIBS))
 | 
			
		||||
 | 
			
		||||
# automatically trigger a git submodule update
 | 
			
		||||
# if any libraries are missing
 | 
			
		||||
$(eval $(call SubmoduleCheck,$(ALL_LIB_FILES),$(COMPONENT_PATH)/lib))
 | 
			
		||||
COMPONENT_SUBMODULES += lib
 | 
			
		||||
 | 
			
		||||
# this is a hack to make sure the app is re-linked if the binary
 | 
			
		||||
# libraries change or are updated. If they change, the main esp32
 | 
			
		||||
 
 | 
			
		||||
@@ -50,6 +50,7 @@
 | 
			
		||||
#include "esp_brownout.h"
 | 
			
		||||
#include "esp_int_wdt.h"
 | 
			
		||||
#include "esp_task_wdt.h"
 | 
			
		||||
#include "esp_phy_init.h"
 | 
			
		||||
#include "trax.h"
 | 
			
		||||
 | 
			
		||||
void start_cpu0(void) __attribute__((weak, alias("start_cpu0_default")));
 | 
			
		||||
@@ -62,6 +63,7 @@ static bool app_cpu_started = false;
 | 
			
		||||
#endif //!CONFIG_FREERTOS_UNICORE
 | 
			
		||||
 | 
			
		||||
static void do_global_ctors(void);
 | 
			
		||||
static void do_phy_init();
 | 
			
		||||
static void main_task(void* args);
 | 
			
		||||
extern void app_main(void);
 | 
			
		||||
 | 
			
		||||
@@ -187,6 +189,11 @@ void start_cpu0_default(void)
 | 
			
		||||
    esp_ipc_init();
 | 
			
		||||
    spi_flash_init();
 | 
			
		||||
 | 
			
		||||
#if CONFIG_ESP32_PHY_AUTO_INIT
 | 
			
		||||
    nvs_flash_init();
 | 
			
		||||
    do_phy_init();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    xTaskCreatePinnedToCore(&main_task, "main",
 | 
			
		||||
            ESP_TASK_MAIN_STACK, NULL,
 | 
			
		||||
            ESP_TASK_MAIN_PRIO, NULL, 0);
 | 
			
		||||
@@ -224,3 +231,36 @@ static void main_task(void* args)
 | 
			
		||||
    vTaskDelete(NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void do_phy_init()
 | 
			
		||||
{
 | 
			
		||||
    esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
 | 
			
		||||
    if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
 | 
			
		||||
        calibration_mode = PHY_RF_CAL_NONE;
 | 
			
		||||
    }
 | 
			
		||||
    const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
 | 
			
		||||
    if (init_data == NULL) {
 | 
			
		||||
        ESP_LOGE(TAG, "failed to obtain PHY init data");
 | 
			
		||||
        abort();
 | 
			
		||||
    }
 | 
			
		||||
    esp_phy_calibration_data_t* cal_data =
 | 
			
		||||
            (esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1);
 | 
			
		||||
    if (cal_data == NULL) {
 | 
			
		||||
        ESP_LOGE(TAG, "failed to allocate memory for RF calibration data");
 | 
			
		||||
        abort();
 | 
			
		||||
    }
 | 
			
		||||
    esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGW(TAG, "failed to load RF calibration data, falling back to full calibration");
 | 
			
		||||
        calibration_mode = PHY_RF_CAL_FULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    esp_phy_init(init_data, calibration_mode, cal_data);
 | 
			
		||||
 | 
			
		||||
    if (calibration_mode != PHY_RF_CAL_NONE) {
 | 
			
		||||
        err = esp_phy_store_cal_data_to_nvs(cal_data);
 | 
			
		||||
    } else {
 | 
			
		||||
        err = ESP_OK;
 | 
			
		||||
    }
 | 
			
		||||
    esp_phy_release_init_data(init_data);
 | 
			
		||||
    free(cal_data); // PHY maintains a copy of calibration data, so we can free this
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										96
									
								
								components/esp32/freertos_hooks.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								components/esp32/freertos_hooks.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,96 @@
 | 
			
		||||
// 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 <stdint.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "esp_attr.h"
 | 
			
		||||
#include "esp_freertos_hooks.h"
 | 
			
		||||
 | 
			
		||||
//We use just a static array here because it's not expected many components will need
 | 
			
		||||
//an idle or tick hook.
 | 
			
		||||
#define MAX_HOOKS 8
 | 
			
		||||
 | 
			
		||||
static esp_freertos_idle_cb_t idle_cb[MAX_HOOKS]={0};
 | 
			
		||||
static esp_freertos_tick_cb_t tick_cb[MAX_HOOKS]={0};
 | 
			
		||||
 | 
			
		||||
void IRAM_ATTR esp_vApplicationTickHook() 
 | 
			
		||||
{
 | 
			
		||||
    int n;
 | 
			
		||||
    for (n=0; n<MAX_HOOKS; n++) {
 | 
			
		||||
        if (tick_cb[n]!=NULL) {
 | 
			
		||||
            tick_cb[n]();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void esp_vApplicationIdleHook() 
 | 
			
		||||
{
 | 
			
		||||
    bool doWait=true;
 | 
			
		||||
    bool r;
 | 
			
		||||
    int n;
 | 
			
		||||
    for (n=0; n<MAX_HOOKS; n++) {
 | 
			
		||||
        if (idle_cb[n]!=NULL) {
 | 
			
		||||
            r=idle_cb[n]();
 | 
			
		||||
            if (!r) doWait=false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (doWait) {
 | 
			
		||||
        //Wait for whatever interrupt comes next... this should save some power.
 | 
			
		||||
        asm("waiti 0");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
esp_err_t esp_register_freertos_idle_hook(esp_freertos_idle_cb_t new_idle_cb) 
 | 
			
		||||
{
 | 
			
		||||
    int n;
 | 
			
		||||
    for (n=0; n<MAX_HOOKS; n++) {
 | 
			
		||||
        if (idle_cb[n]==NULL) {
 | 
			
		||||
            idle_cb[n]=new_idle_cb;
 | 
			
		||||
            return ESP_OK;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return ESP_ERR_NO_MEM;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
esp_err_t esp_register_freertos_tick_hook(esp_freertos_tick_cb_t new_tick_cb) 
 | 
			
		||||
{
 | 
			
		||||
    int n;
 | 
			
		||||
    for (n=0; n<MAX_HOOKS; n++) {
 | 
			
		||||
        if (tick_cb[n]==NULL) {
 | 
			
		||||
            tick_cb[n]=new_tick_cb;
 | 
			
		||||
            return ESP_OK;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return ESP_ERR_NO_MEM;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void esp_deregister_freertos_idle_hook(esp_freertos_idle_cb_t old_idle_cb)
 | 
			
		||||
{
 | 
			
		||||
    int n;
 | 
			
		||||
    for (n=0; n<MAX_HOOKS; n++) {
 | 
			
		||||
        if (idle_cb[n]==old_idle_cb) idle_cb[n]=NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t old_tick_cb)
 | 
			
		||||
{
 | 
			
		||||
    int n;
 | 
			
		||||
    for (n=0; n<MAX_HOOKS; n++) {
 | 
			
		||||
        if (tick_cb[n]==old_tick_cb) tick_cb[n]=NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -25,6 +25,7 @@
 | 
			
		||||
#include "soc/io_mux_reg.h"
 | 
			
		||||
 | 
			
		||||
#include "esp_gdbstub.h"
 | 
			
		||||
#include "driver/gpio.h"
 | 
			
		||||
 | 
			
		||||
//Length of buffer used to reserve GDB commands. Has to be at least able to fit the G command, which
 | 
			
		||||
//implies a minimum size of about 320 bytes.
 | 
			
		||||
@@ -354,7 +355,7 @@ static int gdbReadCommand() {
 | 
			
		||||
void esp_gdbstub_panic_handler(XtExcFrame *frame) {
 | 
			
		||||
	dumpHwToRegfile(frame);
 | 
			
		||||
	//Make sure txd/rxd are enabled
 | 
			
		||||
	PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
 | 
			
		||||
	gpio_pullup_dis(1);
 | 
			
		||||
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_U0RXD);
 | 
			
		||||
	PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_U0TXD);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,10 @@
 | 
			
		||||
// Forces data into DRAM instead of flash
 | 
			
		||||
#define DRAM_ATTR __attribute__((section(".dram1")))
 | 
			
		||||
 | 
			
		||||
// Forces a string into DRAM instrad of flash
 | 
			
		||||
// Use as ets_printf(DRAM_STR("Hello world!\n"));
 | 
			
		||||
#define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;}))
 | 
			
		||||
 | 
			
		||||
// Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst"
 | 
			
		||||
#define RTC_IRAM_ATTR __attribute__((section(".rtc.text")))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										83
									
								
								components/esp32/include/esp_freertos_hooks.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								components/esp32/include/esp_freertos_hooks.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,83 @@
 | 
			
		||||
// 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_FREERTOS_HOOKS_H__
 | 
			
		||||
#define __ESP_FREERTOS_HOOKS_H__
 | 
			
		||||
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include "esp_err.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C"
 | 
			
		||||
{
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 Definitions for the tickhook and idlehook callbacks
 | 
			
		||||
*/
 | 
			
		||||
typedef bool (*esp_freertos_idle_cb_t)();
 | 
			
		||||
typedef void (*esp_freertos_tick_cb_t)();
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Register a callback to be called on the freertos idle hook
 | 
			
		||||
  *         The callback should return true if it's okay for the core to
 | 
			
		||||
  *         sleep until an interrupt (or FreeRTOS tick) happens and false
 | 
			
		||||
  *         if it should be called again as fast as possible.
 | 
			
		||||
  *
 | 
			
		||||
  * @warning Idle callbacks MUST NOT, UNDER ANY CIRCUMSTANCES, CALL 
 | 
			
		||||
  *          A FUNCTION THAT MIGHT BLOCK.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  esp_freertos_idle_cb_t new_idle_cb : Callback to be called
 | 
			
		||||
  *
 | 
			
		||||
  * @return ESP_OK : Callback registered
 | 
			
		||||
  * @return ESP_ERR_NO_MEM : No more space to register hook
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_register_freertos_idle_hook(esp_freertos_idle_cb_t new_idle_cb);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Register a callback to be called on the freertos tick hook
 | 
			
		||||
  *
 | 
			
		||||
  * @param  esp_freertos_tick_cb_t new_tick_cb : Callback to be called
 | 
			
		||||
  *
 | 
			
		||||
  * @return ESP_OK : Callback registered
 | 
			
		||||
  * @return ESP_ERR_NO_MEM : No more space to register hook
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_register_freertos_tick_hook(esp_freertos_tick_cb_t tick_cb);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Unregister an idle callback registered earlier
 | 
			
		||||
  *
 | 
			
		||||
  * @param  esp_freertos_idle_cb_t new_idle_cb : Callback to be unregistered
 | 
			
		||||
  *
 | 
			
		||||
  * @return void
 | 
			
		||||
  */
 | 
			
		||||
void esp_deregister_freertos_idle_hook(esp_freertos_idle_cb_t old_idle_cb);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Unregister a tick callback registered earlier
 | 
			
		||||
  *
 | 
			
		||||
  * @param  esp_freertos_idle_cb_t new_idle_cb : Callback to be unregistered
 | 
			
		||||
  *
 | 
			
		||||
  * @return void
 | 
			
		||||
  */
 | 
			
		||||
void esp_deregister_freertos_tick_hook(esp_freertos_tick_cb_t old_tick_cb);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@@ -41,9 +41,6 @@ This uses the TIMERG1 WDT.
 | 
			
		||||
  * @brief  Initialize the interrupt watchdog. This is called in the init code if
 | 
			
		||||
  *         the interrupt watchdog is enabled in menuconfig.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  null
 | 
			
		||||
  *
 | 
			
		||||
  * @return null
 | 
			
		||||
  */
 | 
			
		||||
void esp_int_wdt_init();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										249
									
								
								components/esp32/include/esp_phy_init.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										249
									
								
								components/esp32/include/esp_phy_init.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,249 @@
 | 
			
		||||
// 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.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include "esp_err.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file PHY init parameters and API
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Structure holding PHY init parameters
 | 
			
		||||
 */
 | 
			
		||||
typedef struct {
 | 
			
		||||
	uint8_t param_ver_id;                   /*!< init_data structure version */
 | 
			
		||||
	uint8_t crystal_select;                 /*!< 0: 40MHz, 1: 26 MHz, 2: 24 MHz, 3: auto */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_1;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_2;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_3;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_4;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_5;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_6;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_7;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_8;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_9;        /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_10;       /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_11;       /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_12;       /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_13;       /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_14;       /*!< do not change */
 | 
			
		||||
	uint8_t wifi_rx_gain_swp_step_15;       /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_1;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_2;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_3;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_4;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_5;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_6;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_7;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_8;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_9;          /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_10;         /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_11;         /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_12;         /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_13;         /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_14;         /*!< do not change */
 | 
			
		||||
	uint8_t bt_rx_gain_swp_step_15;         /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_1;                     /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_6;                     /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_11;                    /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_ext2_1;                /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_ext2_6;                /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_ext2_11;               /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_ext3_1;                /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_ext3_6;                /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_ext3_11;               /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_bt_ofs_1;              /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_bt_ofs_6;              /*!< do not change */
 | 
			
		||||
	uint8_t gain_cmp_bt_ofs_11;             /*!< do not change */
 | 
			
		||||
	uint8_t target_power_qdb_0;             /*!< 78 means target power is 78/4=19.5dbm */
 | 
			
		||||
	uint8_t target_power_qdb_1;             /*!< 76 means target power is 76/4=19dbm */
 | 
			
		||||
	uint8_t target_power_qdb_2;             /*!< 74 means target power is 74/4=18.5dbm */
 | 
			
		||||
	uint8_t target_power_qdb_3;             /*!< 68 means target power is 68/4=17dbm */
 | 
			
		||||
	uint8_t target_power_qdb_4;             /*!< 64 means target power is 64/4=16dbm */
 | 
			
		||||
	uint8_t target_power_qdb_5;             /*!< 52 means target power is 52/4=13dbm */
 | 
			
		||||
	uint8_t target_power_index_mcs0;        /*!< target power index is 0, means target power is target_power_qdb_0 19.5dbm;  (1m,2m,5.5m,11m,6m,9m) */
 | 
			
		||||
	uint8_t target_power_index_mcs1;        /*!< target power index is 0, means target power is target_power_qdb_0 19.5dbm;  (12m) */
 | 
			
		||||
	uint8_t target_power_index_mcs2;        /*!< target power index is 1, means target power is target_power_qdb_1 19dbm;    (18m) */
 | 
			
		||||
	uint8_t target_power_index_mcs3;        /*!< target power index is 1, means target power is target_power_qdb_1 19dbm;    (24m) */
 | 
			
		||||
	uint8_t target_power_index_mcs4;        /*!< target power index is 2, means target power is target_power_qdb_2 18.5dbm;  (36m) */
 | 
			
		||||
	uint8_t target_power_index_mcs5;        /*!< target power index is 3, means target power is target_power_qdb_3 17dbm;    (48m) */
 | 
			
		||||
	uint8_t target_power_index_mcs6;        /*!< target power index is 4, means target power is target_power_qdb_4 16dbm;    (54m) */
 | 
			
		||||
	uint8_t target_power_index_mcs7;        /*!< target power index is 5, means target power is target_power_qdb_5 13dbm */
 | 
			
		||||
	uint8_t pwr_ind_11b_en;                 /*!< 0: 11b power is same as mcs0 and 6m, 1: 11b power different with OFDM */
 | 
			
		||||
	uint8_t pwr_ind_11b_0;                  /*!< 1m, 2m power index [0~5] */
 | 
			
		||||
	uint8_t pwr_ind_11b_1;                  /*!< 5.5m, 11m power index [0~5] */
 | 
			
		||||
	uint8_t chan_backoff_en;                /*!< 0: channel backoff disable, 1:channel backoff enable */
 | 
			
		||||
	uint8_t chan1_power_backoff_qdb;        /*!< 4 means backoff is 1db */
 | 
			
		||||
	uint8_t chan2_power_backoff_qdb;        /*!< see chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan3_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan4_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan5_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan6_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan7_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan8_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan9_power_backoff_qdb;        /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan10_power_backoff_qdb;       /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan11_power_backoff_qdb;       /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan12_power_backoff_qdb;       /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan13_power_backoff_qdb;       /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan14_power_backoff_qdb;       /*!< chan1_power_backoff_qdb */
 | 
			
		||||
	uint8_t chan1_rate_backoff_index;       /*!< if bit i is set, backoff data rate is target_power_qdb_i */
 | 
			
		||||
	uint8_t chan2_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan3_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan4_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan5_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan6_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan7_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan8_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan9_rate_backoff_index;       /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan10_rate_backoff_index;      /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan11_rate_backoff_index;      /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan12_rate_backoff_index;      /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan13_rate_backoff_index;      /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t chan14_rate_backoff_index;      /*!< see chan1_rate_backoff_index */
 | 
			
		||||
	uint8_t spur_freq_cfg_msb_1;            /*!< first spur: */
 | 
			
		||||
	uint8_t spur_freq_cfg_1;                /*!< spur_freq_cfg = (spur_freq_cfg_msb_1 <<8) | spur_freq_cfg_1 */
 | 
			
		||||
	uint8_t spur_freq_cfg_div_1;            /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_1 */
 | 
			
		||||
	uint8_t spur_freq_en_h_1;               /*!< the seventh bit for total enable */
 | 
			
		||||
	uint8_t spur_freq_en_l_1;               /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority */
 | 
			
		||||
	uint8_t spur_freq_cfg_msb_2;            /*!< second spur: */
 | 
			
		||||
	uint8_t spur_freq_cfg_2;                /*!< spur_freq_cfg = (spur_freq_cfg_msb_2 <<8) | spur_freq_cfg_2 */
 | 
			
		||||
	uint8_t spur_freq_cfg_div_2;            /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_2 */
 | 
			
		||||
	uint8_t spur_freq_en_h_2;               /*!< the seventh bit for total enable */
 | 
			
		||||
	uint8_t spur_freq_en_l_2;               /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority */
 | 
			
		||||
	uint8_t spur_freq_cfg_msb_3;            /*!< third spur: */
 | 
			
		||||
	uint8_t spur_freq_cfg_3;                /*!< spur_freq_cfg = (spur_freq_cfg_msb_3 <<8) | spur_freq_cfg_3 */
 | 
			
		||||
	uint8_t spur_freq_cfg_div_3;            /*!< spur_freq=spur_freq_cfg/spur_freq_cfg_div_3 */
 | 
			
		||||
	uint8_t spur_freq_en_h_3;               /*!< the seventh bit for total enable */
 | 
			
		||||
	uint8_t spur_freq_en_l_3;               /*!< each bit for 1 channel, and use [spur_freq_en_h, spur_freq_en_l] to select the spur's channel priority, */
 | 
			
		||||
	uint8_t reserved[23];                   /*!< reserved for future expansion */
 | 
			
		||||
} esp_phy_init_data_t;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Opaque PHY calibration data
 | 
			
		||||
 */
 | 
			
		||||
typedef struct {
 | 
			
		||||
    uint8_t opaque[1904];                   /*!< calibration data */
 | 
			
		||||
} esp_phy_calibration_data_t;
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    PHY_RF_CAL_PARTIAL = 0x00000000,        /*!< Do part of RF calibration. This should be used after power-on reset. */
 | 
			
		||||
    PHY_RF_CAL_NONE    = 0x00000001,        /*!< Don't do any RF calibration. This mode is only suggested to be used after deep sleep reset. */
 | 
			
		||||
    PHY_RF_CAL_FULL    = 0x00000002         /*!< Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once. */
 | 
			
		||||
} esp_phy_calibration_mode_t;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Get PHY init data
 | 
			
		||||
 *
 | 
			
		||||
 * If "Use a partition to store PHY init data" option is set in menuconfig,
 | 
			
		||||
 * This function will load PHY init data from a partition. Otherwise,
 | 
			
		||||
 * PHY init data will be compiled into the application itself, and this function
 | 
			
		||||
 * will return a pointer to PHY init data located in read-only memory (DROM).
 | 
			
		||||
 *
 | 
			
		||||
 * If "Use a partition to store PHY init data" option is enabled, this function
 | 
			
		||||
 * may return NULL if the data loaded from flash is not valid.
 | 
			
		||||
 *
 | 
			
		||||
 * @note Call esp_phy_release_init_data to release the pointer obtained using
 | 
			
		||||
 * this function after the call to esp_wifi_init.
 | 
			
		||||
 *
 | 
			
		||||
 * @return pointer to PHY init data structure
 | 
			
		||||
 */
 | 
			
		||||
const esp_phy_init_data_t* esp_phy_get_init_data();
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Release PHY init data
 | 
			
		||||
 * @param data  pointer to PHY init data structure obtained from
 | 
			
		||||
 *              esp_phy_get_init_data function
 | 
			
		||||
 */
 | 
			
		||||
void esp_phy_release_init_data(const esp_phy_init_data_t* data);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function called by esp_phy_init to load PHY calibration data
 | 
			
		||||
 *
 | 
			
		||||
 * This is a convenience function which can be used to load PHY calibration
 | 
			
		||||
 * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
 | 
			
		||||
 * function.
 | 
			
		||||
 *
 | 
			
		||||
 * If calibration data is not present in the NVS, or
 | 
			
		||||
 * data is not valid (was obtained for a chip with a different MAC address,
 | 
			
		||||
 * or obtained for a different version of software), this function will
 | 
			
		||||
 * return an error.
 | 
			
		||||
 *
 | 
			
		||||
 * If "Initialize PHY in startup code" option is set in menuconfig, this
 | 
			
		||||
 * function will be used to load calibration data. To provide a different
 | 
			
		||||
 * mechanism for loading calibration data, disable
 | 
			
		||||
 * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
 | 
			
		||||
 * function from the application. For an example usage of esp_phy_init and
 | 
			
		||||
 * this function, see do_phy_init function in cpu_start.c
 | 
			
		||||
 *
 | 
			
		||||
 * @param out_cal_data pointer to calibration data structure to be filled with
 | 
			
		||||
 *                     loaded data.
 | 
			
		||||
 * @return ESP_OK on success
 | 
			
		||||
 */
 | 
			
		||||
esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Function called by esp_phy_init to store PHY calibration data
 | 
			
		||||
 *
 | 
			
		||||
 * This is a convenience function which can be used to store PHY calibration
 | 
			
		||||
 * data to the NVS. Calibration data is returned by esp_phy_init function.
 | 
			
		||||
 * Data saved using this function to the NVS can later be loaded using
 | 
			
		||||
 * esp_phy_store_cal_data_to_nvs function.
 | 
			
		||||
 *
 | 
			
		||||
 * If "Initialize PHY in startup code" option is set in menuconfig, this
 | 
			
		||||
 * function will be used to store calibration data. To provide a different
 | 
			
		||||
 * mechanism for storing calibration data, disable
 | 
			
		||||
 * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
 | 
			
		||||
 * function from the application.
 | 
			
		||||
 *
 | 
			
		||||
 * @param cal_data pointer to calibration data which has to be saved.
 | 
			
		||||
 * @return ESP_OK on success
 | 
			
		||||
 */
 | 
			
		||||
esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Initialize PHY module
 | 
			
		||||
 *
 | 
			
		||||
 * PHY module should be initialized in order to use WiFi or BT.
 | 
			
		||||
 * If "Initialize PHY in startup code" option is set in menuconfig,
 | 
			
		||||
 * this function will be called automatically before app_main is called,
 | 
			
		||||
 * using parameters obtained from esp_phy_get_init_data.
 | 
			
		||||
 *
 | 
			
		||||
 * Applications which don't need to enable PHY on every start up should
 | 
			
		||||
 * disable this menuconfig option and call esp_phy_init before calling
 | 
			
		||||
 * esp_wifi_init or bt_controller_init. See do_phy_init function in
 | 
			
		||||
 * cpu_start.c for an example of using this function.
 | 
			
		||||
 *
 | 
			
		||||
 * @param init_data  PHY parameters. Default set of parameters can
 | 
			
		||||
 *                   be obtained by calling esp_phy_get_default_init_data
 | 
			
		||||
 *                   function.
 | 
			
		||||
 * @param mode  Calibration mode (Full, partial, or no calibration)
 | 
			
		||||
 * @param[inout] calibration_data
 | 
			
		||||
 * @return ESP_OK on success.
 | 
			
		||||
 */
 | 
			
		||||
esp_err_t esp_phy_init(const esp_phy_init_data_t* init_data,
 | 
			
		||||
        esp_phy_calibration_mode_t mode, esp_phy_calibration_data_t* calibration_data);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
@@ -42,9 +42,6 @@ This uses the TIMERG0 WDT.
 | 
			
		||||
  * @brief  Initialize the task watchdog. This is called in the init code, if the
 | 
			
		||||
  *         task watchdog is enabled in menuconfig.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  null
 | 
			
		||||
  *
 | 
			
		||||
  * @return null
 | 
			
		||||
  */
 | 
			
		||||
void esp_task_wdt_init();
 | 
			
		||||
 | 
			
		||||
@@ -52,9 +49,6 @@ void esp_task_wdt_init();
 | 
			
		||||
  * @brief  Feed the watchdog. After the first feeding session, the watchdog will expect the calling
 | 
			
		||||
  *         task to keep feeding the watchdog until task_wdt_delete() is called.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  null
 | 
			
		||||
  *
 | 
			
		||||
  * @return null
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
void esp_task_wdt_feed();
 | 
			
		||||
@@ -63,9 +57,6 @@ void esp_task_wdt_feed();
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Delete the watchdog for the current task.
 | 
			
		||||
  *
 | 
			
		||||
  * @param  null
 | 
			
		||||
  *
 | 
			
		||||
  * @return null
 | 
			
		||||
  */
 | 
			
		||||
void esp_task_wdt_delete();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -88,6 +88,9 @@ extern "C" {
 | 
			
		||||
#define ESP_ERR_WIFI_PASSWORD    (ESP_ERR_WIFI_BASE + 10)  /*!< Passord is invalid */
 | 
			
		||||
#define ESP_ERR_WIFI_TIMEOUT     (ESP_ERR_WIFI_BASE + 11)  /*!< Timeout error */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief WiFi stack configuration parameters passed to esp_wifi_init call.
 | 
			
		||||
 */
 | 
			
		||||
typedef struct {
 | 
			
		||||
    system_event_handler_t event_handler;  /**< WiFi event handler */
 | 
			
		||||
} wifi_init_config_t;
 | 
			
		||||
@@ -108,12 +111,12 @@ typedef struct {
 | 
			
		||||
  *               will post station connected event to this queue. If the queue is not initialized, WiFi
 | 
			
		||||
  *               will not post any events
 | 
			
		||||
  *
 | 
			
		||||
  * @param  wifi_init_config_t *config : provide WiFi init configuration
 | 
			
		||||
  * @param  config provide WiFi init configuration
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM : out of memory
 | 
			
		||||
  *    - others : refer to error code esp_err.h 
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM: out of memory
 | 
			
		||||
  *    - others: refer to error code esp_err.h 
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_init(wifi_init_config_t *config);
 | 
			
		||||
 | 
			
		||||
@@ -123,7 +126,7 @@ esp_err_t esp_wifi_init(wifi_init_config_t *config);
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. This API should be called if you want to remove WiFi driver from the system
 | 
			
		||||
  *
 | 
			
		||||
  * @return ESP_OK : succeed
 | 
			
		||||
  * @return ESP_OK: succeed
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_deinit(void);
 | 
			
		||||
 | 
			
		||||
@@ -133,25 +136,25 @@ esp_err_t esp_wifi_deinit(void);
 | 
			
		||||
  *            Set the WiFi operating mode as station, soft-AP or station+soft-AP,
 | 
			
		||||
  *            The default mode is soft-AP mode.
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_mode_t mode : WiFi operating modes:
 | 
			
		||||
  * @param     mode  WiFi operating mode
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - others: refer to error code in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_mode(wifi_mode_t mode);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Get current operating mode of WiFi
 | 
			
		||||
  *
 | 
			
		||||
  * @param  wifi_mode_t *mode : store current WiFi mode
 | 
			
		||||
  * @param[out]  mode  store current WiFi mode
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);
 | 
			
		||||
 | 
			
		||||
@@ -161,29 +164,25 @@ esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);
 | 
			
		||||
  *         If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP
 | 
			
		||||
  *         If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station
 | 
			
		||||
  *
 | 
			
		||||
  * @param  null
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM : out of memory
 | 
			
		||||
  *    - ESP_ERR_WIFI_CONN : WiFi internal error, station or soft-AP control block wrong
 | 
			
		||||
  *    - ESP_ERR_WIFI_FAIL : other WiFi internal errors
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM: out of memory
 | 
			
		||||
  *    - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
 | 
			
		||||
  *    - ESP_ERR_WIFI_FAIL: other WiFi internal errors
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_start(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief  Stop WiFi
 | 
			
		||||
            If mode is WIFI_MODE_STA, it stop station and free station control block
 | 
			
		||||
  *         If mode is WIFI_MODE_STA, it stop station and free station control block
 | 
			
		||||
  *         If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block
 | 
			
		||||
  *         If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block
 | 
			
		||||
  *
 | 
			
		||||
  * @param  null
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_stop(void);
 | 
			
		||||
 | 
			
		||||
@@ -193,52 +192,47 @@ esp_err_t esp_wifi_stop(void);
 | 
			
		||||
  * @attention 1. This API only impact WIFI_MODE_STA or WIFI_MODE_APSTA mode
 | 
			
		||||
  * @attention 2. If the ESP32 is connected to an AP, call esp_wifi_disconnect to disconnect.
 | 
			
		||||
  *
 | 
			
		||||
  * @param     null
 | 
			
		||||
  *
 | 
			
		||||
  * @return 
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_CONN : WiFi internal error, station or soft-AP control block wrong
 | 
			
		||||
  *    - ESP_ERR_WIFI_SSID : SSID of AP which station connects is invalid
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong
 | 
			
		||||
  *    - ESP_ERR_WIFI_SSID: SSID of AP which station connects is invalid
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_connect(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Disconnect the ESP32 WiFi station from the AP.
 | 
			
		||||
  *
 | 
			
		||||
  * @param     null
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_FAIL : other WiFi internal errors
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_FAIL: other WiFi internal errors
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_disconnect(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Currently this API is just an stub API
 | 
			
		||||
  *
 | 
			
		||||
  * @param     null
 | 
			
		||||
  *
 | 
			
		||||
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - others : fail
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - others: fail
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_clear_fast_connect(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     deauthenticate all stations or associated id equals to aid
 | 
			
		||||
  *
 | 
			
		||||
  * @param     uint16_t aid : when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid
 | 
			
		||||
  * @param     aid  when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE : WiFi mode is wrong
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE: WiFi mode is wrong
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_deauth_sta(uint16_t aid);
 | 
			
		||||
 | 
			
		||||
@@ -249,88 +243,87 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid);
 | 
			
		||||
  *            will be freed in esp_wifi_get_ap_list, so generally, call esp_wifi_get_ap_list to cause
 | 
			
		||||
  *            the memory to be freed once the scan is done
 | 
			
		||||
  *
 | 
			
		||||
  * @param     struct scan_config *config : configuration of scanning
 | 
			
		||||
  * @param     bool block : if block is true, this API will block the caller until the scan is done, otherwise
 | 
			
		||||
  * @param     config  configuration of scanning
 | 
			
		||||
  * @param     block if block is true, this API will block the caller until the scan is done, otherwise
 | 
			
		||||
  *                         it will return immediately
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_TIMEOUT : blocking scan is timeout
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout
 | 
			
		||||
  *    - others: refer to error code in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_scan_start(wifi_scan_config_t *conf, bool block);
 | 
			
		||||
esp_err_t esp_wifi_scan_start(wifi_scan_config_t *config, bool block);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Stop the scan in process
 | 
			
		||||
  *
 | 
			
		||||
  * @param     null
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_scan_stop(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get number of APs found in last scan
 | 
			
		||||
  *
 | 
			
		||||
  * @param     uint16_t *number : store number of APIs found in last scan
 | 
			
		||||
  * @param[out] number  store number of APIs found in last scan
 | 
			
		||||
  *
 | 
			
		||||
  * @attention This API can only be called when the scan is completed, otherwise it may get wrong value
 | 
			
		||||
  * @attention This API can only be called when the scan is completed, otherwise it may get wrong value.
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get AP list found in last scan
 | 
			
		||||
  *
 | 
			
		||||
  * @param     uint16_t *number : as input param, it stores max AP number ap_records can hold, as output param, it store
 | 
			
		||||
                                  the actual AP number this API returns
 | 
			
		||||
  * @param     wifi_ap_record_t *ap_records: wifi_ap_record_t array to hold the found APs
 | 
			
		||||
  * @param[inout]  number As input param, it stores max AP number ap_records can hold. 
 | 
			
		||||
  *                As output param, it receives the actual AP number this API returns.
 | 
			
		||||
  * @param         ap_records  wifi_ap_record_t array to hold the found APs
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM : out of memory
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM: out of memory
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get information of AP associated with ESP32 station
 | 
			
		||||
  * @brief     Get information of AP which the ESP32 station is associated with
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_ap_record_t *ap_info: the wifi_ap_record_t to hold station assocated AP
 | 
			
		||||
  * @param     ap_info  the wifi_ap_record_t to hold AP information
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - others : fail
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - others: fail
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Set current power save type
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_ps_type_t type : power save type
 | 
			
		||||
  * @param     type  power save type
 | 
			
		||||
  *
 | 
			
		||||
  * @return    ESP_ERR_WIFI_NOT_SUPPORT : not support yet
 | 
			
		||||
  * @return    ESP_ERR_WIFI_NOT_SUPPORT: not supported yet
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_ps(wifi_ps_type_t type);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get current power save type
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_ps_type_t *type : store current power save type
 | 
			
		||||
  * @param[out]  type: store current power save type
 | 
			
		||||
  *
 | 
			
		||||
  * @return    ESP_ERR_WIFI_NOT_SUPPORT : not support yet
 | 
			
		||||
  * @return    ESP_ERR_WIFI_NOT_SUPPORT: not supported yet
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type);
 | 
			
		||||
 | 
			
		||||
@@ -340,47 +333,47 @@ esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type);
 | 
			
		||||
  *
 | 
			
		||||
  * @attention Currently we only support 802.11b or 802.11bg or 802.11bgn mode
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interfaces
 | 
			
		||||
  * @param     uint8_t protocol : WiFi protocol bitmap
 | 
			
		||||
  * @param     ifx  interfaces
 | 
			
		||||
  * @param     protocol_bitmap  WiFi protocol bitmap
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - others : refer to erro code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - others: refer to error codes in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get the current protocol bitmap of specified ifx
 | 
			
		||||
  * @brief     Get the current protocol bitmap of the specified interface
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interfaces
 | 
			
		||||
  * @param     uint8_t protocol : store current WiFi protocol bitmap of interface ifx
 | 
			
		||||
  * @param     ifx  interface
 | 
			
		||||
  * @param[out] protocol_bitmap  store current WiFi protocol bitmap of interface ifx
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - others: refer to error codes in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Set the bandwidth of ESP32 specified interface
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. API return false if try to configure a interface that is not enable
 | 
			
		||||
  * @attention 1. API return false if try to configure an interface that is not enabled
 | 
			
		||||
  * @attention 2. WIFI_BW_HT40 is supported only when the interface support 11N
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interface to be configured
 | 
			
		||||
  * @param     wifi_bandwidth_t bw : bandwidth
 | 
			
		||||
  * @param     ifx  interface to be configured
 | 
			
		||||
  * @param     bw  bandwidth
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - others: refer to error codes in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw);
 | 
			
		||||
 | 
			
		||||
@@ -389,45 +382,45 @@ esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw);
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. API return false if try to get a interface that is not enable
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interface to be configured
 | 
			
		||||
  * @param     wifi_bandwidth_t *bw : store bandwidth  of interface ifx
 | 
			
		||||
  * @param     ifx interface to be configured
 | 
			
		||||
  * @param[out] bw  store bandwidth of interface ifx
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Set primary/second channel of ESP32
 | 
			
		||||
  * @brief     Set primary/secondary channel of ESP32
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. This is a special API for sniffer
 | 
			
		||||
  *
 | 
			
		||||
  * @param     uint8_t primary : for HT20, primary is the channel number, for HT40, primary is the primary channel
 | 
			
		||||
  * @param     wifi_second_chan_t second : for HT20, second is ignored, for HT40, second is the second channel
 | 
			
		||||
  * @param     primary  for HT20, primary is the channel number, for HT40, primary is the primary channel
 | 
			
		||||
  * @param     second   for HT20, second is ignored, for HT40, second is the second channel
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get the primary/second channel of ESP32
 | 
			
		||||
  * @brief     Get the primary/secondary channel of ESP32
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. API return false if try to get a interface that is not enable
 | 
			
		||||
  *
 | 
			
		||||
  * @param     uint8_t *primary : store current primary channel
 | 
			
		||||
  * @param     wifi_second_chan_t *second : store current second channel
 | 
			
		||||
  * @param     primary   store current primary channel
 | 
			
		||||
  * @param[out]  second  store current second channel
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
 | 
			
		||||
 | 
			
		||||
@@ -435,25 +428,25 @@ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
 | 
			
		||||
  * @brief     Set country code
 | 
			
		||||
  *            The default value is WIFI_COUNTRY_CN
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_country_t country : country type
 | 
			
		||||
  * @param     country  country type
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - others: refer to error code in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_country(wifi_country_t country);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get country code
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_country_t country : store current country
 | 
			
		||||
  * @param     country  store current country
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_country(wifi_country_t *country);
 | 
			
		||||
 | 
			
		||||
@@ -462,43 +455,44 @@ esp_err_t esp_wifi_get_country(wifi_country_t *country);
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. This API can only be called when the interface is disabled
 | 
			
		||||
  * @attention 2. ESP32 soft-AP and station have different MAC addresses, do not set them to be the same.
 | 
			
		||||
  *    - The bit0 of the first byte of ESP32 MAC address can not be 1. For example, the MAC address
 | 
			
		||||
  * @attention 3. The bit 0 of the first byte of ESP32 MAC address can not be 1. For example, the MAC address
 | 
			
		||||
  *      can set to be "1a:XX:XX:XX:XX:XX", but can not be "15:XX:XX:XX:XX:XX".
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interface
 | 
			
		||||
  * @param     uint8 mac[6]: the MAC address.
 | 
			
		||||
  * @param     ifx  interface
 | 
			
		||||
  * @param     mac  the MAC address
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_MAC : invalid mac address
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE : WiFi mode is wrong
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_MAC: invalid mac address
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE: WiFi mode is wrong
 | 
			
		||||
  *    - others: refer to error codes in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, uint8_t mac[6]);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get mac of specified interface
 | 
			
		||||
  *
 | 
			
		||||
  * @param     uint8_t mac[6] : store mac of this interface ifx
 | 
			
		||||
  * @param      ifx  interface
 | 
			
		||||
  * @param[out] mac  store mac of the interface ifx
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief The RX callback function in the promiscuous mode.
 | 
			
		||||
  *
 | 
			
		||||
  *        Each time a packet is received, the callback function will be called.
 | 
			
		||||
  * Each time a packet is received, the callback function will be called.
 | 
			
		||||
  *
 | 
			
		||||
  * @param void *buf : the data received
 | 
			
		||||
  * @param uint16_t len : data length
 | 
			
		||||
  * @param buf  the data received
 | 
			
		||||
  * @param len  data length
 | 
			
		||||
  *
 | 
			
		||||
  * @return    none
 | 
			
		||||
  */
 | 
			
		||||
@@ -507,36 +501,36 @@ typedef void (* wifi_promiscuous_cb_t)(void *buf, uint16_t len);
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Register the RX callback function in the promiscuous mode.
 | 
			
		||||
  *
 | 
			
		||||
  *        Each time a packet is received, the registered callback function will be called.
 | 
			
		||||
  * Each time a packet is received, the registered callback function will be called.
 | 
			
		||||
  *
 | 
			
		||||
  * @param wifi_promiscuous_cb_t cb : callback
 | 
			
		||||
  * @param cb  callback
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Enable the promiscuous mode.
 | 
			
		||||
  *
 | 
			
		||||
  * @param     bool promiscuous : false - disable / true - enable
 | 
			
		||||
  * @param     en  false - disable, true - enable
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_promiscuous(bool en);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get the promiscuous mode.
 | 
			
		||||
  *
 | 
			
		||||
  * @param     bool *enable : store the current status of promiscuous mode
 | 
			
		||||
  * @param[out] en  store the current status of promiscuous mode
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT  : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_promiscuous(bool *en);
 | 
			
		||||
 | 
			
		||||
@@ -548,32 +542,32 @@ esp_err_t esp_wifi_get_promiscuous(bool *en);
 | 
			
		||||
  * @attention 3. ESP32 is limited to only one channel, so when in the soft-AP+station mode, the soft-AP will adjust its channel automatically to be the same as
 | 
			
		||||
  *               the channel of the ESP32 station.
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interface
 | 
			
		||||
  * @param     wifi_config_t *conf : station or soft-AP configuration
 | 
			
		||||
  * @param     ifx  interface
 | 
			
		||||
  * @param     conf  station or soft-AP configuration
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE : invalid mode
 | 
			
		||||
  *    - ESP_ERR_WIFI_PASSWORD : invalid password
 | 
			
		||||
  *    - ESP_ERR_WIFI_NVS : WiFi internal NVS error
 | 
			
		||||
  *    - others : refer to the erro code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE: invalid mode
 | 
			
		||||
  *    - ESP_ERR_WIFI_PASSWORD: invalid password
 | 
			
		||||
  *    - ESP_ERR_WIFI_NVS: WiFi internal NVS error
 | 
			
		||||
  *    - others: refer to the erro code in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get configuration of specified interface
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_interface_t ifx : interface
 | 
			
		||||
  * @param     wifi_config_t *conf : station or soft-AP configuration
 | 
			
		||||
  * @param     ifx  interface
 | 
			
		||||
  * @param[out]  conf  station or soft-AP configuration
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF : invalid interface
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_IF: invalid interface
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf);
 | 
			
		||||
 | 
			
		||||
@@ -582,14 +576,14 @@ esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf);
 | 
			
		||||
  *
 | 
			
		||||
  * @attention SSC only API
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_sta_list_t *sta:  station list
 | 
			
		||||
  * @param[out] sta  station list
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE : WiFi mode is wrong
 | 
			
		||||
  *    - ESP_ERR_WIFI_CONN : WiFi internal error, the station/soft-AP control block is invalid
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE: WiFi mode is wrong
 | 
			
		||||
  *    - ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
 | 
			
		||||
 | 
			
		||||
@@ -599,12 +593,12 @@ esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta);
 | 
			
		||||
  *
 | 
			
		||||
  * @attention 1. The default value is WIFI_STORAGE_FLASH
 | 
			
		||||
  *
 | 
			
		||||
  * @param     wifi_storage_t storage : storage type
 | 
			
		||||
  * @param     storage : storage type
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *   - ESP_OK : succeed
 | 
			
		||||
  *   - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *   - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *   - ESP_OK: succeed
 | 
			
		||||
  *   - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *   - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
 | 
			
		||||
 | 
			
		||||
@@ -612,72 +606,63 @@ esp_err_t esp_wifi_set_storage(wifi_storage_t storage);
 | 
			
		||||
  * @brief     Set auto connect
 | 
			
		||||
  *            The default value is true
 | 
			
		||||
  *
 | 
			
		||||
  * @param     bool en : true - enable auto connect / false - disable auto connect
 | 
			
		||||
  * @param     en : true - enable auto connect / false - disable auto connect
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE : WiFi internal error, the station/soft-AP control block is invalid
 | 
			
		||||
  *    - others : refer to error code in esp_err.h
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_MODE: WiFi internal error, the station/soft-AP control block is invalid
 | 
			
		||||
  *    - others: refer to error code in esp_err.h
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_auto_connect(bool en);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Get the auto connect flag
 | 
			
		||||
  *
 | 
			
		||||
  * @param     bool *en : store current auto connect configuration
 | 
			
		||||
  * @param[out] en  store current auto connect configuration
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_get_auto_connect(bool *en);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Set vendor specific element
 | 
			
		||||
  *
 | 
			
		||||
  * @param     bool enable : enable or not
 | 
			
		||||
  * @param     wifi_vendor_ie_type_t type : 0 - WIFI_VND_IE_TYPE_BEACON
 | 
			
		||||
  *                           1 - WIFI_VND_IE_TYPE_PROBE_REQ
 | 
			
		||||
  *                           2 - WIFI_VND_IE_TYPE_PROBE_RESP
 | 
			
		||||
  *                           3 - WIFI_VND_IE_TYPE_ASSOC_REQ
 | 
			
		||||
  *                           4 - WIFI_VND_IE_TYPE_ASSOC_RESP
 | 
			
		||||
  * @param     wifi_vendor_ie_id_t idx : 0 - WIFI_VND_IE_ID_0
 | 
			
		||||
                                    1 - WIFI_VND_IE_ID_1
 | 
			
		||||
  * @param     uint8_t *vnd_ie : pointer to a vendor specific element
 | 
			
		||||
  * @param     enable  enable or not
 | 
			
		||||
  * @param     type  information element type
 | 
			
		||||
  * @param     idx  information element index
 | 
			
		||||
  * @param     vnd_ie  pointer to a vendor specific element
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG : invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM : out of memory
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_ERR_WIFI_ARG: invalid argument
 | 
			
		||||
  *    - ESP_ERR_WIFI_NO_MEM: out of memory
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, uint8_t *vnd_ie);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Define function pointer for vendor specific element callback
 | 
			
		||||
  * @param     void *ctx : reserved
 | 
			
		||||
  * @param     wifi_vendor_ie_type_t type : 0 - WIFI_VND_IE_TYPE_BEACON
 | 
			
		||||
  *                           1 - WIFI_VND_IE_TYPE_PROBE_REQ
 | 
			
		||||
  *                           2 - WIFI_VND_IE_TYPE_PROBE_RESP
 | 
			
		||||
  *                           3 - WIFI_VND_IE_TYPE_ASSOC_REQ
 | 
			
		||||
  *                           4 - WIFI_VND_IE_TYPE_ASSOC_RESP
 | 
			
		||||
  * @param     const uint8_t sa[6] : source address
 | 
			
		||||
  * @param     const uint8_t *vnd_ie : pointer to a vendor specific element
 | 
			
		||||
  * @param     int rssi : received signal strength indication
 | 
			
		||||
  * @param     ctx  reserved
 | 
			
		||||
  * @param     type  information element type 
 | 
			
		||||
  * @param     sa  source address
 | 
			
		||||
  * @param     vnd_ie  pointer to a vendor specific element
 | 
			
		||||
  * @param     rssi  received signal strength indication
 | 
			
		||||
  */
 | 
			
		||||
typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const uint8_t *vnd_ie, int rssi);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief     Set vendor specific element callback
 | 
			
		||||
  *
 | 
			
		||||
  * @param     esp_vendor_ie_cb_t cb : callback function
 | 
			
		||||
  * @param     void *ctx : reserved
 | 
			
		||||
  * @param     cb   callback function
 | 
			
		||||
  * @param     ctx  reserved
 | 
			
		||||
  *
 | 
			
		||||
  * @return
 | 
			
		||||
  *    - ESP_OK : succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  *    - ESP_OK: succeed
 | 
			
		||||
  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
 | 
			
		||||
  */
 | 
			
		||||
esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1028,6 +1028,7 @@
 | 
			
		||||
#define DPORT_WIFI_RST_EN_REG          (DR_REG_DPORT_BASE + 0x0D0)
 | 
			
		||||
/* DPORT_WIFI_RST : R/W ;bitpos:[31:0] ;default: 32'h0 ; */
 | 
			
		||||
/*description: */
 | 
			
		||||
#define DPORT_MAC_RST (BIT(2))
 | 
			
		||||
#define DPORT_WIFI_RST  0xFFFFFFFF
 | 
			
		||||
#define DPORT_WIFI_RST_M  ((DPORT_WIFI_RST_V)<<(DPORT_WIFI_RST_S))
 | 
			
		||||
#define DPORT_WIFI_RST_V  0xFFFFFFFF
 | 
			
		||||
 
 | 
			
		||||
@@ -34,10 +34,41 @@
 | 
			
		||||
#define PIN_INPUT_ENABLE(PIN_NAME)               SET_PERI_REG_MASK(PIN_NAME,FUN_IE)
 | 
			
		||||
#define PIN_INPUT_DISABLE(PIN_NAME)              CLEAR_PERI_REG_MASK(PIN_NAME,FUN_IE)
 | 
			
		||||
#define PIN_SET_DRV(PIN_NAME, drv)            REG_SET_FIELD(PIN_NAME, FUN_DRV, (drv));
 | 
			
		||||
#define PIN_PULLUP_DIS(PIN_NAME)                 REG_CLR_BIT(PIN_NAME, FUN_PU)
 | 
			
		||||
#define PIN_PULLUP_EN(PIN_NAME)                  REG_SET_BIT(PIN_NAME, FUN_PU)
 | 
			
		||||
#define PIN_PULLDWN_DIS(PIN_NAME)             REG_CLR_BIT(PIN_NAME, FUN_PD)
 | 
			
		||||
#define PIN_PULLDWN_EN(PIN_NAME)              REG_SET_BIT(PIN_NAME, FUN_PD)
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * @attention
 | 
			
		||||
 *     The PIN_PULL[UP|DWN]_[EN|DIS]() functions used to exist as macros in previous SDK versions. 
 | 
			
		||||
 *     Unfortunately, however, they do not work for some GPIOs on the ESP32 chip, which needs pullups 
 | 
			
		||||
 *     and -downs turned on and off through RTC registers. The functions still exist for compatibility 
 | 
			
		||||
 *     with older code, but are marked as deprecated in order to generate a warning.
 | 
			
		||||
 *     Please replace them in this fashion: (make sure to include driver/gpio.h as well)
 | 
			
		||||
 *     PIN_PULLUP_EN(GPIO_PIN_MUX_REG[x])   ->  gpio_pullup_en(x)
 | 
			
		||||
 *     PIN_PULLUP_DIS(GPIO_PIN_MUX_REG[x])  ->  gpio_pullup_dis(x)
 | 
			
		||||
 *     PIN_PULLDWN_EN(GPIO_PIN_MUX_REG[x])  ->  gpio_pulldown_en(x)
 | 
			
		||||
 *     PIN_PULLDWN_DIS(GPIO_PIN_MUX_REG[x]) ->  gpio_pulldown_dis(x)
 | 
			
		||||
 *
 | 
			
		||||
*/
 | 
			
		||||
static inline void __attribute__ ((deprecated)) PIN_PULLUP_DIS(uint32_t PIN_NAME) 
 | 
			
		||||
{
 | 
			
		||||
    REG_CLR_BIT(PIN_NAME, FUN_PU);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void __attribute__ ((deprecated)) PIN_PULLUP_EN(uint32_t PIN_NAME)
 | 
			
		||||
{
 | 
			
		||||
    REG_SET_BIT(PIN_NAME, FUN_PU);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void __attribute__ ((deprecated)) PIN_PULLDWN_DIS(uint32_t PIN_NAME)
 | 
			
		||||
{
 | 
			
		||||
    REG_CLR_BIT(PIN_NAME, FUN_PD);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void __attribute__ ((deprecated)) PIN_PULLDWN_EN(uint32_t PIN_NAME)
 | 
			
		||||
{
 | 
			
		||||
    REG_SET_BIT(PIN_NAME, FUN_PD);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define PIN_FUNC_SELECT(PIN_NAME, FUNC)      REG_SET_FIELD(PIN_NAME, MCU_SEL, FUNC)
 | 
			
		||||
 | 
			
		||||
#define PIN_FUNC_GPIO                               2
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,7 @@
 | 
			
		||||
#include "esp_err.h"
 | 
			
		||||
#include "esp_intr.h"
 | 
			
		||||
#include "esp_attr.h"
 | 
			
		||||
#include "esp_freertos_hooks.h"
 | 
			
		||||
#include "soc/timer_group_struct.h"
 | 
			
		||||
#include "soc/timer_group_reg.h"
 | 
			
		||||
 | 
			
		||||
@@ -36,6 +37,38 @@
 | 
			
		||||
#define WDT_INT_NUM 24
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//Take care: the tick hook can also be called before esp_int_wdt_init() is called.
 | 
			
		||||
#if CONFIG_INT_WDT_CHECK_CPU1
 | 
			
		||||
//Not static; the ISR assembly checks this.
 | 
			
		||||
bool int_wdt_app_cpu_ticked=false;
 | 
			
		||||
 | 
			
		||||
static void IRAM_ATTR tick_hook(void) {
 | 
			
		||||
    if (xPortGetCoreID()!=0) {
 | 
			
		||||
        int_wdt_app_cpu_ticked=true;
 | 
			
		||||
    } else {
 | 
			
		||||
        //Only feed wdt if app cpu also ticked.
 | 
			
		||||
        if (int_wdt_app_cpu_ticked) {
 | 
			
		||||
            TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
 | 
			
		||||
            TIMERG1.wdt_config2=CONFIG_INT_WDT_TIMEOUT_MS*2;        //Set timeout before interrupt
 | 
			
		||||
            TIMERG1.wdt_config3=CONFIG_INT_WDT_TIMEOUT_MS*4;        //Set timeout before reset
 | 
			
		||||
            TIMERG1.wdt_feed=1;
 | 
			
		||||
            TIMERG1.wdt_wprotect=0;
 | 
			
		||||
            int_wdt_app_cpu_ticked=false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
static void IRAM_ATTR tick_hook(void) {
 | 
			
		||||
    if (xPortGetCoreID()!=0) return;
 | 
			
		||||
    TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
 | 
			
		||||
    TIMERG1.wdt_config2=CONFIG_INT_WDT_TIMEOUT_MS*2;        //Set timeout before interrupt
 | 
			
		||||
    TIMERG1.wdt_config3=CONFIG_INT_WDT_TIMEOUT_MS*4;        //Set timeout before reset
 | 
			
		||||
    TIMERG1.wdt_feed=1;
 | 
			
		||||
    TIMERG1.wdt_wprotect=0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void esp_int_wdt_init() {
 | 
			
		||||
    TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
 | 
			
		||||
    TIMERG1.wdt_config0.sys_reset_length=7;                 //3.2uS
 | 
			
		||||
@@ -53,6 +86,7 @@ void esp_int_wdt_init() {
 | 
			
		||||
    TIMERG1.wdt_wprotect=0;
 | 
			
		||||
    TIMERG1.int_clr_timers.wdt=1;
 | 
			
		||||
    TIMERG1.int_ena.wdt=1;
 | 
			
		||||
    esp_register_freertos_tick_hook(tick_hook);
 | 
			
		||||
    ESP_INTR_DISABLE(WDT_INT_NUM);
 | 
			
		||||
    intr_matrix_set(xPortGetCoreID(), ETS_TG1_WDT_LEVEL_INTR_SOURCE, WDT_INT_NUM);
 | 
			
		||||
    //We do not register a handler for the interrupt because it is interrupt level 4 which
 | 
			
		||||
@@ -62,35 +96,5 @@ void esp_int_wdt_init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//Take care: the tick hook can also be called before esp_int_wdt_init() is called.
 | 
			
		||||
#if CONFIG_INT_WDT_CHECK_CPU1
 | 
			
		||||
//Not static; the ISR assembly checks this.
 | 
			
		||||
bool int_wdt_app_cpu_ticked=false;
 | 
			
		||||
 | 
			
		||||
void IRAM_ATTR vApplicationTickHook(void) {
 | 
			
		||||
    if (xPortGetCoreID()!=0) {
 | 
			
		||||
        int_wdt_app_cpu_ticked=true;
 | 
			
		||||
    } else {
 | 
			
		||||
        //Only feed wdt if app cpu also ticked.
 | 
			
		||||
        if (int_wdt_app_cpu_ticked) {
 | 
			
		||||
            TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
 | 
			
		||||
            TIMERG1.wdt_config2=CONFIG_INT_WDT_TIMEOUT_MS*2;        //Set timeout before interrupt
 | 
			
		||||
            TIMERG1.wdt_config3=CONFIG_INT_WDT_TIMEOUT_MS*4;        //Set timeout before reset
 | 
			
		||||
            TIMERG1.wdt_feed=1;
 | 
			
		||||
            TIMERG1.wdt_wprotect=0;
 | 
			
		||||
            int_wdt_app_cpu_ticked=false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void IRAM_ATTR vApplicationTickHook(void) {
 | 
			
		||||
    if (xPortGetCoreID()!=0) return;
 | 
			
		||||
    TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
 | 
			
		||||
    TIMERG1.wdt_config2=CONFIG_INT_WDT_TIMEOUT_MS*2;        //Set timeout before interrupt
 | 
			
		||||
    TIMERG1.wdt_config3=CONFIG_INT_WDT_TIMEOUT_MS*4;        //Set timeout before reset
 | 
			
		||||
    TIMERG1.wdt_feed=1;
 | 
			
		||||
    TIMERG1.wdt_wprotect=0;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 Submodule components/esp32/lib updated: 01f5c068e1...a580f70a64
									
								
							
							
								
								
									
										64
									
								
								components/esp32/phy.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								components/esp32/phy.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
// 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.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "esp_phy_init.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @file phy.h
 | 
			
		||||
 * @brief Declarations for functions provided by libphy.a
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Initialize function pointer table in PHY library.
 | 
			
		||||
 * @note This function should be called before register_chipv7_phy.
 | 
			
		||||
 */
 | 
			
		||||
void phy_get_romfunc_addr(void);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Initialize PHY module and do RF calibration
 | 
			
		||||
 * @param[in] init_data Initialization parameters to be used by the PHY
 | 
			
		||||
 * @param[inout] cal_data As input, calibration data previously obtained. As output, will contain new calibration data.
 | 
			
		||||
 * @param[in] cal_mode  RF calibration mode
 | 
			
		||||
 * @return reserved for future use
 | 
			
		||||
 */
 | 
			
		||||
int register_chipv7_phy(const esp_phy_init_data_t* init_data, esp_phy_calibration_data_t *cal_data, esp_phy_calibration_mode_t cal_mode);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Get the format version of calibration data used by PHY library.
 | 
			
		||||
 * @return Format version number, OR'ed with BIT(16) if PHY is in WIFI only mode.
 | 
			
		||||
 */
 | 
			
		||||
uint32_t phy_get_rf_cal_version();
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set RF/BB for only WIFI mode or coexist(WIFI & BT) mode
 | 
			
		||||
 * @param[in] true is for only WIFI mode, false is for coexist mode. default is 0.
 | 
			
		||||
 * @return NULL
 | 
			
		||||
 */
 | 
			
		||||
void phy_set_wifi_mode_only(bool wifi_only);
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Set BT the highest priority in coexist mode.
 | 
			
		||||
 * @return NULL
 | 
			
		||||
 */
 | 
			
		||||
void coex_bt_high_prio(void);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										224
									
								
								components/esp32/phy_init.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								components/esp32/phy_init.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,224 @@
 | 
			
		||||
// 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 <stdbool.h>
 | 
			
		||||
 | 
			
		||||
#include "rom/ets_sys.h"
 | 
			
		||||
#include "soc/dport_reg.h"
 | 
			
		||||
 | 
			
		||||
#include "esp_err.h"
 | 
			
		||||
#include "esp_phy_init.h"
 | 
			
		||||
#include "esp_system.h"
 | 
			
		||||
#include "phy.h"
 | 
			
		||||
#include "esp_log.h"
 | 
			
		||||
#include "nvs.h"
 | 
			
		||||
#include "sdkconfig.h"
 | 
			
		||||
#include "phy_init_data.h"
 | 
			
		||||
 | 
			
		||||
static const char* TAG = "phy_init";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
esp_err_t esp_phy_init(const esp_phy_init_data_t* init_data,
 | 
			
		||||
        esp_phy_calibration_mode_t mode, esp_phy_calibration_data_t* calibration_data)
 | 
			
		||||
{
 | 
			
		||||
    assert(init_data);
 | 
			
		||||
    assert(calibration_data);
 | 
			
		||||
    // Initialize PHY pointer table
 | 
			
		||||
    phy_get_romfunc_addr();
 | 
			
		||||
    REG_SET_BIT(DPORT_WIFI_RST_EN_REG, DPORT_MAC_RST);
 | 
			
		||||
    REG_CLR_BIT(DPORT_WIFI_RST_EN_REG, DPORT_MAC_RST);
 | 
			
		||||
    // Enable WiFi peripheral clock
 | 
			
		||||
    SET_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG, 0x87cf);
 | 
			
		||||
    ESP_LOGV(TAG, "register_chipv7_phy, init_data=%p, cal_data=%p, mode=%d",
 | 
			
		||||
            init_data, calibration_data, mode);
 | 
			
		||||
    phy_set_wifi_mode_only(0);
 | 
			
		||||
    register_chipv7_phy(init_data, calibration_data, mode);
 | 
			
		||||
    coex_bt_high_prio();
 | 
			
		||||
    return ESP_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PHY init data handling functions
 | 
			
		||||
#if CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION
 | 
			
		||||
#include "esp_partition.h"
 | 
			
		||||
 | 
			
		||||
const esp_phy_init_data_t* esp_phy_get_init_data()
 | 
			
		||||
{
 | 
			
		||||
    const esp_partition_t* partition = esp_partition_find_first(
 | 
			
		||||
            ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL);
 | 
			
		||||
    if (partition == NULL) {
 | 
			
		||||
        ESP_LOGE(TAG, "PHY data partition not found");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    ESP_LOGD(TAG, "loading PHY init data from partition at offset 0x%x", partition->address);
 | 
			
		||||
    size_t init_data_store_length = sizeof(phy_init_magic_pre) +
 | 
			
		||||
            sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post);
 | 
			
		||||
    uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length);
 | 
			
		||||
    if (init_data_store == NULL) {
 | 
			
		||||
        ESP_LOGE(TAG, "failed to allocate memory for PHY init data");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGE(TAG, "failed to read PHY data partition (%d)", err);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 ||
 | 
			
		||||
        memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
 | 
			
		||||
                PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) {
 | 
			
		||||
        ESP_LOGE(TAG, "failed to validate PHY data partition");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    ESP_LOGE(TAG, "PHY data partition validated");
 | 
			
		||||
    return (const esp_phy_init_data_t*) (init_data_store + sizeof(phy_init_magic_pre));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void esp_phy_release_init_data(const esp_phy_init_data_t* init_data)
 | 
			
		||||
{
 | 
			
		||||
    free((uint8_t*) init_data - sizeof(phy_init_magic_pre));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else // CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION
 | 
			
		||||
 | 
			
		||||
// phy_init_data.h will declare static 'phy_init_data' variable initialized with default init data
 | 
			
		||||
 | 
			
		||||
const esp_phy_init_data_t* esp_phy_get_init_data()
 | 
			
		||||
{
 | 
			
		||||
    ESP_LOGD(TAG, "loading PHY init data from application binary");
 | 
			
		||||
    return &phy_init_data;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void esp_phy_release_init_data(const esp_phy_init_data_t* init_data)
 | 
			
		||||
{
 | 
			
		||||
    // no-op
 | 
			
		||||
}
 | 
			
		||||
#endif // CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// PHY calibration data handling functions
 | 
			
		||||
static const char* PHY_NAMESPACE = "phy";
 | 
			
		||||
static const char* PHY_CAL_VERSION_KEY = "cal_version";
 | 
			
		||||
static const char* PHY_CAL_MAC_KEY = "cal_mac";
 | 
			
		||||
static const char* PHY_CAL_DATA_KEY = "cal_data";
 | 
			
		||||
 | 
			
		||||
static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
 | 
			
		||||
        esp_phy_calibration_data_t* out_cal_data);
 | 
			
		||||
 | 
			
		||||
static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
 | 
			
		||||
        const esp_phy_calibration_data_t* cal_data);
 | 
			
		||||
 | 
			
		||||
esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data)
 | 
			
		||||
{
 | 
			
		||||
    nvs_handle handle;
 | 
			
		||||
    esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READONLY, &handle);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: failed to open NVS namespace (%d)", __func__, err);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        err = load_cal_data_from_nvs_handle(handle, out_cal_data);
 | 
			
		||||
        nvs_close(handle);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data)
 | 
			
		||||
{
 | 
			
		||||
    nvs_handle handle;
 | 
			
		||||
    esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READWRITE, &handle);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: failed to open NVS namespace (%d)", __func__, err);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        err = store_cal_data_to_nvs_handle(handle, cal_data);
 | 
			
		||||
        nvs_close(handle);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
 | 
			
		||||
        esp_phy_calibration_data_t* out_cal_data)
 | 
			
		||||
{
 | 
			
		||||
    esp_err_t err;
 | 
			
		||||
    uint32_t cal_data_version;
 | 
			
		||||
    err = nvs_get_u32(handle, PHY_CAL_VERSION_KEY, &cal_data_version);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: failed to get cal_version (%d)", __func__, err);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16));
 | 
			
		||||
    ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version);
 | 
			
		||||
    if (cal_data_version != cal_format_version) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: expected calibration data format %d, found %d",
 | 
			
		||||
                __func__, cal_format_version, cal_data_version);
 | 
			
		||||
        return ESP_FAIL;
 | 
			
		||||
    }
 | 
			
		||||
    uint8_t cal_data_mac[6];
 | 
			
		||||
    size_t length = sizeof(cal_data_mac);
 | 
			
		||||
    err = nvs_get_blob(handle, PHY_CAL_MAC_KEY, cal_data_mac, &length);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: failed to get cal_mac (%d)", __func__, err);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    if (length != sizeof(cal_data_mac)) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: invalid length of cal_mac (%d)", __func__, length);
 | 
			
		||||
        return ESP_ERR_INVALID_SIZE;
 | 
			
		||||
    }
 | 
			
		||||
    uint8_t sta_mac[6];
 | 
			
		||||
    system_efuse_read_mac(sta_mac);
 | 
			
		||||
    if (memcmp(sta_mac, cal_data_mac, sizeof(sta_mac)) != 0) {
 | 
			
		||||
        ESP_LOGE(TAG, "%s: calibration data MAC check failed: expected " \
 | 
			
		||||
                MACSTR ", found " MACSTR,
 | 
			
		||||
                __func__, MAC2STR(sta_mac), MAC2STR(cal_data_mac));
 | 
			
		||||
        return ESP_FAIL;
 | 
			
		||||
    }
 | 
			
		||||
    length = sizeof(*out_cal_data);
 | 
			
		||||
    err = nvs_get_blob(handle, PHY_CAL_DATA_KEY, out_cal_data, &length);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        ESP_LOGE(TAG, "%s: failed to get cal_data(%d)", __func__, err);
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    if (length != sizeof(*out_cal_data)) {
 | 
			
		||||
        ESP_LOGD(TAG, "%s: invalid length of cal_data (%d)", __func__, length);
 | 
			
		||||
        return ESP_ERR_INVALID_SIZE;
 | 
			
		||||
    }
 | 
			
		||||
    return ESP_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
 | 
			
		||||
        const esp_phy_calibration_data_t* cal_data)
 | 
			
		||||
{
 | 
			
		||||
    esp_err_t err;
 | 
			
		||||
    uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16));
 | 
			
		||||
    ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version);
 | 
			
		||||
    err = nvs_set_u32(handle, PHY_CAL_VERSION_KEY, cal_format_version);
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    uint8_t sta_mac[6];
 | 
			
		||||
    system_efuse_read_mac(sta_mac);
 | 
			
		||||
    err = nvs_set_blob(handle, PHY_CAL_MAC_KEY, sta_mac, sizeof(sta_mac));
 | 
			
		||||
    if (err != ESP_OK) {
 | 
			
		||||
        return err;
 | 
			
		||||
    }
 | 
			
		||||
    err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data, sizeof(*cal_data));
 | 
			
		||||
    return err;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void register_chipv7_phy_stub()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										139
									
								
								components/esp32/phy_init_data.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								components/esp32/phy_init_data.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,139 @@
 | 
			
		||||
// Copyright 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.
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
#include "esp_phy_init.h"
 | 
			
		||||
#include "sdkconfig.h"
 | 
			
		||||
 | 
			
		||||
// constrain a value between 'low' and 'high', inclusive
 | 
			
		||||
#define LIMIT(val, low, high) ((val < low) ? low : (val > high) ? high : val)
 | 
			
		||||
 | 
			
		||||
#define PHY_INIT_MAGIC "PHYINIT"
 | 
			
		||||
 | 
			
		||||
static const char phy_init_magic_pre[] = PHY_INIT_MAGIC;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @brief Structure containing default recommended PHY initialization parameters.
 | 
			
		||||
 */
 | 
			
		||||
static const esp_phy_init_data_t phy_init_data= {
 | 
			
		||||
        .param_ver_id = 0,
 | 
			
		||||
        .crystal_select = 3,
 | 
			
		||||
        .wifi_rx_gain_swp_step_1 = 0x05,
 | 
			
		||||
        .wifi_rx_gain_swp_step_2 = 0x04,
 | 
			
		||||
        .wifi_rx_gain_swp_step_3 = 0x06,
 | 
			
		||||
        .wifi_rx_gain_swp_step_4 = 0x05,
 | 
			
		||||
        .wifi_rx_gain_swp_step_5 = 0x01,
 | 
			
		||||
        .wifi_rx_gain_swp_step_6 = 0x06,
 | 
			
		||||
        .wifi_rx_gain_swp_step_7 = 0x05,
 | 
			
		||||
        .wifi_rx_gain_swp_step_8 = 0x04,
 | 
			
		||||
        .wifi_rx_gain_swp_step_9 = 0x06,
 | 
			
		||||
        .wifi_rx_gain_swp_step_10 = 0x04,
 | 
			
		||||
        .wifi_rx_gain_swp_step_11 = 0x05,
 | 
			
		||||
        .wifi_rx_gain_swp_step_12 = 0x00,
 | 
			
		||||
        .wifi_rx_gain_swp_step_13 = 0x00,
 | 
			
		||||
        .wifi_rx_gain_swp_step_14 = 0x00,
 | 
			
		||||
        .wifi_rx_gain_swp_step_15 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_1 = 0x05,
 | 
			
		||||
        .bt_rx_gain_swp_step_2 = 0x04,
 | 
			
		||||
        .bt_rx_gain_swp_step_3 = 0x06,
 | 
			
		||||
        .bt_rx_gain_swp_step_4 = 0x05,
 | 
			
		||||
        .bt_rx_gain_swp_step_5 = 0x01,
 | 
			
		||||
        .bt_rx_gain_swp_step_6 = 0x06,
 | 
			
		||||
        .bt_rx_gain_swp_step_7 = 0x05,
 | 
			
		||||
        .bt_rx_gain_swp_step_8 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_9 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_10 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_11 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_12 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_13 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_14 = 0x00,
 | 
			
		||||
        .bt_rx_gain_swp_step_15 = 0x00,
 | 
			
		||||
        .gain_cmp_1 = 0x0a,
 | 
			
		||||
        .gain_cmp_6 = 0x0a,
 | 
			
		||||
        .gain_cmp_11 = 0x0c,
 | 
			
		||||
        .gain_cmp_ext2_1 = 0xf0,
 | 
			
		||||
        .gain_cmp_ext2_6 = 0xf0,
 | 
			
		||||
        .gain_cmp_ext2_11 = 0xf0,
 | 
			
		||||
        .gain_cmp_ext3_1 = 0xe0,
 | 
			
		||||
        .gain_cmp_ext3_6 = 0xe0,
 | 
			
		||||
        .gain_cmp_ext3_11 = 0xe0,
 | 
			
		||||
        .gain_cmp_bt_ofs_1 = 0x18,
 | 
			
		||||
        .gain_cmp_bt_ofs_6 = 0x18,
 | 
			
		||||
        .gain_cmp_bt_ofs_11 = 0x18,
 | 
			
		||||
        .target_power_qdb_0 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 78),
 | 
			
		||||
        .target_power_qdb_1 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 76),
 | 
			
		||||
        .target_power_qdb_2 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 74),
 | 
			
		||||
        .target_power_qdb_3 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 68),
 | 
			
		||||
        .target_power_qdb_4 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 64),
 | 
			
		||||
        .target_power_qdb_5 = LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52),
 | 
			
		||||
        .target_power_index_mcs0 = 0,
 | 
			
		||||
        .target_power_index_mcs1 = 0,
 | 
			
		||||
        .target_power_index_mcs2 = 1,
 | 
			
		||||
        .target_power_index_mcs3 = 1,
 | 
			
		||||
        .target_power_index_mcs4 = 2,
 | 
			
		||||
        .target_power_index_mcs5 = 3,
 | 
			
		||||
        .target_power_index_mcs6 = 4,
 | 
			
		||||
        .target_power_index_mcs7 = 5,
 | 
			
		||||
        .pwr_ind_11b_en = 0,
 | 
			
		||||
        .pwr_ind_11b_0 = 0,
 | 
			
		||||
        .pwr_ind_11b_1 = 0,
 | 
			
		||||
        .chan_backoff_en = 0,
 | 
			
		||||
        .chan1_power_backoff_qdb = 0,
 | 
			
		||||
        .chan2_power_backoff_qdb = 0,
 | 
			
		||||
        .chan3_power_backoff_qdb = 0,
 | 
			
		||||
        .chan4_power_backoff_qdb = 0,
 | 
			
		||||
        .chan5_power_backoff_qdb = 0,
 | 
			
		||||
        .chan6_power_backoff_qdb = 0,
 | 
			
		||||
        .chan7_power_backoff_qdb = 0,
 | 
			
		||||
        .chan8_power_backoff_qdb = 0,
 | 
			
		||||
        .chan9_power_backoff_qdb = 0,
 | 
			
		||||
        .chan10_power_backoff_qdb = 0,
 | 
			
		||||
        .chan11_power_backoff_qdb = 0,
 | 
			
		||||
        .chan12_power_backoff_qdb = 0,
 | 
			
		||||
        .chan13_power_backoff_qdb = 0,
 | 
			
		||||
        .chan14_power_backoff_qdb = 0,
 | 
			
		||||
        .chan1_rate_backoff_index = 0,
 | 
			
		||||
        .chan2_rate_backoff_index = 0,
 | 
			
		||||
        .chan3_rate_backoff_index = 0,
 | 
			
		||||
        .chan4_rate_backoff_index = 0,
 | 
			
		||||
        .chan5_rate_backoff_index = 0,
 | 
			
		||||
        .chan6_rate_backoff_index = 0,
 | 
			
		||||
        .chan7_rate_backoff_index = 0,
 | 
			
		||||
        .chan8_rate_backoff_index = 0,
 | 
			
		||||
        .chan9_rate_backoff_index = 0,
 | 
			
		||||
        .chan10_rate_backoff_index = 0,
 | 
			
		||||
        .chan11_rate_backoff_index = 0,
 | 
			
		||||
        .chan12_rate_backoff_index = 0,
 | 
			
		||||
        .chan13_rate_backoff_index = 0,
 | 
			
		||||
        .chan14_rate_backoff_index = 0,
 | 
			
		||||
        .spur_freq_cfg_msb_1 = 0,
 | 
			
		||||
        .spur_freq_cfg_1 = 0,
 | 
			
		||||
        .spur_freq_cfg_div_1 = 0,
 | 
			
		||||
        .spur_freq_en_h_1 = 0,
 | 
			
		||||
        .spur_freq_en_l_1 = 0,
 | 
			
		||||
        .spur_freq_cfg_msb_2 = 0,
 | 
			
		||||
        .spur_freq_cfg_2 = 0,
 | 
			
		||||
        .spur_freq_cfg_div_2 = 0,
 | 
			
		||||
        .spur_freq_en_h_2 = 0,
 | 
			
		||||
        .spur_freq_en_l_2 = 0,
 | 
			
		||||
        .spur_freq_cfg_msb_3 = 0,
 | 
			
		||||
        .spur_freq_cfg_3 = 0,
 | 
			
		||||
        .spur_freq_cfg_div_3 = 0,
 | 
			
		||||
        .spur_freq_en_h_3 = 0,
 | 
			
		||||
        .spur_freq_en_l_3 = 0,
 | 
			
		||||
        .reserved = {0}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const char phy_init_magic_post[] = PHY_INIT_MAGIC;
 | 
			
		||||
 | 
			
		||||
@@ -22,10 +22,13 @@
 | 
			
		||||
#include "sdkconfig.h"
 | 
			
		||||
#include "freertos/FreeRTOS.h"
 | 
			
		||||
#include "freertos/task.h"
 | 
			
		||||
#include "freertos/queue.h"
 | 
			
		||||
#include "freertos/semphr.h"
 | 
			
		||||
#include <esp_types.h>
 | 
			
		||||
#include "esp_err.h"
 | 
			
		||||
#include "esp_intr.h"
 | 
			
		||||
#include "esp_attr.h"
 | 
			
		||||
#include "esp_freertos_hooks.h"
 | 
			
		||||
#include "soc/timer_group_struct.h"
 | 
			
		||||
#include "soc/timer_group_reg.h"
 | 
			
		||||
#include "esp_log.h"
 | 
			
		||||
@@ -44,6 +47,8 @@ struct wdt_task_t {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static wdt_task_t *wdt_task_list=NULL;
 | 
			
		||||
static portMUX_TYPE taskwdt_spinlock = portMUX_INITIALIZER_UNLOCKED;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void IRAM_ATTR task_wdt_isr(void *arg) {
 | 
			
		||||
    wdt_task_t *wdttask;
 | 
			
		||||
@@ -54,24 +59,35 @@ static void IRAM_ATTR task_wdt_isr(void *arg) {
 | 
			
		||||
    TIMERG0.wdt_wprotect=0;
 | 
			
		||||
    //Ack interrupt
 | 
			
		||||
    TIMERG0.int_clr_timers.wdt=1;
 | 
			
		||||
    //We are taking a spinlock while doing I/O (ets_printf) here. Normally, that is a pretty
 | 
			
		||||
    //bad thing, possibly (temporarily) hanging up the 2nd core and stopping FreeRTOS. In this case,
 | 
			
		||||
    //something bad already happened and reporting this is considered more important
 | 
			
		||||
    //than the badness caused by a spinlock here.
 | 
			
		||||
    portENTER_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
    if (!wdt_task_list) {
 | 
			
		||||
        //No task on list. Maybe none registered yet.
 | 
			
		||||
        portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    //Watchdog got triggered because at least one task did not report in.
 | 
			
		||||
    ets_printf("Task watchdog got triggered. The following tasks did not feed the watchdog in time:\n");
 | 
			
		||||
    ets_printf(DRAM_STR("Task watchdog got triggered. The following tasks did not feed the watchdog in time:\n"));
 | 
			
		||||
    for (wdttask=wdt_task_list; wdttask!=NULL; wdttask=wdttask->next) {
 | 
			
		||||
        if (!wdttask->fed_watchdog) {
 | 
			
		||||
            cpu=xTaskGetAffinity(wdttask->task_handle)==0?"CPU 0":"CPU 1";
 | 
			
		||||
            if (xTaskGetAffinity(wdttask->task_handle)==tskNO_AFFINITY) cpu="CPU 0/1";
 | 
			
		||||
            printf(" - %s (%s)\n", pcTaskGetTaskName(wdttask->task_handle), cpu);
 | 
			
		||||
            cpu=xTaskGetAffinity(wdttask->task_handle)==0?DRAM_STR("CPU 0"):DRAM_STR("CPU 1");
 | 
			
		||||
            if (xTaskGetAffinity(wdttask->task_handle)==tskNO_AFFINITY) cpu=DRAM_STR("CPU 0/1");
 | 
			
		||||
            ets_printf(DRAM_STR(" - %s (%s)\n"), pcTaskGetTaskName(wdttask->task_handle), cpu);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ets_printf("Tasks currently running:\n");
 | 
			
		||||
    ets_printf(DRAM_STR("Tasks currently running:\n"));
 | 
			
		||||
    for (int x=0; x<portNUM_PROCESSORS; x++) {
 | 
			
		||||
        ets_printf("CPU %d: %s\n", x, pcTaskGetTaskName(xTaskGetCurrentTaskHandleForCPU(x)));
 | 
			
		||||
        ets_printf(DRAM_STR("CPU %d: %s\n"), x, pcTaskGetTaskName(xTaskGetCurrentTaskHandleForCPU(x)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#if CONFIG_TASK_WDT_PANIC
 | 
			
		||||
    ets_printf("Aborting.\n");
 | 
			
		||||
    ets_printf(DRAM_STR("Aborting.\n"));
 | 
			
		||||
    abort();
 | 
			
		||||
#endif
 | 
			
		||||
    portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -79,6 +95,8 @@ void esp_task_wdt_feed() {
 | 
			
		||||
    wdt_task_t *wdttask=wdt_task_list;
 | 
			
		||||
    bool found_task=false, do_feed_wdt=true;
 | 
			
		||||
    TaskHandle_t handle=xTaskGetCurrentTaskHandle();
 | 
			
		||||
    portENTER_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
 | 
			
		||||
    //Walk the linked list of wdt tasks to find this one, as well as see if we need to feed
 | 
			
		||||
    //the real watchdog timer.
 | 
			
		||||
    for (wdttask=wdt_task_list; wdttask!=NULL; wdttask=wdttask->next) {
 | 
			
		||||
@@ -113,14 +131,18 @@ void esp_task_wdt_feed() {
 | 
			
		||||
        //Reset fed_watchdog status
 | 
			
		||||
        for (wdttask=wdt_task_list; wdttask->next!=NULL; wdttask=wdttask->next) wdttask->fed_watchdog=false;
 | 
			
		||||
    }
 | 
			
		||||
    portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void esp_task_wdt_delete() {
 | 
			
		||||
    TaskHandle_t handle=xTaskGetCurrentTaskHandle();
 | 
			
		||||
    wdt_task_t *wdttask=wdt_task_list;
 | 
			
		||||
    portENTER_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
 | 
			
		||||
    //Wdt task list can't be empty
 | 
			
		||||
    if (!wdt_task_list) {
 | 
			
		||||
        ESP_LOGE(TAG, "task_wdt_delete: No tasks in list?");
 | 
			
		||||
        portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (handle==wdt_task_list) {
 | 
			
		||||
@@ -129,17 +151,39 @@ void esp_task_wdt_delete() {
 | 
			
		||||
        free(wdttask);
 | 
			
		||||
    } else {
 | 
			
		||||
        //Find current task in list
 | 
			
		||||
        if (wdt_task_list->task_handle==handle) {
 | 
			
		||||
            //Task is the very first one.
 | 
			
		||||
            wdt_task_t *freeme=wdt_task_list;
 | 
			
		||||
            wdt_task_list=wdt_task_list->next;
 | 
			
		||||
            free(freeme);
 | 
			
		||||
            portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        while (wdttask->next!=NULL && wdttask->next->task_handle!=handle) wdttask=wdttask->next;
 | 
			
		||||
        if (!wdttask->next) {
 | 
			
		||||
            ESP_LOGE(TAG, "task_wdt_delete: Task never called task_wdt_feed!");
 | 
			
		||||
            portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        wdt_task_t *freeme=wdttask->next;
 | 
			
		||||
        wdttask->next=wdttask->next->next;
 | 
			
		||||
        free(freeme);
 | 
			
		||||
    }
 | 
			
		||||
    portEXIT_CRITICAL(&taskwdt_spinlock);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#if CONFIG_TASK_WDT_CHECK_IDLE_TASK
 | 
			
		||||
static bool idle_hook(void) {
 | 
			
		||||
#if !CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
 | 
			
		||||
    if (xPortGetCoreID()!=0) return true;
 | 
			
		||||
#endif
 | 
			
		||||
    esp_task_wdt_feed();
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void esp_task_wdt_init() {
 | 
			
		||||
    TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
 | 
			
		||||
    TIMERG0.wdt_config0.sys_reset_length=7;                 //3.2uS
 | 
			
		||||
@@ -153,6 +197,9 @@ void esp_task_wdt_init() {
 | 
			
		||||
    TIMERG0.wdt_config0.en=1;
 | 
			
		||||
    TIMERG0.wdt_feed=1;
 | 
			
		||||
    TIMERG0.wdt_wprotect=0;
 | 
			
		||||
#if CONFIG_TASK_WDT_CHECK_IDLE_TASK
 | 
			
		||||
    esp_register_freertos_idle_hook(idle_hook);
 | 
			
		||||
#endif
 | 
			
		||||
    ESP_INTR_DISABLE(ETS_T0_WDT_INUM);
 | 
			
		||||
    intr_matrix_set(xPortGetCoreID(), ETS_TG0_WDT_LEVEL_INTR_SOURCE, ETS_T0_WDT_INUM);
 | 
			
		||||
    xt_set_interrupt_handler(ETS_T0_WDT_INUM, task_wdt_isr, NULL);
 | 
			
		||||
@@ -161,13 +208,5 @@ void esp_task_wdt_init() {
 | 
			
		||||
    ESP_INTR_ENABLE(ETS_T0_WDT_INUM);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if CONFIG_TASK_WDT_CHECK_IDLE_TASK
 | 
			
		||||
void vApplicationIdleHook(void) {
 | 
			
		||||
#if !CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1
 | 
			
		||||
    if (xPortGetCoreID()!=0) return;
 | 
			
		||||
#endif
 | 
			
		||||
    esp_task_wdt_feed();
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user