esp_phy_init.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "esp_err.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * @file
  15. * init parameters and API
  16. */
  17. /**
  18. * @brief Structure holding PHY init parameters
  19. */
  20. typedef struct {
  21. uint8_t params[128]; /*!< opaque PHY initialization parameters */
  22. } esp_phy_init_data_t;
  23. /**
  24. * @brief PHY enable or disable modem
  25. */
  26. typedef enum {
  27. PHY_MODEM_WIFI = 1, /*!< PHY modem WIFI */
  28. PHY_MODEM_BT = 2, /*!< PHY modem BT */
  29. PHY_MODEM_IEEE802154 = 4, /*!< PHY modem IEEE802154 */
  30. } esp_phy_modem_t;
  31. /**
  32. * @brief Opaque PHY calibration data
  33. */
  34. typedef struct {
  35. uint8_t version[4]; /*!< PHY version */
  36. uint8_t mac[6]; /*!< The MAC address of the station */
  37. uint8_t opaque[1894]; /*!< calibration data */
  38. } esp_phy_calibration_data_t;
  39. /**
  40. * @brief PHY calibration mode
  41. *
  42. */
  43. typedef enum {
  44. PHY_RF_CAL_PARTIAL = 0x00000000, /*!< Do part of RF calibration. This should be used after power-on reset. */
  45. PHY_RF_CAL_NONE = 0x00000001, /*!< Don't do any RF calibration. This mode is only suggested to be used after deep sleep reset. */
  46. PHY_RF_CAL_FULL = 0x00000002 /*!< Do full RF calibration. Produces best results, but also consumes a lot of time and current. Suggested to be used once. */
  47. } esp_phy_calibration_mode_t;
  48. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  49. /**
  50. * @brief PHY init data type
  51. */
  52. typedef enum {
  53. ESP_PHY_INIT_DATA_TYPE_DEFAULT = 0,
  54. ESP_PHY_INIT_DATA_TYPE_SRRC,
  55. ESP_PHY_INIT_DATA_TYPE_FCC,
  56. ESP_PHY_INIT_DATA_TYPE_CE,
  57. ESP_PHY_INIT_DATA_TYPE_NCC,
  58. ESP_PHY_INIT_DATA_TYPE_KCC,
  59. ESP_PHY_INIT_DATA_TYPE_MIC,
  60. ESP_PHY_INIT_DATA_TYPE_IC,
  61. ESP_PHY_INIT_DATA_TYPE_ACMA,
  62. ESP_PHY_INIT_DATA_TYPE_ANATEL,
  63. ESP_PHY_INIT_DATA_TYPE_ISED,
  64. ESP_PHY_INIT_DATA_TYPE_WPC,
  65. ESP_PHY_INIT_DATA_TYPE_OFCA,
  66. ESP_PHY_INIT_DATA_TYPE_IFETEL,
  67. ESP_PHY_INIT_DATA_TYPE_RCM,
  68. ESP_PHY_INIT_DATA_TYPE_NUMBER,
  69. } phy_init_data_type_t;
  70. #endif
  71. /**
  72. * @brief Get PHY init data
  73. *
  74. * If "Use a partition to store PHY init data" option is set in menuconfig,
  75. * This function will load PHY init data from a partition. Otherwise,
  76. * PHY init data will be compiled into the application itself, and this function
  77. * will return a pointer to PHY init data located in read-only memory (DROM).
  78. *
  79. * If "Use a partition to store PHY init data" option is enabled, this function
  80. * may return NULL if the data loaded from flash is not valid.
  81. *
  82. * @note Call esp_phy_release_init_data to release the pointer obtained using
  83. * this function after the call to esp_wifi_init.
  84. *
  85. * @return pointer to PHY init data structure
  86. */
  87. const esp_phy_init_data_t* esp_phy_get_init_data(void);
  88. /**
  89. * @brief Release PHY init data
  90. * @param data pointer to PHY init data structure obtained from
  91. * esp_phy_get_init_data function
  92. */
  93. void esp_phy_release_init_data(const esp_phy_init_data_t* data);
  94. /**
  95. * @brief Function called by esp_phy_load_cal_and_init to load PHY calibration data
  96. *
  97. * This is a convenience function which can be used to load PHY calibration
  98. * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
  99. * function.
  100. *
  101. * If calibration data is not present in the NVS, or
  102. * data is not valid (was obtained for a chip with a different MAC address,
  103. * or obtained for a different version of software), this function will
  104. * return an error.
  105. *
  106. * @param out_cal_data pointer to calibration data structure to be filled with
  107. * loaded data.
  108. * @return ESP_OK on success
  109. */
  110. esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data);
  111. /**
  112. * @brief Function called by esp_phy_load_cal_and_init to store PHY calibration data
  113. *
  114. * This is a convenience function which can be used to store PHY calibration
  115. * data to the NVS. Calibration data is returned by esp_phy_load_cal_and_init function.
  116. * Data saved using this function to the NVS can later be loaded using
  117. * esp_phy_store_cal_data_to_nvs function.
  118. *
  119. * @param cal_data pointer to calibration data which has to be saved.
  120. * @return ESP_OK on success
  121. */
  122. esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data);
  123. /**
  124. * @brief Erase PHY calibration data which is stored in the NVS
  125. *
  126. * This is a function which can be used to trigger full calibration as a last-resort remedy
  127. * if partial calibration is used. It can be called in the application based on some conditions
  128. * (e.g. an option provided in some diagnostic mode).
  129. *
  130. * @return ESP_OK on success
  131. * @return others on fail. Please refer to NVS API return value error number.
  132. */
  133. esp_err_t esp_phy_erase_cal_data_in_nvs(void);
  134. /**
  135. * @brief Enable PHY and RF module
  136. *
  137. * PHY and RF module should be enabled in order to use WiFi or BT.
  138. * Now PHY and RF enabling job is done automatically when start WiFi or BT. Users should not
  139. * call this API in their application.
  140. *
  141. * @param modem the modem to call the phy enable.
  142. */
  143. void esp_phy_enable(esp_phy_modem_t modem);
  144. /**
  145. * @brief Disable PHY and RF module
  146. *
  147. * PHY module should be disabled in order to shutdown WiFi or BT.
  148. * Now PHY and RF disabling job is done automatically when stop WiFi or BT. Users should not
  149. * call this API in their application.
  150. *
  151. * @param modem the modem to call the phy disable.
  152. */
  153. void esp_phy_disable(esp_phy_modem_t modem);
  154. /**
  155. * @brief Enable BTBB module
  156. *
  157. * BTBB module should be enabled in order to use IEEE802154 or BT.
  158. * Now BTBB enabling job is done automatically when start IEEE802154 or BT. Users should not
  159. * call this API in their application.
  160. *
  161. */
  162. void esp_btbb_enable(void);
  163. /**
  164. * @brief Disable BTBB module
  165. *
  166. * Dsiable BTBB module, used by IEEE802154 or Bluetooth.
  167. * Users should not call this API in their application.
  168. *
  169. */
  170. void esp_btbb_disable(void);
  171. /**
  172. * @brief Load calibration data from NVS and initialize PHY and RF module
  173. */
  174. void esp_phy_load_cal_and_init(void);
  175. /**
  176. * @brief Initialize backup memory for Phy power up/down
  177. */
  178. void esp_phy_modem_init(void);
  179. /**
  180. * @brief Deinitialize backup memory for Phy power up/down
  181. * Set phy_init_flag if all modems deinit on ESP32C3
  182. */
  183. void esp_phy_modem_deinit(void);
  184. #if CONFIG_MAC_BB_PD
  185. /**
  186. * @brief Initialize backup memory for MAC and Baseband power up/down
  187. */
  188. void esp_mac_bb_pd_mem_init(void);
  189. /**
  190. * @brief Deinitialize backup memory for MAC and Baseband power up/down
  191. */
  192. void esp_mac_bb_pd_mem_deinit(void);
  193. /**
  194. * @brief Power up MAC and Baseband
  195. */
  196. void esp_mac_bb_power_up(void);
  197. /**
  198. * @brief Power down MAC and Baseband
  199. */
  200. void esp_mac_bb_power_down(void);
  201. #endif
  202. /**
  203. * @brief Enable WiFi/BT common clock
  204. *
  205. */
  206. void esp_phy_common_clock_enable(void);
  207. /**
  208. * @brief Disable WiFi/BT common clock
  209. *
  210. */
  211. void esp_phy_common_clock_disable(void);
  212. /**
  213. * @brief Get the time stamp when PHY/RF was switched on
  214. * @return return 0 if PHY/RF is never switched on. Otherwise return time in
  215. * microsecond since boot when phy/rf was last switched on
  216. */
  217. int64_t esp_phy_rf_get_on_ts(void);
  218. /**
  219. * @brief Update the corresponding PHY init type according to the country code of Wi-Fi.
  220. *
  221. * @param country country code
  222. * @return ESP_OK on success.
  223. * @return esp_err_t code describing the error on fail
  224. */
  225. esp_err_t esp_phy_update_country_info(const char *country);
  226. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  227. /**
  228. * @brief Apply PHY init bin to PHY
  229. * @return ESP_OK on success.
  230. * @return ESP_FAIL on fail.
  231. */
  232. esp_err_t esp_phy_apply_phy_init_data(uint8_t *init_data);
  233. #endif
  234. /**
  235. * @brief Get PHY lib version
  236. * @return PHY lib version.
  237. */
  238. char * get_phy_version_str(void);
  239. /**
  240. * @brief Set PHY init parameters
  241. * @param param is 1 means combo module
  242. */
  243. void phy_init_param_set(uint8_t param);
  244. /**
  245. * @brief Wi-Fi RX enable
  246. * @param enable True for enable wifi receiving mode as default, false for closing wifi receiving mode as default.
  247. */
  248. void phy_wifi_enable_set(uint8_t enable);
  249. #ifdef __cplusplus
  250. }
  251. #endif