mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 04:25:32 +00:00
phy_init: reduce the amount of hardwired logic, add coexist init
This commit is contained in:
@@ -63,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);
|
||||
|
||||
@@ -189,17 +190,8 @@ void start_cpu0_default(void)
|
||||
spi_flash_init();
|
||||
|
||||
#if CONFIG_ESP32_PHY_AUTO_INIT
|
||||
#if CONFIG_ESP32_STORE_PHY_CALIBRATION_DATA_IN_NVS
|
||||
nvs_flash_init();
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
if (esp_phy_init(calibration_mode) != ESP_OK) {
|
||||
ESP_LOGD(TAG, "phy init has failed");
|
||||
abort();
|
||||
}
|
||||
do_phy_init();
|
||||
#endif
|
||||
|
||||
xTaskCreatePinnedToCore(&main_task, "main",
|
||||
@@ -239,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
|
||||
}
|
||||
|
Reference in New Issue
Block a user