// Lua: code, reason [, exccause, epc1, epc2, epc3, excvaddr, depc ] = bootreason() static int node_bootreason (lua_State *L) { const struct rst_info *ri = system_get_rst_info (); uint32_t arr[8] = { rtc_get_reset_reason(), ri->reason, ri->exccause, ri->epc1, ri->epc2, ri->epc3, ri->excvaddr, ri->depc }; int i, n = ((ri->reason != REASON_EXCEPTION_RST) ? 2 : 8); for (i = 0; i < n; ++i) lua_pushinteger (L, arr[i]); return n; }
void esp_phy_load_cal_and_init(void) { 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(); } 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(); } #ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE 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; } 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 (0x%x), falling back to full calibration", err); calibration_mode = PHY_RF_CAL_FULL; } esp_phy_rf_init(init_data, calibration_mode, cal_data); if (calibration_mode != PHY_RF_CAL_NONE && err != ESP_OK) { err = esp_phy_store_cal_data_to_nvs(cal_data); } else { err = ESP_OK; } #else esp_phy_rf_init(init_data, PHY_RF_CAL_FULL, cal_data); #endif esp_phy_release_init_data(init_data); free(cal_data); // PHY maintains a copy of calibration data, so we can free this }