esp_phy_init.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @file PHY init parameters and API
  23. */
  24. /**
  25. * @brief Structure holding PHY init parameters
  26. */
  27. typedef struct {
  28. uint8_t params[128]; /*!< opaque PHY initialization parameters */
  29. } esp_phy_init_data_t;
  30. /**
  31. * @brief Opaque PHY calibration data
  32. */
  33. typedef struct {
  34. uint8_t version[4]; /*!< PHY version */
  35. uint8_t mac[6]; /*!< The MAC address of the station */
  36. uint8_t opaque[1894]; /*!< calibration data */
  37. } esp_phy_calibration_data_t;
  38. typedef enum {
  39. PHY_RF_CAL_PARTIAL = 0x00000000, /*!< Do part of RF calibration. This should be used after power-on reset. */
  40. PHY_RF_CAL_NONE = 0x00000001, /*!< Don't do any RF calibration. This mode is only suggested to be used after deep sleep reset. */
  41. 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. */
  42. } esp_phy_calibration_mode_t;
  43. #if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
  44. /**
  45. * @brief PHY init data type
  46. */
  47. typedef enum {
  48. ESP_PHY_INIT_DATA_TYPE_DEFAULT = 0,
  49. ESP_PHY_INIT_DATA_TYPE_SRRC,
  50. ESP_PHY_INIT_DATA_TYPE_FCC,
  51. ESP_PHY_INIT_DATA_TYPE_CE,
  52. ESP_PHY_INIT_DATA_TYPE_NCC,
  53. ESP_PHY_INIT_DATA_TYPE_KCC,
  54. ESP_PHY_INIT_DATA_TYPE_MIC,
  55. ESP_PHY_INIT_DATA_TYPE_IC,
  56. ESP_PHY_INIT_DATA_TYPE_ACMA,
  57. ESP_PHY_INIT_DATA_TYPE_ANATEL,
  58. ESP_PHY_INIT_DATA_TYPE_ISED,
  59. ESP_PHY_INIT_DATA_TYPE_WPC,
  60. ESP_PHY_INIT_DATA_TYPE_OFCA,
  61. ESP_PHY_INIT_DATA_TYPE_IFETEL,
  62. ESP_PHY_INIT_DATA_TYPE_RCM,
  63. ESP_PHY_INIT_DATA_TYPE_NUMBER,
  64. } phy_init_data_type_t;
  65. #endif
  66. /**
  67. * @brief Get PHY init data
  68. *
  69. * If "Use a partition to store PHY init data" option is set in menuconfig,
  70. * This function will load PHY init data from a partition. Otherwise,
  71. * PHY init data will be compiled into the application itself, and this function
  72. * will return a pointer to PHY init data located in read-only memory (DROM).
  73. *
  74. * If "Use a partition to store PHY init data" option is enabled, this function
  75. * may return NULL if the data loaded from flash is not valid.
  76. *
  77. * @note Call esp_phy_release_init_data to release the pointer obtained using
  78. * this function after the call to esp_wifi_init.
  79. *
  80. * @return pointer to PHY init data structure
  81. */
  82. const esp_phy_init_data_t* esp_phy_get_init_data(void);
  83. /**
  84. * @brief Release PHY init data
  85. * @param data pointer to PHY init data structure obtained from
  86. * esp_phy_get_init_data function
  87. */
  88. void esp_phy_release_init_data(const esp_phy_init_data_t* data);
  89. /**
  90. * @brief Function called by esp_phy_init to load PHY calibration data
  91. *
  92. * This is a convenience function which can be used to load PHY calibration
  93. * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
  94. * function.
  95. *
  96. * If calibration data is not present in the NVS, or
  97. * data is not valid (was obtained for a chip with a different MAC address,
  98. * or obtained for a different version of software), this function will
  99. * return an error.
  100. *
  101. * If "Initialize PHY in startup code" option is set in menuconfig, this
  102. * function will be used to load calibration data. To provide a different
  103. * mechanism for loading calibration data, disable
  104. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  105. * function from the application. For an example usage of esp_phy_init and
  106. * this function, see esp_phy_store_cal_data_to_nvs function in cpu_start.c
  107. *
  108. * @param out_cal_data pointer to calibration data structure to be filled with
  109. * loaded data.
  110. * @return ESP_OK on success
  111. */
  112. esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data);
  113. /**
  114. * @brief Function called by esp_phy_init to store PHY calibration data
  115. *
  116. * This is a convenience function which can be used to store PHY calibration
  117. * data to the NVS. Calibration data is returned by esp_phy_init function.
  118. * Data saved using this function to the NVS can later be loaded using
  119. * esp_phy_store_cal_data_to_nvs function.
  120. *
  121. * If "Initialize PHY in startup code" option is set in menuconfig, this
  122. * function will be used to store calibration data. To provide a different
  123. * mechanism for storing calibration data, disable
  124. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  125. * function from the application.
  126. *
  127. * @param cal_data pointer to calibration data which has to be saved.
  128. * @return ESP_OK on success
  129. */
  130. esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data);
  131. /**
  132. * @brief Erase PHY calibration data which is stored in the NVS
  133. *
  134. * This is a function which can be used to trigger full calibration as a last-resort remedy
  135. * if partial calibration is used. It can be called in the application based on some conditions
  136. * (e.g. an option provided in some diagnostic mode).
  137. *
  138. * @return ESP_OK on success
  139. * @return others on fail. Please refer to NVS API return value error number.
  140. */
  141. esp_err_t esp_phy_erase_cal_data_in_nvs(void);
  142. /**
  143. * @brief Enable PHY and RF module
  144. *
  145. * PHY and RF module should be enabled in order to use WiFi or BT.
  146. * Now PHY and RF enabling job is done automatically when start WiFi or BT. Users should not
  147. * call this API in their application.
  148. *
  149. */
  150. void esp_phy_enable(void);
  151. /**
  152. * @brief Disable PHY and RF module
  153. *
  154. * PHY module should be disabled in order to shutdown WiFi or BT.
  155. * Now PHY and RF disabling job is done automatically when stop WiFi or BT. Users should not
  156. * call this API in their application.
  157. *
  158. */
  159. void esp_phy_disable(void);
  160. /**
  161. * @brief Load calibration data from NVS and initialize PHY and RF module
  162. */
  163. void esp_phy_load_cal_and_init(void);
  164. #if CONFIG_MAC_BB_PD
  165. /**
  166. * @brief Initialize backup memory for MAC and Baseband power up/down
  167. */
  168. void esp_mac_bb_pd_mem_init(void);
  169. /**
  170. * @brief Power up MAC and Baseband
  171. */
  172. void esp_mac_bb_power_up(void);
  173. /**
  174. * @brief Power down MAC and Baseband
  175. */
  176. void esp_mac_bb_power_down(void);
  177. #endif
  178. /**
  179. * @brief Enable WiFi/BT common clock
  180. *
  181. */
  182. void esp_phy_common_clock_enable(void);
  183. /**
  184. * @brief Disable WiFi/BT common clock
  185. *
  186. */
  187. void esp_phy_common_clock_disable(void);
  188. /**
  189. * @brief Get the time stamp when PHY/RF was switched on
  190. * @return return 0 if PHY/RF is never switched on. Otherwise return time in
  191. * microsecond since boot when phy/rf was last switched on
  192. */
  193. int64_t esp_phy_rf_get_on_ts(void);
  194. /**
  195. * @brief Update the corresponding PHY init type according to the country code of Wi-Fi.
  196. */
  197. esp_err_t esp_phy_update_country_info(const char *country);
  198. #if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
  199. /**
  200. * @brief Apply PHY init bin to PHY
  201. * @return ESP_OK on success.
  202. * @return ESP_FAIL on fail.
  203. */
  204. esp_err_t esp_phy_apply_phy_init_data(uint8_t *init_data);
  205. #endif
  206. /**
  207. * @brief Get PHY lib version
  208. * @return PHY lib version.
  209. */
  210. char * get_phy_version_str(void);
  211. #ifdef __cplusplus
  212. }
  213. #endif