From 67424816ccb339b9a6fa8ba7d81514f981c2b504 Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Sat, 19 May 2018 12:13:34 +0800 Subject: [PATCH] esp32: some changes relating to phy v3900 1. Store the calibration data to NVS if PHY does full calibration because of calibration data checksum failure 2. Pass the station's mac to PHY for checksum calculation --- components/esp32/include/esp_phy_init.h | 4 +++- components/esp32/phy.h | 4 +++- components/esp32/phy_init.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/components/esp32/include/esp_phy_init.h b/components/esp32/include/esp_phy_init.h index 75cb8fb58..0228edf1c 100644 --- a/components/esp32/include/esp_phy_init.h +++ b/components/esp32/include/esp_phy_init.h @@ -37,7 +37,9 @@ typedef struct { * @brief Opaque PHY calibration data */ typedef struct { - uint8_t opaque[1904]; /*!< calibration data */ + uint8_t version[4]; /*!< PHY version */ + uint8_t mac[6]; /*!< The MAC address of the station */ + uint8_t opaque[1894]; /*!< calibration data */ } esp_phy_calibration_data_t; typedef enum { diff --git a/components/esp32/phy.h b/components/esp32/phy.h index 71c44cd3d..37066d00f 100644 --- a/components/esp32/phy.h +++ b/components/esp32/phy.h @@ -19,6 +19,8 @@ extern "C" { #endif +#define ESP_CAL_DATA_CHECK_FAIL 1 + /** * @file phy.h * @brief Declarations for functions provided by libphy.a @@ -34,7 +36,7 @@ void phy_get_romfunc_addr(void); * @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 + * @return ESP_CAL_DATA_CHECK_FAIL if calibration data checksum fails, other values are 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); diff --git a/components/esp32/phy_init.c b/components/esp32/phy_init.c index 027e6733a..cf1853387 100644 --- a/components/esp32/phy_init.c +++ b/components/esp32/phy_init.c @@ -119,7 +119,16 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibrat // Enable WiFi/BT common peripheral clock periph_module_enable(PERIPH_WIFI_BT_COMMON_MODULE); phy_set_wifi_mode_only(0); - register_chipv7_phy(init_data, calibration_data, mode); + + if (ESP_CAL_DATA_CHECK_FAIL == register_chipv7_phy(init_data, calibration_data, mode)) { + ESP_LOGW(TAG, "saving new calibration data because of checksum failure, mode(%d)", mode); +#ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE + if (mode != PHY_RF_CAL_FULL) { + esp_phy_store_cal_data_to_nvs(calibration_data); + } +#endif + } + coex_bt_high_prio(); } } @@ -476,6 +485,7 @@ static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle, ESP_LOGD(TAG, "%s: invalid length of cal_data (%d)", __func__, length); return ESP_ERR_INVALID_SIZE; } + memcpy(out_cal_data->mac, sta_mac, 6); return ESP_OK; }