phy_init.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stddef.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdbool.h>
  10. #include <sys/lock.h>
  11. #include "soc/rtc.h"
  12. #include "esp_err.h"
  13. #include "esp_phy_init.h"
  14. #include "esp_mac.h"
  15. #include "esp_log.h"
  16. #include "nvs.h"
  17. #include "nvs_flash.h"
  18. #include "esp_efuse.h"
  19. #include "esp_timer.h"
  20. #include "sdkconfig.h"
  21. #include "freertos/FreeRTOS.h"
  22. #include "freertos/portmacro.h"
  23. #include "endian.h"
  24. #include "phy.h"
  25. #include "phy_init_data.h"
  26. #include "esp_coexist_internal.h"
  27. #include "esp_private/periph_ctrl.h"
  28. #include "esp_private/wifi.h"
  29. #include "esp_rom_crc.h"
  30. #include "esp_rom_sys.h"
  31. #include "soc/rtc_periph.h"
  32. #if __has_include("soc/syscon_reg.h")
  33. #include "soc/syscon_reg.h"
  34. #endif
  35. #if CONFIG_IDF_TARGET_ESP32
  36. #include "soc/dport_reg.h"
  37. #endif
  38. #include "hal/efuse_hal.h"
  39. #if CONFIG_IDF_TARGET_ESP32
  40. extern wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb;
  41. #endif
  42. static const char* TAG = "phy_init";
  43. static _lock_t s_phy_access_lock;
  44. #if !CONFIG_IDF_TARGET_ESP32C2 && !CONFIG_IDF_TARGET_ESP32C6 // TODO - WIFI-4424
  45. static DRAM_ATTR struct {
  46. int count; /* power on count of wifi and bt power domain */
  47. _lock_t lock;
  48. } s_wifi_bt_pd_controller = { .count = 0 };
  49. #endif
  50. /* Indicate PHY is calibrated or not */
  51. static bool s_is_phy_calibrated = false;
  52. static bool s_is_phy_reg_stored = false;
  53. /* Reference count of enabling PHY */
  54. static uint8_t s_phy_access_ref = 0;
  55. #if CONFIG_MAC_BB_PD
  56. /* Reference of powering down MAC and BB */
  57. static bool s_mac_bb_pu = true;
  58. #endif
  59. #if CONFIG_IDF_TARGET_ESP32
  60. /* time stamp updated when the PHY/RF is turned on */
  61. static int64_t s_phy_rf_en_ts = 0;
  62. #endif
  63. /* PHY spinlock for libphy.a */
  64. static DRAM_ATTR portMUX_TYPE s_phy_int_mux = portMUX_INITIALIZER_UNLOCKED;
  65. /* Memory to store PHY digital registers */
  66. static uint32_t* s_phy_digital_regs_mem = NULL;
  67. static uint8_t s_phy_modem_init_ref = 0;
  68. #if CONFIG_MAC_BB_PD
  69. uint32_t* s_mac_bb_pd_mem = NULL;
  70. /* Reference count of MAC BB backup memory */
  71. static uint8_t s_macbb_backup_mem_ref = 0;
  72. #endif
  73. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  74. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  75. extern uint8_t multi_phy_init_data_bin_start[] asm("_binary_phy_multiple_init_data_bin_start");
  76. extern uint8_t multi_phy_init_data_bin_end[] asm("_binary_phy_multiple_init_data_bin_end");
  77. #endif
  78. /* The following static variables are only used by Wi-Fi tasks, so they can be handled without lock */
  79. static phy_init_data_type_t s_phy_init_data_type = 0;
  80. static phy_init_data_type_t s_current_apply_phy_init_data = 0;
  81. static char s_phy_current_country[PHY_COUNTRY_CODE_LEN] = {0};
  82. /* Whether it is a new bin */
  83. static bool s_multiple_phy_init_data_bin = false;
  84. /* PHY init data type array */
  85. static char* s_phy_type[ESP_PHY_INIT_DATA_TYPE_NUMBER] = {"DEFAULT", "SRRC", "FCC", "CE", "NCC", "KCC", "MIC", "IC",
  86. "ACMA", "ANATEL", "ISED", "WPC", "OFCA", "IFETEL", "RCM"};
  87. /* Country and PHY init data type map */
  88. static phy_country_to_bin_type_t s_country_code_map_type_table[] = {
  89. {"AT", ESP_PHY_INIT_DATA_TYPE_CE},
  90. {"AU", ESP_PHY_INIT_DATA_TYPE_ACMA},
  91. {"BE", ESP_PHY_INIT_DATA_TYPE_CE},
  92. {"BG", ESP_PHY_INIT_DATA_TYPE_CE},
  93. {"BR", ESP_PHY_INIT_DATA_TYPE_ANATEL},
  94. {"CA", ESP_PHY_INIT_DATA_TYPE_ISED},
  95. {"CH", ESP_PHY_INIT_DATA_TYPE_CE},
  96. {"CN", ESP_PHY_INIT_DATA_TYPE_SRRC},
  97. {"CY", ESP_PHY_INIT_DATA_TYPE_CE},
  98. {"CZ", ESP_PHY_INIT_DATA_TYPE_CE},
  99. {"DE", ESP_PHY_INIT_DATA_TYPE_CE},
  100. {"DK", ESP_PHY_INIT_DATA_TYPE_CE},
  101. {"EE", ESP_PHY_INIT_DATA_TYPE_CE},
  102. {"ES", ESP_PHY_INIT_DATA_TYPE_CE},
  103. {"FI", ESP_PHY_INIT_DATA_TYPE_CE},
  104. {"FR", ESP_PHY_INIT_DATA_TYPE_CE},
  105. {"GB", ESP_PHY_INIT_DATA_TYPE_CE},
  106. {"GR", ESP_PHY_INIT_DATA_TYPE_CE},
  107. {"HK", ESP_PHY_INIT_DATA_TYPE_OFCA},
  108. {"HR", ESP_PHY_INIT_DATA_TYPE_CE},
  109. {"HU", ESP_PHY_INIT_DATA_TYPE_CE},
  110. {"IE", ESP_PHY_INIT_DATA_TYPE_CE},
  111. {"IN", ESP_PHY_INIT_DATA_TYPE_WPC},
  112. {"IS", ESP_PHY_INIT_DATA_TYPE_CE},
  113. {"IT", ESP_PHY_INIT_DATA_TYPE_CE},
  114. {"JP", ESP_PHY_INIT_DATA_TYPE_MIC},
  115. {"KR", ESP_PHY_INIT_DATA_TYPE_KCC},
  116. {"LI", ESP_PHY_INIT_DATA_TYPE_CE},
  117. {"LT", ESP_PHY_INIT_DATA_TYPE_CE},
  118. {"LU", ESP_PHY_INIT_DATA_TYPE_CE},
  119. {"LV", ESP_PHY_INIT_DATA_TYPE_CE},
  120. {"MT", ESP_PHY_INIT_DATA_TYPE_CE},
  121. {"MX", ESP_PHY_INIT_DATA_TYPE_IFETEL},
  122. {"NL", ESP_PHY_INIT_DATA_TYPE_CE},
  123. {"NO", ESP_PHY_INIT_DATA_TYPE_CE},
  124. {"NZ", ESP_PHY_INIT_DATA_TYPE_RCM},
  125. {"PL", ESP_PHY_INIT_DATA_TYPE_CE},
  126. {"PT", ESP_PHY_INIT_DATA_TYPE_CE},
  127. {"RO", ESP_PHY_INIT_DATA_TYPE_CE},
  128. {"SE", ESP_PHY_INIT_DATA_TYPE_CE},
  129. {"SI", ESP_PHY_INIT_DATA_TYPE_CE},
  130. {"SK", ESP_PHY_INIT_DATA_TYPE_CE},
  131. {"TW", ESP_PHY_INIT_DATA_TYPE_NCC},
  132. {"US", ESP_PHY_INIT_DATA_TYPE_FCC},
  133. };
  134. #endif
  135. uint32_t IRAM_ATTR phy_enter_critical(void)
  136. {
  137. if (xPortInIsrContext()) {
  138. portENTER_CRITICAL_ISR(&s_phy_int_mux);
  139. } else {
  140. portENTER_CRITICAL(&s_phy_int_mux);
  141. }
  142. // Interrupt level will be stored in current tcb, so always return zero.
  143. return 0;
  144. }
  145. void IRAM_ATTR phy_exit_critical(uint32_t level)
  146. {
  147. // Param level don't need any more, ignore it.
  148. if (xPortInIsrContext()) {
  149. portEXIT_CRITICAL_ISR(&s_phy_int_mux);
  150. } else {
  151. portEXIT_CRITICAL(&s_phy_int_mux);
  152. }
  153. }
  154. #if CONFIG_IDF_TARGET_ESP32
  155. int64_t esp_phy_rf_get_on_ts(void)
  156. {
  157. return s_phy_rf_en_ts;
  158. }
  159. static inline void phy_update_wifi_mac_time(bool en_clock_stopped, int64_t now)
  160. {
  161. static uint32_t s_common_clock_disable_time = 0;
  162. if (en_clock_stopped) {
  163. s_common_clock_disable_time = (uint32_t)now;
  164. } else {
  165. if (s_common_clock_disable_time) {
  166. uint32_t diff = (uint64_t)now - s_common_clock_disable_time;
  167. if (s_wifi_mac_time_update_cb) {
  168. s_wifi_mac_time_update_cb(diff);
  169. }
  170. s_common_clock_disable_time = 0;
  171. }
  172. }
  173. }
  174. #endif
  175. IRAM_ATTR void esp_phy_common_clock_enable(void)
  176. {
  177. #if !CONFIG_IDF_TARGET_ESP32C6 // IDF-5679
  178. wifi_bt_common_module_enable();
  179. #endif
  180. }
  181. IRAM_ATTR void esp_phy_common_clock_disable(void)
  182. {
  183. #if !CONFIG_IDF_TARGET_ESP32C6 // IDF-5679
  184. wifi_bt_common_module_disable();
  185. #endif
  186. }
  187. static inline void phy_digital_regs_store(void)
  188. {
  189. if (s_phy_digital_regs_mem != NULL) {
  190. phy_dig_reg_backup(true, s_phy_digital_regs_mem);
  191. s_is_phy_reg_stored = true;
  192. }
  193. }
  194. static inline void phy_digital_regs_load(void)
  195. {
  196. if (s_is_phy_reg_stored && s_phy_digital_regs_mem != NULL) {
  197. phy_dig_reg_backup(false, s_phy_digital_regs_mem);
  198. }
  199. }
  200. void esp_phy_enable(void)
  201. {
  202. _lock_acquire(&s_phy_access_lock);
  203. if (s_phy_access_ref == 0) {
  204. #if CONFIG_IDF_TARGET_ESP32
  205. // Update time stamp
  206. s_phy_rf_en_ts = esp_timer_get_time();
  207. // Update WiFi MAC time before WiFi/BT common clock is enabled
  208. phy_update_wifi_mac_time(false, s_phy_rf_en_ts);
  209. #endif
  210. esp_phy_common_clock_enable();
  211. if (s_is_phy_calibrated == false) {
  212. esp_phy_load_cal_and_init();
  213. s_is_phy_calibrated = true;
  214. }
  215. else {
  216. phy_wakeup_init();
  217. phy_digital_regs_load();
  218. }
  219. #if CONFIG_IDF_TARGET_ESP32
  220. coex_bt_high_prio();
  221. #endif
  222. }
  223. s_phy_access_ref++;
  224. _lock_release(&s_phy_access_lock);
  225. }
  226. void esp_phy_disable(void)
  227. {
  228. _lock_acquire(&s_phy_access_lock);
  229. s_phy_access_ref--;
  230. if (s_phy_access_ref == 0) {
  231. phy_digital_regs_store();
  232. // Disable PHY and RF.
  233. phy_close_rf();
  234. #if !CONFIG_IDF_TARGET_ESP32
  235. // Disable PHY temperature sensor
  236. phy_xpd_tsens();
  237. #endif
  238. #if CONFIG_IDF_TARGET_ESP32
  239. // Update WiFi MAC time before disalbe WiFi/BT common peripheral clock
  240. phy_update_wifi_mac_time(true, esp_timer_get_time());
  241. #endif
  242. // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware RNG
  243. esp_phy_common_clock_disable();
  244. }
  245. _lock_release(&s_phy_access_lock);
  246. }
  247. void IRAM_ATTR esp_wifi_bt_power_domain_on(void)
  248. {
  249. #if !CONFIG_IDF_TARGET_ESP32C2 && !CONFIG_IDF_TARGET_ESP32C6 // TODO - WIFI-4424
  250. _lock_acquire(&s_wifi_bt_pd_controller.lock);
  251. if (s_wifi_bt_pd_controller.count++ == 0) {
  252. CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
  253. #if !CONFIG_IDF_TARGET_ESP32
  254. SET_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, MODEM_RESET_FIELD_WHEN_PU);
  255. CLEAR_PERI_REG_MASK(SYSCON_WIFI_RST_EN_REG, MODEM_RESET_FIELD_WHEN_PU);
  256. #endif
  257. CLEAR_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
  258. }
  259. _lock_release(&s_wifi_bt_pd_controller.lock);
  260. #endif
  261. }
  262. void esp_wifi_bt_power_domain_off(void)
  263. {
  264. #if !CONFIG_IDF_TARGET_ESP32C2 && !CONFIG_IDF_TARGET_ESP32C6 // TODO - WIFI-4424
  265. _lock_acquire(&s_wifi_bt_pd_controller.lock);
  266. if (--s_wifi_bt_pd_controller.count == 0) {
  267. SET_PERI_REG_MASK(RTC_CNTL_DIG_ISO_REG, RTC_CNTL_WIFI_FORCE_ISO);
  268. SET_PERI_REG_MASK(RTC_CNTL_DIG_PWC_REG, RTC_CNTL_WIFI_FORCE_PD);
  269. }
  270. _lock_release(&s_wifi_bt_pd_controller.lock);
  271. #endif
  272. }
  273. void esp_phy_modem_init(void)
  274. {
  275. _lock_acquire(&s_phy_access_lock);
  276. s_phy_modem_init_ref++;
  277. if (s_phy_digital_regs_mem == NULL) {
  278. s_phy_digital_regs_mem = (uint32_t *)heap_caps_malloc(SOC_PHY_DIG_REGS_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
  279. }
  280. _lock_release(&s_phy_access_lock);
  281. }
  282. void esp_phy_modem_deinit(void)
  283. {
  284. _lock_acquire(&s_phy_access_lock);
  285. s_phy_modem_init_ref--;
  286. if (s_phy_modem_init_ref == 0) {
  287. s_is_phy_reg_stored = false;
  288. free(s_phy_digital_regs_mem);
  289. s_phy_digital_regs_mem = NULL;
  290. /* Fix the issue caused by the power domain off.
  291. * This issue is only on ESP32C3.
  292. */
  293. #if CONFIG_IDF_TARGET_ESP32C3
  294. phy_init_flag();
  295. #endif
  296. }
  297. _lock_release(&s_phy_access_lock);
  298. }
  299. #if CONFIG_MAC_BB_PD
  300. void esp_mac_bb_pd_mem_init(void)
  301. {
  302. _lock_acquire(&s_phy_access_lock);
  303. s_macbb_backup_mem_ref++;
  304. if (s_mac_bb_pd_mem == NULL) {
  305. s_mac_bb_pd_mem = (uint32_t *)heap_caps_malloc(SOC_MAC_BB_PD_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
  306. }
  307. _lock_release(&s_phy_access_lock);
  308. }
  309. void esp_mac_bb_pd_mem_deinit(void)
  310. {
  311. _lock_acquire(&s_phy_access_lock);
  312. s_macbb_backup_mem_ref--;
  313. if (s_macbb_backup_mem_ref == 0) {
  314. free(s_mac_bb_pd_mem);
  315. s_mac_bb_pd_mem = NULL;
  316. }
  317. _lock_release(&s_phy_access_lock);
  318. }
  319. IRAM_ATTR void esp_mac_bb_power_up(void)
  320. {
  321. if (s_mac_bb_pd_mem == NULL) {
  322. return;
  323. }
  324. esp_wifi_bt_power_domain_on();
  325. if (!s_mac_bb_pu) {
  326. esp_phy_common_clock_enable();
  327. phy_freq_mem_backup(false, s_mac_bb_pd_mem);
  328. esp_phy_common_clock_disable();
  329. s_mac_bb_pu = true;
  330. }
  331. }
  332. IRAM_ATTR void esp_mac_bb_power_down(void)
  333. {
  334. if (s_mac_bb_pd_mem == NULL) {
  335. return;
  336. }
  337. if (s_mac_bb_pu) {
  338. esp_phy_common_clock_enable();
  339. phy_freq_mem_backup(true, s_mac_bb_pd_mem);
  340. esp_phy_common_clock_disable();
  341. s_mac_bb_pu = false;
  342. }
  343. esp_wifi_bt_power_domain_off();
  344. }
  345. #endif
  346. // PHY init data handling functions
  347. #if CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
  348. #include "esp_partition.h"
  349. const esp_phy_init_data_t* esp_phy_get_init_data(void)
  350. {
  351. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  352. size_t init_data_store_length = sizeof(phy_init_magic_pre) +
  353. sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post);
  354. uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length);
  355. if (init_data_store == NULL) {
  356. ESP_LOGE(TAG, "failed to allocate memory for updated country code PHY init data");
  357. return NULL;
  358. }
  359. memcpy(init_data_store, multi_phy_init_data_bin_start, init_data_store_length);
  360. ESP_LOGI(TAG, "loading embedded multiple PHY init data");
  361. #else
  362. const esp_partition_t* partition = esp_partition_find_first(
  363. ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL);
  364. if (partition == NULL) {
  365. ESP_LOGE(TAG, "PHY data partition not found");
  366. return NULL;
  367. }
  368. ESP_LOGD(TAG, "loading PHY init data from partition at offset 0x%x", partition->address);
  369. size_t init_data_store_length = sizeof(phy_init_magic_pre) +
  370. sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post);
  371. uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length);
  372. if (init_data_store == NULL) {
  373. ESP_LOGE(TAG, "failed to allocate memory for PHY init data");
  374. return NULL;
  375. }
  376. // read phy data from flash
  377. esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length);
  378. if (err != ESP_OK) {
  379. ESP_LOGE(TAG, "failed to read PHY data partition (0x%x)", err);
  380. free(init_data_store);
  381. return NULL;
  382. }
  383. #endif
  384. // verify data
  385. if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 ||
  386. memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
  387. PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) {
  388. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  389. ESP_LOGE(TAG, "failed to validate embedded PHY init data");
  390. free(init_data_store);
  391. return NULL;
  392. #else
  393. #ifndef CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID
  394. ESP_LOGE(TAG, "failed to validate PHY data partition");
  395. free(init_data_store);
  396. return NULL;
  397. #else
  398. ESP_LOGE(TAG, "failed to validate PHY data partition, restoring default data into flash...");
  399. memcpy(init_data_store,
  400. PHY_INIT_MAGIC, sizeof(phy_init_magic_pre));
  401. memcpy(init_data_store + sizeof(phy_init_magic_pre),
  402. &phy_init_data, sizeof(phy_init_data));
  403. memcpy(init_data_store + sizeof(phy_init_magic_pre) + sizeof(phy_init_data),
  404. PHY_INIT_MAGIC, sizeof(phy_init_magic_post));
  405. assert(memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) == 0);
  406. assert(memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
  407. PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) == 0);
  408. // write default data
  409. err = esp_partition_write(partition, 0, init_data_store, init_data_store_length);
  410. if (err != ESP_OK) {
  411. ESP_LOGE(TAG, "failed to write default PHY data partition (0x%x)", err);
  412. free(init_data_store);
  413. return NULL;
  414. }
  415. #endif // CONFIG_ESP_PHY_DEFAULT_INIT_IF_INVALID
  416. #endif // CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  417. }
  418. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  419. if ((*(init_data_store + (sizeof(phy_init_magic_pre) + PHY_SUPPORT_MULTIPLE_BIN_OFFSET)))) {
  420. s_multiple_phy_init_data_bin = true;
  421. ESP_LOGI(TAG, "Support multiple PHY init data bins");
  422. } else {
  423. ESP_LOGW(TAG, "Does not support multiple PHY init data bins");
  424. }
  425. #endif
  426. ESP_LOGD(TAG, "PHY data partition validated");
  427. return (const esp_phy_init_data_t*) (init_data_store + sizeof(phy_init_magic_pre));
  428. }
  429. void esp_phy_release_init_data(const esp_phy_init_data_t* init_data)
  430. {
  431. free((uint8_t*) init_data - sizeof(phy_init_magic_pre));
  432. }
  433. #else // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
  434. // phy_init_data.h will declare static 'phy_init_data' variable initialized with default init data
  435. const esp_phy_init_data_t* esp_phy_get_init_data(void)
  436. {
  437. ESP_LOGD(TAG, "loading PHY init data from application binary");
  438. return &phy_init_data;
  439. }
  440. void esp_phy_release_init_data(const esp_phy_init_data_t* init_data)
  441. {
  442. // no-op
  443. }
  444. #endif // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
  445. // PHY calibration data handling functions
  446. static const char* PHY_NAMESPACE = "phy";
  447. static const char* PHY_CAL_VERSION_KEY = "cal_version";
  448. static const char* PHY_CAL_MAC_KEY = "cal_mac";
  449. static const char* PHY_CAL_DATA_KEY = "cal_data";
  450. static esp_err_t load_cal_data_from_nvs_handle(nvs_handle_t handle,
  451. esp_phy_calibration_data_t* out_cal_data);
  452. static esp_err_t store_cal_data_to_nvs_handle(nvs_handle_t handle,
  453. const esp_phy_calibration_data_t* cal_data);
  454. esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data)
  455. {
  456. nvs_handle_t handle;
  457. esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READONLY, &handle);
  458. if (err == ESP_ERR_NVS_NOT_INITIALIZED) {
  459. ESP_LOGE(TAG, "%s: NVS has not been initialized. "
  460. "Call nvs_flash_init before starting WiFi/BT.", __func__);
  461. return err;
  462. } else if (err != ESP_OK) {
  463. ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
  464. return err;
  465. }
  466. err = load_cal_data_from_nvs_handle(handle, out_cal_data);
  467. nvs_close(handle);
  468. return err;
  469. }
  470. esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data)
  471. {
  472. nvs_handle_t handle;
  473. esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READWRITE, &handle);
  474. if (err != ESP_OK) {
  475. ESP_LOGD(TAG, "%s: failed to open NVS namespace (0x%x)", __func__, err);
  476. return err;
  477. }
  478. else {
  479. err = store_cal_data_to_nvs_handle(handle, cal_data);
  480. nvs_close(handle);
  481. return err;
  482. }
  483. }
  484. esp_err_t esp_phy_erase_cal_data_in_nvs(void)
  485. {
  486. nvs_handle_t handle;
  487. esp_err_t err = nvs_open(PHY_NAMESPACE, NVS_READWRITE, &handle);
  488. if (err != ESP_OK) {
  489. ESP_LOGE(TAG, "%s: failed to open NVS phy namespace (0x%x)", __func__, err);
  490. return err;
  491. }
  492. else {
  493. err = nvs_erase_all(handle);
  494. if (err != ESP_OK) {
  495. ESP_LOGE(TAG, "%s: failed to erase NVS phy namespace (0x%x)", __func__, err);
  496. }
  497. else {
  498. err = nvs_commit(handle);
  499. if (err != ESP_OK) {
  500. ESP_LOGE(TAG, "%s: failed to commit NVS phy namespace (0x%x)", __func__, err);
  501. }
  502. }
  503. }
  504. nvs_close(handle);
  505. return err;
  506. }
  507. static esp_err_t load_cal_data_from_nvs_handle(nvs_handle_t handle,
  508. esp_phy_calibration_data_t* out_cal_data)
  509. {
  510. esp_err_t err;
  511. uint32_t cal_data_version;
  512. err = nvs_get_u32(handle, PHY_CAL_VERSION_KEY, &cal_data_version);
  513. if (err != ESP_OK) {
  514. ESP_LOGD(TAG, "%s: failed to get cal_version (0x%x)", __func__, err);
  515. return err;
  516. }
  517. uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16));
  518. ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version);
  519. if (cal_data_version != cal_format_version) {
  520. ESP_LOGD(TAG, "%s: expected calibration data format %d, found %d",
  521. __func__, cal_format_version, cal_data_version);
  522. return ESP_FAIL;
  523. }
  524. uint8_t cal_data_mac[6];
  525. size_t length = sizeof(cal_data_mac);
  526. err = nvs_get_blob(handle, PHY_CAL_MAC_KEY, cal_data_mac, &length);
  527. if (err != ESP_OK) {
  528. ESP_LOGD(TAG, "%s: failed to get cal_mac (0x%x)", __func__, err);
  529. return err;
  530. }
  531. if (length != sizeof(cal_data_mac)) {
  532. ESP_LOGD(TAG, "%s: invalid length of cal_mac (%d)", __func__, length);
  533. return ESP_ERR_INVALID_SIZE;
  534. }
  535. uint8_t sta_mac[6];
  536. esp_efuse_mac_get_default(sta_mac);
  537. if (memcmp(sta_mac, cal_data_mac, sizeof(sta_mac)) != 0) {
  538. ESP_LOGE(TAG, "%s: calibration data MAC check failed: expected " \
  539. MACSTR ", found " MACSTR,
  540. __func__, MAC2STR(sta_mac), MAC2STR(cal_data_mac));
  541. return ESP_FAIL;
  542. }
  543. length = sizeof(*out_cal_data);
  544. err = nvs_get_blob(handle, PHY_CAL_DATA_KEY, out_cal_data, &length);
  545. if (err != ESP_OK) {
  546. ESP_LOGE(TAG, "%s: failed to get cal_data(0x%x)", __func__, err);
  547. return err;
  548. }
  549. if (length != sizeof(*out_cal_data)) {
  550. ESP_LOGD(TAG, "%s: invalid length of cal_data (%d)", __func__, length);
  551. return ESP_ERR_INVALID_SIZE;
  552. }
  553. return ESP_OK;
  554. }
  555. static esp_err_t store_cal_data_to_nvs_handle(nvs_handle_t handle,
  556. const esp_phy_calibration_data_t* cal_data)
  557. {
  558. esp_err_t err;
  559. err = nvs_set_blob(handle, PHY_CAL_DATA_KEY, cal_data, sizeof(*cal_data));
  560. if (err != ESP_OK) {
  561. ESP_LOGE(TAG, "%s: store calibration data failed(0x%x)\n", __func__, err);
  562. return err;
  563. }
  564. uint8_t sta_mac[6];
  565. esp_efuse_mac_get_default(sta_mac);
  566. err = nvs_set_blob(handle, PHY_CAL_MAC_KEY, sta_mac, sizeof(sta_mac));
  567. if (err != ESP_OK) {
  568. ESP_LOGE(TAG, "%s: store calibration mac failed(0x%x)\n", __func__, err);
  569. return err;
  570. }
  571. uint32_t cal_format_version = phy_get_rf_cal_version() & (~BIT(16));
  572. ESP_LOGV(TAG, "phy_get_rf_cal_version: %d\n", cal_format_version);
  573. err = nvs_set_u32(handle, PHY_CAL_VERSION_KEY, cal_format_version);
  574. if (err != ESP_OK) {
  575. ESP_LOGE(TAG, "%s: store calibration version failed(0x%x)\n", __func__, err);
  576. return err;
  577. }
  578. err = nvs_commit(handle);
  579. if (err != ESP_OK) {
  580. ESP_LOGE(TAG, "%s: store calibration nvs commit failed(0x%x)\n", __func__, err);
  581. }
  582. return err;
  583. }
  584. #if CONFIG_ESP_PHY_REDUCE_TX_POWER
  585. static void __attribute((unused)) esp_phy_reduce_tx_power(esp_phy_init_data_t* init_data)
  586. {
  587. uint8_t i;
  588. for(i = 0; i < PHY_TX_POWER_NUM; i++) {
  589. // LOWEST_PHY_TX_POWER is the lowest tx power
  590. init_data->params[PHY_TX_POWER_OFFSET+i] = PHY_TX_POWER_LOWEST;
  591. }
  592. }
  593. #endif
  594. void esp_phy_load_cal_and_init(void)
  595. {
  596. char * phy_version = get_phy_version_str();
  597. ESP_LOGI(TAG, "phy_version %s", phy_version);
  598. #if CONFIG_IDF_TARGET_ESP32S2
  599. phy_eco_version_sel(efuse_hal_chip_revision() / 100);
  600. #endif
  601. esp_phy_calibration_data_t* cal_data =
  602. (esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1);
  603. if (cal_data == NULL) {
  604. ESP_LOGE(TAG, "failed to allocate memory for RF calibration data");
  605. abort();
  606. }
  607. #if CONFIG_ESP_PHY_REDUCE_TX_POWER
  608. const esp_phy_init_data_t* phy_init_data = esp_phy_get_init_data();
  609. if (phy_init_data == NULL) {
  610. ESP_LOGE(TAG, "failed to obtain PHY init data");
  611. abort();
  612. }
  613. esp_phy_init_data_t* init_data = (esp_phy_init_data_t*) malloc(sizeof(esp_phy_init_data_t));
  614. if (init_data == NULL) {
  615. ESP_LOGE(TAG, "failed to allocate memory for phy init data");
  616. abort();
  617. }
  618. memcpy(init_data, phy_init_data, sizeof(esp_phy_init_data_t));
  619. if (esp_reset_reason() == ESP_RST_BROWNOUT) {
  620. esp_phy_reduce_tx_power(init_data);
  621. }
  622. #else
  623. const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
  624. if (init_data == NULL) {
  625. ESP_LOGE(TAG, "failed to obtain PHY init data");
  626. abort();
  627. }
  628. #endif
  629. #if CONFIG_ESP_PHY_ENABLE_USB
  630. phy_bbpll_en_usb(true);
  631. #endif
  632. #ifdef CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE
  633. esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
  634. uint8_t sta_mac[6];
  635. if (esp_rom_get_reset_reason(0) == RESET_REASON_CORE_DEEP_SLEEP) {
  636. calibration_mode = PHY_RF_CAL_NONE;
  637. }
  638. esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
  639. if (err != ESP_OK) {
  640. ESP_LOGW(TAG, "failed to load RF calibration data (0x%x), falling back to full calibration", err);
  641. calibration_mode = PHY_RF_CAL_FULL;
  642. }
  643. esp_efuse_mac_get_default(sta_mac);
  644. memcpy(cal_data->mac, sta_mac, 6);
  645. esp_err_t ret = register_chipv7_phy(init_data, cal_data, calibration_mode);
  646. if (ret == ESP_CAL_DATA_CHECK_FAIL) {
  647. ESP_LOGW(TAG, "saving new calibration data because of checksum failure, mode(%d)", calibration_mode);
  648. }
  649. if ((calibration_mode != PHY_RF_CAL_NONE && err != ESP_OK) ||
  650. (calibration_mode != PHY_RF_CAL_FULL && ret == ESP_CAL_DATA_CHECK_FAIL)) {
  651. err = esp_phy_store_cal_data_to_nvs(cal_data);
  652. } else {
  653. err = ESP_OK;
  654. }
  655. #else
  656. register_chipv7_phy(init_data, cal_data, PHY_RF_CAL_FULL);
  657. #endif
  658. #if CONFIG_ESP_PHY_REDUCE_TX_POWER
  659. esp_phy_release_init_data(phy_init_data);
  660. free(init_data);
  661. #else
  662. esp_phy_release_init_data(init_data);
  663. #endif
  664. free(cal_data); // PHY maintains a copy of calibration data, so we can free this
  665. }
  666. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  667. static esp_err_t phy_crc_check_init_data(uint8_t* init_data, const uint8_t* checksum, size_t init_data_length)
  668. {
  669. uint32_t crc_data = 0;
  670. crc_data = esp_rom_crc32_le(crc_data, init_data, init_data_length);
  671. uint32_t crc_size_conversion = htobe32(crc_data);
  672. if (crc_size_conversion != *(uint32_t*)(checksum)) {
  673. return ESP_FAIL;
  674. }
  675. return ESP_OK;
  676. }
  677. static uint8_t phy_find_bin_type_according_country(const char* country)
  678. {
  679. uint32_t i = 0;
  680. uint8_t phy_init_data_type = 0;
  681. for (i = 0; i < sizeof(s_country_code_map_type_table)/sizeof(phy_country_to_bin_type_t); i++)
  682. {
  683. if (!memcmp(country, s_country_code_map_type_table[i].cc, sizeof(s_phy_current_country))) {
  684. phy_init_data_type = s_country_code_map_type_table[i].type;
  685. ESP_LOGD(TAG, "Current country is %c%c, PHY init data type is %s\n", s_country_code_map_type_table[i].cc[0],
  686. s_country_code_map_type_table[i].cc[1], s_phy_type[s_country_code_map_type_table[i].type]);
  687. break;
  688. }
  689. }
  690. if (i == sizeof(s_country_code_map_type_table)/sizeof(phy_country_to_bin_type_t)) {
  691. phy_init_data_type = ESP_PHY_INIT_DATA_TYPE_DEFAULT;
  692. ESP_LOGW(TAG, "Use the default certification code beacuse %c%c doesn't have a certificate", country[0], country[1]);
  693. }
  694. return phy_init_data_type;
  695. }
  696. static esp_err_t phy_find_bin_data_according_type(uint8_t* out_init_data_store,
  697. const phy_control_info_data_t* init_data_control_info,
  698. const uint8_t* init_data_multiple,
  699. phy_init_data_type_t init_data_type)
  700. {
  701. int i = 0;
  702. for (i = 0; i < init_data_control_info->number; i++) {
  703. if (init_data_type == *(init_data_multiple + (i * sizeof(esp_phy_init_data_t)) + PHY_INIT_DATA_TYPE_OFFSET)) {
  704. memcpy(out_init_data_store + sizeof(phy_init_magic_pre),
  705. init_data_multiple + (i * sizeof(esp_phy_init_data_t)), sizeof(esp_phy_init_data_t));
  706. break;
  707. }
  708. }
  709. if (i == init_data_control_info->number) {
  710. return ESP_FAIL;
  711. }
  712. return ESP_OK;
  713. }
  714. static esp_err_t phy_get_multiple_init_data(const esp_partition_t* partition,
  715. uint8_t* init_data_store,
  716. size_t init_data_store_length,
  717. phy_init_data_type_t init_data_type)
  718. {
  719. phy_control_info_data_t* init_data_control_info = (phy_control_info_data_t*) malloc(sizeof(phy_control_info_data_t));
  720. if (init_data_control_info == NULL) {
  721. ESP_LOGE(TAG, "failed to allocate memory for PHY init data control info");
  722. return ESP_FAIL;
  723. }
  724. esp_err_t err = ESP_OK;
  725. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  726. memcpy(init_data_control_info, multi_phy_init_data_bin_start + init_data_store_length, sizeof(phy_control_info_data_t));
  727. #else
  728. err = esp_partition_read(partition, init_data_store_length, init_data_control_info, sizeof(phy_control_info_data_t));
  729. if (err != ESP_OK) {
  730. free(init_data_control_info);
  731. ESP_LOGE(TAG, "failed to read PHY control info data partition (0x%x)", err);
  732. return ESP_FAIL;
  733. }
  734. #endif
  735. if ((init_data_control_info->check_algorithm) == PHY_CRC_ALGORITHM) {
  736. err = phy_crc_check_init_data(init_data_control_info->multiple_bin_checksum, init_data_control_info->control_info_checksum,
  737. sizeof(phy_control_info_data_t) - sizeof(init_data_control_info->control_info_checksum));
  738. if (err != ESP_OK) {
  739. free(init_data_control_info);
  740. ESP_LOGE(TAG, "PHY init data control info check error");
  741. return ESP_FAIL;
  742. }
  743. } else {
  744. free(init_data_control_info);
  745. ESP_LOGE(TAG, "Check algorithm not CRC, PHY init data update failed");
  746. return ESP_FAIL;
  747. }
  748. uint8_t* init_data_multiple = (uint8_t*) malloc(sizeof(esp_phy_init_data_t) * init_data_control_info->number);
  749. if (init_data_multiple == NULL) {
  750. free(init_data_control_info);
  751. ESP_LOGE(TAG, "failed to allocate memory for PHY init data multiple bin");
  752. return ESP_FAIL;
  753. }
  754. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  755. memcpy(init_data_multiple, multi_phy_init_data_bin_start + init_data_store_length + sizeof(phy_control_info_data_t), sizeof(esp_phy_init_data_t) * init_data_control_info->number);
  756. #else
  757. err = esp_partition_read(partition, init_data_store_length + sizeof(phy_control_info_data_t),
  758. init_data_multiple, sizeof(esp_phy_init_data_t) * init_data_control_info->number);
  759. if (err != ESP_OK) {
  760. free(init_data_multiple);
  761. free(init_data_control_info);
  762. ESP_LOGE(TAG, "failed to read PHY init data multiple bin partition (0x%x)", err);
  763. return ESP_FAIL;
  764. }
  765. #endif
  766. if ((init_data_control_info->check_algorithm) == PHY_CRC_ALGORITHM) {
  767. err = phy_crc_check_init_data(init_data_multiple, init_data_control_info->multiple_bin_checksum,
  768. sizeof(esp_phy_init_data_t) * init_data_control_info->number);
  769. if (err != ESP_OK) {
  770. free(init_data_multiple);
  771. free(init_data_control_info);
  772. ESP_LOGE(TAG, "PHY init data multiple bin check error");
  773. return ESP_FAIL;
  774. }
  775. } else {
  776. free(init_data_multiple);
  777. free(init_data_control_info);
  778. ESP_LOGE(TAG, "Check algorithm not CRC, PHY init data update failed");
  779. return ESP_FAIL;
  780. }
  781. err = phy_find_bin_data_according_type(init_data_store, init_data_control_info, init_data_multiple, init_data_type);
  782. if (err != ESP_OK) {
  783. ESP_LOGW(TAG, "%s has not been certified, use DEFAULT PHY init data", s_phy_type[init_data_type]);
  784. s_phy_init_data_type = ESP_PHY_INIT_DATA_TYPE_DEFAULT;
  785. } else {
  786. s_phy_init_data_type = init_data_type;
  787. }
  788. free(init_data_multiple);
  789. free(init_data_control_info);
  790. return ESP_OK;
  791. }
  792. esp_err_t esp_phy_update_init_data(phy_init_data_type_t init_data_type)
  793. {
  794. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED
  795. esp_err_t err = ESP_OK;
  796. const esp_partition_t* partition = NULL;
  797. size_t init_data_store_length = sizeof(phy_init_magic_pre) +
  798. sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post);
  799. uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length);
  800. if (init_data_store == NULL) {
  801. ESP_LOGE(TAG, "failed to allocate memory for updated country code PHY init data");
  802. return ESP_ERR_NO_MEM;
  803. }
  804. memcpy(init_data_store, multi_phy_init_data_bin_start, init_data_store_length);
  805. ESP_LOGI(TAG, "load embedded multi phy init data");
  806. #else
  807. const esp_partition_t* partition = esp_partition_find_first(
  808. ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_PHY, NULL);
  809. if (partition == NULL) {
  810. ESP_LOGE(TAG, "Updated country code PHY data partition not found");
  811. return ESP_FAIL;
  812. }
  813. size_t init_data_store_length = sizeof(phy_init_magic_pre) +
  814. sizeof(esp_phy_init_data_t) + sizeof(phy_init_magic_post);
  815. uint8_t* init_data_store = (uint8_t*) malloc(init_data_store_length);
  816. if (init_data_store == NULL) {
  817. ESP_LOGE(TAG, "failed to allocate memory for updated country code PHY init data");
  818. return ESP_ERR_NO_MEM;
  819. }
  820. esp_err_t err = esp_partition_read(partition, 0, init_data_store, init_data_store_length);
  821. if (err != ESP_OK) {
  822. free(init_data_store);
  823. ESP_LOGE(TAG, "failed to read updated country code PHY data partition (0x%x)", err);
  824. return ESP_FAIL;
  825. }
  826. #endif
  827. if (memcmp(init_data_store, PHY_INIT_MAGIC, sizeof(phy_init_magic_pre)) != 0 ||
  828. memcmp(init_data_store + init_data_store_length - sizeof(phy_init_magic_post),
  829. PHY_INIT_MAGIC, sizeof(phy_init_magic_post)) != 0) {
  830. free(init_data_store);
  831. ESP_LOGE(TAG, "failed to validate updated country code PHY data partition");
  832. return ESP_FAIL;
  833. }
  834. //find init data bin according init data type
  835. if (init_data_type != ESP_PHY_INIT_DATA_TYPE_DEFAULT) {
  836. err = phy_get_multiple_init_data(partition, init_data_store, init_data_store_length, init_data_type);
  837. if (err != ESP_OK) {
  838. free(init_data_store);
  839. #if CONFIG_ESP_PHY_INIT_DATA_ERROR
  840. abort();
  841. #else
  842. return ESP_FAIL;
  843. #endif
  844. }
  845. } else {
  846. s_phy_init_data_type = ESP_PHY_INIT_DATA_TYPE_DEFAULT;
  847. }
  848. if (s_current_apply_phy_init_data != s_phy_init_data_type) {
  849. err = esp_phy_apply_phy_init_data(init_data_store + sizeof(phy_init_magic_pre));
  850. if (err != ESP_OK) {
  851. ESP_LOGE(TAG, "PHY init data failed to load");
  852. free(init_data_store);
  853. return ESP_FAIL;
  854. }
  855. ESP_LOGI(TAG, "PHY init data type updated from %s to %s",
  856. s_phy_type[s_current_apply_phy_init_data], s_phy_type[s_phy_init_data_type]);
  857. s_current_apply_phy_init_data = s_phy_init_data_type;
  858. }
  859. free(init_data_store);
  860. return ESP_OK;
  861. }
  862. #endif
  863. esp_err_t esp_phy_update_country_info(const char *country)
  864. {
  865. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  866. uint8_t phy_init_data_type_map = 0;
  867. if (!s_multiple_phy_init_data_bin) {
  868. ESP_LOGD(TAG, "Does not support multiple PHY init data bins");
  869. return ESP_FAIL;
  870. }
  871. //if country equal s_phy_current_country, return;
  872. if (!memcmp(country, s_phy_current_country, sizeof(s_phy_current_country))) {
  873. return ESP_OK;
  874. }
  875. memcpy(s_phy_current_country, country, sizeof(s_phy_current_country));
  876. phy_init_data_type_map = phy_find_bin_type_according_country(country);
  877. if (phy_init_data_type_map == s_phy_init_data_type) {
  878. return ESP_OK;
  879. }
  880. esp_err_t err = esp_phy_update_init_data(phy_init_data_type_map);
  881. if (err != ESP_OK) {
  882. return err;
  883. }
  884. #endif
  885. return ESP_OK;
  886. }
  887. void esp_wifi_power_domain_on(void) __attribute__((alias("esp_wifi_bt_power_domain_on")));
  888. void esp_wifi_power_domain_off(void) __attribute__((alias("esp_wifi_bt_power_domain_off")));