esp_phy_init.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 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 PHY init parameters and API
  15. */
  16. /**
  17. * @brief Structure holding PHY init parameters
  18. */
  19. typedef struct {
  20. uint8_t params[128]; /*!< opaque PHY initialization parameters */
  21. } esp_phy_init_data_t;
  22. /**
  23. * @brief Opaque PHY calibration data
  24. */
  25. typedef struct {
  26. uint8_t version[4]; /*!< PHY version */
  27. uint8_t mac[6]; /*!< The MAC address of the station */
  28. uint8_t opaque[1894]; /*!< calibration data */
  29. } esp_phy_calibration_data_t;
  30. typedef enum {
  31. PHY_RF_CAL_PARTIAL = 0x00000000, /*!< Do part of RF calibration. This should be used after power-on reset. */
  32. PHY_RF_CAL_NONE = 0x00000001, /*!< Don't do any RF calibration. This mode is only suggested to be used after deep sleep reset. */
  33. 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. */
  34. } esp_phy_calibration_mode_t;
  35. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  36. /**
  37. * @brief PHY init data type
  38. */
  39. typedef enum {
  40. ESP_PHY_INIT_DATA_TYPE_DEFAULT = 0,
  41. ESP_PHY_INIT_DATA_TYPE_SRRC,
  42. ESP_PHY_INIT_DATA_TYPE_FCC,
  43. ESP_PHY_INIT_DATA_TYPE_CE,
  44. ESP_PHY_INIT_DATA_TYPE_NCC,
  45. ESP_PHY_INIT_DATA_TYPE_KCC,
  46. ESP_PHY_INIT_DATA_TYPE_MIC,
  47. ESP_PHY_INIT_DATA_TYPE_IC,
  48. ESP_PHY_INIT_DATA_TYPE_ACMA,
  49. ESP_PHY_INIT_DATA_TYPE_ANATEL,
  50. ESP_PHY_INIT_DATA_TYPE_ISED,
  51. ESP_PHY_INIT_DATA_TYPE_WPC,
  52. ESP_PHY_INIT_DATA_TYPE_OFCA,
  53. ESP_PHY_INIT_DATA_TYPE_IFETEL,
  54. ESP_PHY_INIT_DATA_TYPE_RCM,
  55. ESP_PHY_INIT_DATA_TYPE_NUMBER,
  56. } phy_init_data_type_t;
  57. #endif
  58. /**
  59. * @brief Get PHY init data
  60. *
  61. * If "Use a partition to store PHY init data" option is set in menuconfig,
  62. * This function will load PHY init data from a partition. Otherwise,
  63. * PHY init data will be compiled into the application itself, and this function
  64. * will return a pointer to PHY init data located in read-only memory (DROM).
  65. *
  66. * If "Use a partition to store PHY init data" option is enabled, this function
  67. * may return NULL if the data loaded from flash is not valid.
  68. *
  69. * @note Call esp_phy_release_init_data to release the pointer obtained using
  70. * this function after the call to esp_wifi_init.
  71. *
  72. * @return pointer to PHY init data structure
  73. */
  74. const esp_phy_init_data_t* esp_phy_get_init_data(void);
  75. /**
  76. * @brief Release PHY init data
  77. * @param data pointer to PHY init data structure obtained from
  78. * esp_phy_get_init_data function
  79. */
  80. void esp_phy_release_init_data(const esp_phy_init_data_t* data);
  81. /**
  82. * @brief Function called by esp_phy_init to load PHY calibration data
  83. *
  84. * This is a convenience function which can be used to load PHY calibration
  85. * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
  86. * function.
  87. *
  88. * If calibration data is not present in the NVS, or
  89. * data is not valid (was obtained for a chip with a different MAC address,
  90. * or obtained for a different version of software), this function will
  91. * return an error.
  92. *
  93. * If "Initialize PHY in startup code" option is set in menuconfig, this
  94. * function will be used to load calibration data. To provide a different
  95. * mechanism for loading calibration data, disable
  96. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  97. * function from the application. For an example usage of esp_phy_init and
  98. * this function, see esp_phy_store_cal_data_to_nvs function in cpu_start.c
  99. *
  100. * @param out_cal_data pointer to calibration data structure to be filled with
  101. * loaded data.
  102. * @return ESP_OK on success
  103. */
  104. esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data);
  105. /**
  106. * @brief Function called by esp_phy_init to store PHY calibration data
  107. *
  108. * This is a convenience function which can be used to store PHY calibration
  109. * data to the NVS. Calibration data is returned by esp_phy_init function.
  110. * Data saved using this function to the NVS can later be loaded using
  111. * esp_phy_store_cal_data_to_nvs function.
  112. *
  113. * If "Initialize PHY in startup code" option is set in menuconfig, this
  114. * function will be used to store calibration data. To provide a different
  115. * mechanism for storing calibration data, disable
  116. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  117. * function from the application.
  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. */
  142. void esp_phy_enable(void);
  143. /**
  144. * @brief Disable PHY and RF module
  145. *
  146. * PHY module should be disabled in order to shutdown WiFi or BT.
  147. * Now PHY and RF disabling job is done automatically when stop WiFi or BT. Users should not
  148. * call this API in their application.
  149. *
  150. */
  151. void esp_phy_disable(void);
  152. /**
  153. * @brief Load calibration data from NVS and initialize PHY and RF module
  154. */
  155. void esp_phy_load_cal_and_init(void);
  156. #if CONFIG_MAC_BB_PD
  157. /**
  158. * @brief Initialize backup memory for MAC and Baseband power up/down
  159. */
  160. void esp_mac_bb_pd_mem_init(void);
  161. /**
  162. * @brief Power up MAC and Baseband
  163. */
  164. void esp_mac_bb_power_up(void);
  165. /**
  166. * @brief Power down MAC and Baseband
  167. */
  168. void esp_mac_bb_power_down(void);
  169. #endif
  170. /**
  171. * @brief Enable WiFi/BT common clock
  172. *
  173. */
  174. void esp_phy_common_clock_enable(void);
  175. /**
  176. * @brief Disable WiFi/BT common clock
  177. *
  178. */
  179. void esp_phy_common_clock_disable(void);
  180. /**
  181. * @brief Get the time stamp when PHY/RF was switched on
  182. * @return return 0 if PHY/RF is never switched on. Otherwise return time in
  183. * microsecond since boot when phy/rf was last switched on
  184. */
  185. int64_t esp_phy_rf_get_on_ts(void);
  186. /**
  187. * @brief Update the corresponding PHY init type according to the country code of Wi-Fi.
  188. */
  189. esp_err_t esp_phy_update_country_info(const char *country);
  190. #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
  191. /**
  192. * @brief Apply PHY init bin to PHY
  193. * @return ESP_OK on success.
  194. * @return ESP_FAIL on fail.
  195. */
  196. esp_err_t esp_phy_apply_phy_init_data(uint8_t *init_data);
  197. #endif
  198. /**
  199. * @brief Get PHY lib version
  200. * @return PHY lib version.
  201. */
  202. char * get_phy_version_str(void);
  203. #ifdef __cplusplus
  204. }
  205. #endif