]> granicus.if.org Git - esp-idf/commitdiff
when brownout reset occurs,set the phy TX Power to the lowest
authorzhangyanjiao <zhangyanjiao@espressif.com>
Wed, 25 Jul 2018 09:28:56 +0000 (17:28 +0800)
committerzhangyanjiao <zhangyanjiao@espressif.com>
Thu, 30 Aug 2018 06:22:03 +0000 (14:22 +0800)
components/esp32/Kconfig
components/esp32/phy_init.c
components/esp32/phy_init_data.h

index 2f7d4c868ed3098ae5457afe9b40c7050625fe1e..aa7415f57c03da07fd33bed085ae02fad73642ac 100644 (file)
@@ -646,6 +646,14 @@ config BROWNOUT_DET_LVL
     default 7 if BROWNOUT_DET_LVL_SEL_7
 
 
+#Reduce PHY TX power when brownout reset
+config REDUCE_PHY_TX_POWER
+    bool "Reduce PHY TX power when brownout reset"
+    depends on BROWNOUT_DET
+    default y
+    help
+        When brownout reset occurs, reduce PHY TX power to keep the code running
+
 # Note about the use of "FRC1" name: currently FRC1 timer is not used for
 # high resolution timekeeping anymore. Instead the esp_timer API, implemented
 # using FRC2 timer, is used.
index 2da98c31b011da539c96c766360b973a07ccb68b..62f82f6fa70241a340b92b1cc5a24a4ddf9dcf83 100644 (file)
@@ -531,6 +531,18 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
     return err;
 }
 
+#if CONFIG_REDUCE_PHY_TX_POWER
+static void esp_phy_reduce_tx_power(esp_phy_init_data_t* init_data)
+{
+    uint8_t i;
+                                         
+    for(i = 0; i < PHY_TX_POWER_NUM; i++) {
+        // LOWEST_PHY_TX_POWER is the lowest tx power
+        init_data->params[PHY_TX_POWER_OFFSET+i] = PHY_TX_POWER_LOWEST;   
+    }
+}
+#endif
+
 void esp_phy_load_cal_and_init(phy_rf_module_t module)
 {
     esp_phy_calibration_data_t* cal_data =
@@ -540,11 +552,30 @@ void esp_phy_load_cal_and_init(phy_rf_module_t module)
         abort();
     }
 
+#if CONFIG_REDUCE_PHY_TX_POWER
+    const esp_phy_init_data_t* phy_init_data = esp_phy_get_init_data();
+    if (phy_init_data == NULL) {
+        ESP_LOGE(TAG, "failed to obtain PHY init data");
+        abort();
+    }
+
+    esp_phy_init_data_t* init_data = (esp_phy_init_data_t*) malloc(sizeof(esp_phy_init_data_t));
+    if (init_data == NULL) {
+        ESP_LOGE(TAG, "failed to allocate memory for phy init data");
+        abort();
+    }
+
+    memcpy(init_data, phy_init_data, sizeof(esp_phy_init_data_t));
+    if (esp_reset_reason() == ESP_RST_BROWNOUT) {
+        esp_phy_reduce_tx_power(init_data);
+    }
+#else
     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();
     }
+#endif
 
 #ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE
     esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
@@ -571,7 +602,12 @@ void esp_phy_load_cal_and_init(phy_rf_module_t module)
     esp_phy_rf_init(init_data, PHY_RF_CAL_FULL, cal_data, module);
 #endif
 
+#if CONFIG_REDUCE_PHY_TX_POWER
+    esp_phy_release_init_data(phy_init_data);
+    free(init_data);
+#else
     esp_phy_release_init_data(init_data);
+#endif
 
     free(cal_data); // PHY maintains a copy of calibration data, so we can free this
 }
index d09bbdd9c62d2edd92c310eaae56107ef63e3e10..cb211152a589aadca02221f4b253c461000e5cae 100644 (file)
 
 #define PHY_INIT_MAGIC "PHYINIT"
 
+// define the lowest tx power as LOWEST_PHY_TX_POWER
+#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52)
+#define PHY_TX_POWER_OFFSET 44
+#define PHY_TX_POWER_NUM    5
+
 static const char phy_init_magic_pre[] = PHY_INIT_MAGIC;
 
 /**