esp_phy_init.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 opaque[1904]; /*!< calibration data */
  35. } esp_phy_calibration_data_t;
  36. typedef enum {
  37. PHY_RF_CAL_PARTIAL = 0x00000000, /*!< Do part of RF calibration. This should be used after power-on reset. */
  38. PHY_RF_CAL_NONE = 0x00000001, /*!< Don't do any RF calibration. This mode is only suggested to be used after deep sleep reset. */
  39. 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. */
  40. } esp_phy_calibration_mode_t;
  41. /**
  42. * @brief Get PHY init data
  43. *
  44. * If "Use a partition to store PHY init data" option is set in menuconfig,
  45. * This function will load PHY init data from a partition. Otherwise,
  46. * PHY init data will be compiled into the application itself, and this function
  47. * will return a pointer to PHY init data located in read-only memory (DROM).
  48. *
  49. * If "Use a partition to store PHY init data" option is enabled, this function
  50. * may return NULL if the data loaded from flash is not valid.
  51. *
  52. * @note Call esp_phy_release_init_data to release the pointer obtained using
  53. * this function after the call to esp_wifi_init.
  54. *
  55. * @return pointer to PHY init data structure
  56. */
  57. const esp_phy_init_data_t* esp_phy_get_init_data();
  58. /**
  59. * @brief Release PHY init data
  60. * @param data pointer to PHY init data structure obtained from
  61. * esp_phy_get_init_data function
  62. */
  63. void esp_phy_release_init_data(const esp_phy_init_data_t* data);
  64. /**
  65. * @brief Function called by esp_phy_init to load PHY calibration data
  66. *
  67. * This is a convenience function which can be used to load PHY calibration
  68. * data from NVS. Data can be stored to NVS using esp_phy_store_cal_data_to_nvs
  69. * function.
  70. *
  71. * If calibration data is not present in the NVS, or
  72. * data is not valid (was obtained for a chip with a different MAC address,
  73. * or obtained for a different version of software), this function will
  74. * return an error.
  75. *
  76. * If "Initialize PHY in startup code" option is set in menuconfig, this
  77. * function will be used to load calibration data. To provide a different
  78. * mechanism for loading calibration data, disable
  79. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  80. * function from the application. For an example usage of esp_phy_init and
  81. * this function, see esp_phy_store_cal_data_to_nvs function in cpu_start.c
  82. *
  83. * @param out_cal_data pointer to calibration data structure to be filled with
  84. * loaded data.
  85. * @return ESP_OK on success
  86. */
  87. esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t* out_cal_data);
  88. /**
  89. * @brief Function called by esp_phy_init to store PHY calibration data
  90. *
  91. * This is a convenience function which can be used to store PHY calibration
  92. * data to the NVS. Calibration data is returned by esp_phy_init function.
  93. * Data saved using this function to the NVS can later be loaded using
  94. * esp_phy_store_cal_data_to_nvs function.
  95. *
  96. * If "Initialize PHY in startup code" option is set in menuconfig, this
  97. * function will be used to store calibration data. To provide a different
  98. * mechanism for storing calibration data, disable
  99. * "Initialize PHY in startup code" option in menuconfig and call esp_phy_init
  100. * function from the application.
  101. *
  102. * @param cal_data pointer to calibration data which has to be saved.
  103. * @return ESP_OK on success
  104. */
  105. esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t* cal_data);
  106. /**
  107. * @brief Initialize PHY and RF module
  108. *
  109. * PHY and RF module should be initialized in order to use WiFi or BT.
  110. * Now PHY and RF initializing job is done automatically when start WiFi or BT. Users should not
  111. * call this API in their application.
  112. *
  113. * @param init_data PHY parameters. Default set of parameters can
  114. * be obtained by calling esp_phy_get_default_init_data
  115. * function.
  116. * @param mode Calibration mode (Full, partial, or no calibration)
  117. * @param[inout] calibration_data
  118. * @return ESP_OK on success.
  119. * @return ESP_FAIL on fail.
  120. */
  121. esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data,
  122. esp_phy_calibration_mode_t mode, esp_phy_calibration_data_t* calibration_data);
  123. /**
  124. * @brief De-initialize PHY and RF module
  125. *
  126. * PHY module should be de-initialized in order to shutdown WiFi or BT.
  127. * Now PHY and RF de-initializing job is done automatically when stop WiFi or BT. Users should not
  128. * call this API in their application.
  129. *
  130. * @return ESP_OK on success.
  131. */
  132. esp_err_t esp_phy_rf_deinit(void);
  133. /**
  134. * @brief Load calibration data from NVS and initialize PHY and RF module
  135. */
  136. void esp_phy_load_cal_and_init(void);
  137. #ifdef __cplusplus
  138. }
  139. #endif