mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-06-29 05:07:20 +08:00
feat(esp8266): add phy APIs
1. support save cal data in nvs; 2. support use phy partition to store init data; In old SDK, we use (max_sec - 3) as init data sector, and (max_sec - 4) as cal data sector. This is changed in IDF style SDK, and these 2 sectors can be used for other perpose.
This commit is contained in:
116
components/esp8266/include/esp_err.h
Normal file
116
components/esp8266/include/esp_err.h
Normal file
@ -0,0 +1,116 @@
|
||||
// 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 <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t esp_err_t;
|
||||
|
||||
/* Definitions for error constants. */
|
||||
|
||||
#define ESP_OK 0
|
||||
#define ESP_FAIL -1
|
||||
|
||||
#define ESP_ERR_NO_MEM 0x101
|
||||
#define ESP_ERR_INVALID_ARG 0x102
|
||||
#define ESP_ERR_INVALID_STATE 0x103
|
||||
#define ESP_ERR_INVALID_SIZE 0x104
|
||||
#define ESP_ERR_NOT_FOUND 0x105
|
||||
#define ESP_ERR_NOT_SUPPORTED 0x106
|
||||
#define ESP_ERR_TIMEOUT 0x107
|
||||
#define ESP_ERR_INVALID_RESPONSE 0x108
|
||||
#define ESP_ERR_INVALID_CRC 0x109
|
||||
#define ESP_ERR_INVALID_VERSION 0x10A
|
||||
#define ESP_ERR_INVALID_MAC 0x10B
|
||||
|
||||
#define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */
|
||||
#define ESP_ERR_MESH_BASE 0x4000 /*!< Starting number of MESH error codes */
|
||||
|
||||
/**
|
||||
* @brief Returns string for esp_err_t error codes
|
||||
*
|
||||
* This function finds the error code in a pre-generated lookup-table and
|
||||
* returns its string representation.
|
||||
*
|
||||
* The function is generated by the Python script
|
||||
* tools/gen_esp_err_to_name.py which should be run each time an esp_err_t
|
||||
* error is modified, created or removed from the IDF project.
|
||||
*
|
||||
* @param code esp_err_t error code
|
||||
* @return string error message
|
||||
*/
|
||||
const char *esp_err_to_name(esp_err_t code);
|
||||
|
||||
/**
|
||||
* @brief Returns string for esp_err_t and system error codes
|
||||
*
|
||||
* This function finds the error code in a pre-generated lookup-table of
|
||||
* esp_err_t errors and returns its string representation. If the error code
|
||||
* is not found then it is attempted to be found among system errors.
|
||||
*
|
||||
* The function is generated by the Python script
|
||||
* tools/gen_esp_err_to_name.py which should be run each time an esp_err_t
|
||||
* error is modified, created or removed from the IDF project.
|
||||
*
|
||||
* @param code esp_err_t error code
|
||||
* @param[out] buf buffer where the error message should be written
|
||||
* @param buflen Size of buffer buf. At most buflen bytes are written into the buf buffer (including the terminating null byte).
|
||||
* @return buf containing the string error message
|
||||
*/
|
||||
const char *esp_err_to_name_r(esp_err_t code, char *buf, size_t buflen);
|
||||
|
||||
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression) __attribute__((noreturn));
|
||||
|
||||
#ifndef __ASSERT_FUNC
|
||||
/* This won't happen on IDF, which defines __ASSERT_FUNC in assert.h, but it does happen when building on the host which
|
||||
uses /usr/include/assert.h or equivalent.
|
||||
*/
|
||||
#ifdef __ASSERT_FUNCTION
|
||||
#define __ASSERT_FUNC __ASSERT_FUNCTION /* used in glibc assert.h */
|
||||
#else
|
||||
#define __ASSERT_FUNC "??"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro which can be used to check the error code,
|
||||
* and terminate the program in case the code is not ESP_OK.
|
||||
* Prints the error code, error location, and the failed statement to serial output.
|
||||
*
|
||||
* Disabled if assertions are disabled.
|
||||
*/
|
||||
#ifdef NDEBUG
|
||||
#define ESP_ERROR_CHECK(x) do { \
|
||||
esp_err_t __err_rc = (x); \
|
||||
(void) sizeof(__err_rc); \
|
||||
} while(0);
|
||||
#else
|
||||
#define ESP_ERROR_CHECK(x) do { \
|
||||
esp_err_t __err_rc = (x); \
|
||||
if (__err_rc != ESP_OK) { \
|
||||
_esp_error_check_failed(__err_rc, __FILE__, __LINE__, \
|
||||
__ASSERT_FUNC, #x); \
|
||||
} \
|
||||
} while(0);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -15,6 +15,8 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -31,6 +33,138 @@ typedef struct {
|
||||
uint8_t params[128]; /*!< opaque PHY initialization parameters */
|
||||
} esp_phy_init_data_t;
|
||||
|
||||
/**
|
||||
* @brief Opaque PHY calibration data
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t rf_cal_data[128]; /*!< calibration data */
|
||||
uint32_t rx_gain_dc_table[125];
|
||||
} 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 Modules for modem sleep
|
||||
*/
|
||||
typedef enum {
|
||||
MODEM_WIFI_STATION_MODULE, //!< Wi-Fi Station used
|
||||
MODEM_WIFI_SOFTAP_MODULE, //!< Wi-Fi SoftAP used
|
||||
MODEM_WIFI_SNIFFER_MODULE, //!< Wi-Fi Sniffer used
|
||||
MODEM_USER_MODULE, //!< User used
|
||||
MODEM_MODULE_COUNT //!< Number of items
|
||||
} modem_sleep_module_t;
|
||||
|
||||
/**
|
||||
* @brief Module WIFI mask for medem sleep
|
||||
*/
|
||||
#define MODEM_WIFI_MASK ((1<<MODEM_WIFI_STATION_MODULE) | \
|
||||
(1<<MODEM_WIFI_SOFTAP_MODULE) | \
|
||||
(1<<MODEM_WIFI_SNIFFER_MODULE))
|
||||
|
||||
/**
|
||||
* @brief Modules needing to call phy_rf_init
|
||||
*/
|
||||
typedef enum {
|
||||
PHY_WIFI_MODULE, //!< Wi-Fi used
|
||||
PHY_MODEM_MODULE, //!< Modem sleep used
|
||||
PHY_MODULE_COUNT //!< Number of items
|
||||
} phy_rf_module_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.
|
||||
*
|
||||
* @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 phy function.
|
||||
* Data saved using this function to the NVS can later be loaded using
|
||||
* esp_phy_store_cal_data_to_nvs function.
|
||||
*
|
||||
* @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 and RF module
|
||||
*
|
||||
* PHY and RF module should be initialized in order to use WiFi.
|
||||
* Now PHY and RF initializing job is done automatically when start WiFi. Users should not
|
||||
* call this API in their application.
|
||||
*
|
||||
* @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.
|
||||
* @return ESP_FAIL on fail.
|
||||
*/
|
||||
esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibration_mode_t mode,
|
||||
esp_phy_calibration_data_t *calibration_data, phy_rf_module_t module);
|
||||
|
||||
/**
|
||||
* @brief De-initialize PHY and RF module
|
||||
*
|
||||
* PHY module should be de-initialized in order to shutdown WiFi.
|
||||
* Now PHY and RF de-initializing job is done automatically when stop WiFi. Users should not
|
||||
* call this API in their application.
|
||||
*
|
||||
* @return ESP_OK on success.
|
||||
*/
|
||||
esp_err_t esp_phy_rf_deinit(phy_rf_module_t module);
|
||||
|
||||
/**
|
||||
* @brief Load calibration data from NVS and initialize PHY and RF module
|
||||
*/
|
||||
void esp_phy_load_cal_and_init(phy_rf_module_t module);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user