esp_phy_init.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. /**
  44. * @brief Modules for modem sleep
  45. */
  46. typedef enum{
  47. MODEM_BLE_MODULE, //!< BLE controller used
  48. MODEM_CLASSIC_BT_MODULE, //!< Classic BT controller used
  49. MODEM_WIFI_STATION_MODULE, //!< Wi-Fi Station used
  50. MODEM_WIFI_SOFTAP_MODULE, //!< Wi-Fi SoftAP used
  51. MODEM_WIFI_SNIFFER_MODULE, //!< Wi-Fi Sniffer used
  52. MODEM_USER_MODULE, //!< User used
  53. MODEM_MODULE_COUNT //!< Number of items
  54. }modem_sleep_module_t;
  55. /**
  56. * @brief Module WIFI mask for medem sleep
  57. */
  58. #define MODEM_BT_MASK ((1<<MODEM_BLE_MODULE) | \
  59. (1<<MODEM_CLASSIC_BT_MODULE))
  60. /**
  61. * @brief Module WIFI mask for medem sleep
  62. */
  63. #define MODEM_WIFI_MASK ((1<<MODEM_WIFI_STATION_MODULE) | \
  64. (1<<MODEM_WIFI_SOFTAP_MODULE) | \
  65. (1<<MODEM_WIFI_SNIFFER_MODULE))
  66. /**
  67. * @brief Modules needing to call phy_rf_init
  68. */
  69. typedef enum{
  70. PHY_BT_MODULE, //!< Bluetooth used
  71. PHY_WIFI_MODULE, //!< Wi-Fi used
  72. PHY_MODEM_MODULE, //!< Modem sleep used
  73. PHY_MODULE_COUNT //!< Number of items
  74. }phy_rf_module_t;
  75. /**
  76. * @brief Get PHY init data
  77. *
  78. * If "Use a partition to store PHY init data" option is set in menuconfig,
  79. * This function will load PHY init data from a partition. Otherwise,
  80. * PHY init data will be compiled into the application itself, and this function
  81. * will return a pointer to PHY init data located in read-only memory (DROM).
  82. *
  83. * If "Use a partition to store PHY init data" option is enabled, this function
  84. * may return NULL if the data loaded from flash is not valid.
  85. *
  86. * @note Call esp_phy_release_init_data to release the pointer obtained using
  87. * this function after the call to esp_wifi_init.
  88. *
  89. * @return pointer to PHY init data structure
  90. */
  91. const esp_phy_init_data_t* esp_phy_get_init_data();
  92. /**
  93. * @brief Release PHY init data
  94. * @param data pointer to PHY init data structure obtained from
  95. * esp_phy_get_init_data function
  96. */
  97. void esp_phy_release_init_data(const esp_phy_init_data_t* data);
  98. /**
  99. * @brief Function called by esp_phy_init to load PHY calibration data
  100. *
  101. * This is a convenience function which can be used to load PHY calibration
  102. * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
  103. * function.
  104. *
  105. * If calibration data is not present in the NVS, or
  106. * data is not valid (was obtained for a chip with a different MAC address,
  107. * or obtained for a different version of software), this function will
  108. * return an error.
  109. *
  110. * If "Initialize PHY in startup code" option is set in menuconfig, this
  111. * function will be used to load calibration data. To provide a different
  112. * mechanism for loading calibration data, disable
  113. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  114. * function from the application. For an example usage of esp_phy_init and
  115. * this function, see esp_phy_store_cal_data_to_nvs function in cpu_start.c
  116. *
  117. * @param out_cal_data pointer to calibration data structure to be filled with
  118. * loaded data.
  119. * @return ESP_OK on success
  120. */
  121. esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data);
  122. /**
  123. * @brief Function called by esp_phy_init to store PHY calibration data
  124. *
  125. * This is a convenience function which can be used to store PHY calibration
  126. * data to the NVS. Calibration data is returned by esp_phy_init function.
  127. * Data saved using this function to the NVS can later be loaded using
  128. * esp_phy_store_cal_data_to_nvs function.
  129. *
  130. * If "Initialize PHY in startup code" option is set in menuconfig, this
  131. * function will be used to store calibration data. To provide a different
  132. * mechanism for storing calibration data, disable
  133. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  134. * function from the application.
  135. *
  136. * @param cal_data pointer to calibration data which has to be saved.
  137. * @return ESP_OK on success
  138. */
  139. esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data);
  140. /**
  141. * @brief Initialize PHY and RF module
  142. *
  143. * PHY and RF module should be initialized in order to use WiFi or BT.
  144. * Now PHY and RF initializing job is done automatically when start WiFi or BT. Users should not
  145. * call this API in their application.
  146. *
  147. * @param init_data PHY parameters. Default set of parameters can
  148. * be obtained by calling esp_phy_get_default_init_data
  149. * function.
  150. * @param mode Calibration mode (Full, partial, or no calibration)
  151. * @param[inout] calibration_data
  152. * @return ESP_OK on success.
  153. * @return ESP_FAIL on fail.
  154. */
  155. esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data,esp_phy_calibration_mode_t mode,
  156. esp_phy_calibration_data_t* calibration_data, phy_rf_module_t module);
  157. /**
  158. * @brief De-initialize PHY and RF module
  159. *
  160. * PHY module should be de-initialized in order to shutdown WiFi or BT.
  161. * Now PHY and RF de-initializing job is done automatically when stop WiFi or BT. Users should not
  162. * call this API in their application.
  163. *
  164. * @return ESP_OK on success.
  165. */
  166. esp_err_t esp_phy_rf_deinit(phy_rf_module_t module);
  167. /**
  168. * @brief Load calibration data from NVS and initialize PHY and RF module
  169. */
  170. void esp_phy_load_cal_and_init(phy_rf_module_t module);
  171. /**
  172. * @brief Module requires to enter modem sleep
  173. */
  174. esp_err_t esp_modem_sleep_enter(modem_sleep_module_t module);
  175. /**
  176. * @brief Module requires to exit modem sleep
  177. */
  178. esp_err_t esp_modem_sleep_exit(modem_sleep_module_t module);
  179. /**
  180. * @brief Register module to make it be able to require to enter/exit modem sleep
  181. */
  182. esp_err_t esp_modem_sleep_register(modem_sleep_module_t module);
  183. /**
  184. * @brief De-register module from modem sleep list
  185. */
  186. esp_err_t esp_modem_sleep_deregister(modem_sleep_module_t module);
  187. #ifdef __cplusplus
  188. }
  189. #endif