phy.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "esp_phy_init.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define ESP_CAL_DATA_CHECK_FAIL 1
  12. typedef enum {
  13. PHY_I2C_MST_CMD_TYPE_OFF = 0,
  14. PHY_I2C_MST_CMD_TYPE_ON,
  15. PHY_I2C_MST_CMD_TYPE_MAX
  16. } phy_i2c_master_command_type_t;
  17. typedef struct {
  18. struct {
  19. uint8_t start, end; /* the start and end index of phy i2c master command memory */
  20. uint8_t host_id; /* phy i2c master host id */
  21. } config[PHY_I2C_MST_CMD_TYPE_MAX];
  22. } phy_i2c_master_command_attribute_t;
  23. /**
  24. * @file phy.h
  25. * @brief Declarations for functions provided by libphy.a
  26. */
  27. /**
  28. * @brief Return ROM function pointer table from PHY library.
  29. */
  30. void phy_get_romfunc_addr(void);
  31. /**
  32. * @brief Initialize PHY module and do RF calibration
  33. * @param[in] init_data Initialization parameters to be used by the PHY
  34. * @param[inout] cal_data As input, calibration data previously obtained. As output, will contain new calibration data.
  35. * @param[in] cal_mode RF calibration mode
  36. * @return ESP_CAL_DATA_CHECK_FAIL if calibration data checksum fails, other values are reserved for future use
  37. */
  38. int register_chipv7_phy(const esp_phy_init_data_t* init_data, esp_phy_calibration_data_t *cal_data, esp_phy_calibration_mode_t cal_mode);
  39. /**
  40. * @brief Get the format version of calibration data used by PHY library.
  41. * @return Format version number, OR'ed with BIT(16) if PHY is in WIFI only mode.
  42. */
  43. uint32_t phy_get_rf_cal_version(void);
  44. /**
  45. * @brief Set RF/BB for only WIFI mode or coexist(WIFI & BT) mode
  46. * @param[in] true is for only WIFI mode, false is for coexist mode. default is 0.
  47. * @return NULL
  48. */
  49. void phy_set_wifi_mode_only(bool wifi_only);
  50. /**
  51. * @brief Set BT the highest priority in coexist mode.
  52. * @return NULL
  53. */
  54. void coex_bt_high_prio(void);
  55. /**
  56. * @brief Open PHY and RF.
  57. */
  58. void phy_wakeup_init(void);
  59. /**
  60. * @brief Shutdown PHY and RF.
  61. */
  62. void phy_close_rf(void);
  63. #if !CONFIG_IDF_TARGET_ESP32
  64. /**
  65. * @brief Disable PHY temperature sensor.
  66. */
  67. void phy_xpd_tsens(void);
  68. #endif
  69. #if CONFIG_IDF_TARGET_ESP32C3
  70. /**
  71. * @brief Update internal state of PHY when wifi deinit powers off the wifi power domain.
  72. */
  73. void phy_init_flag(void);
  74. #endif
  75. #if CONFIG_IDF_TARGET_ESP32C6
  76. /**
  77. * @brief Get the configuration info of PHY i2c master command memory.
  78. *
  79. * @param attr the configuration info of PHY i2c master command memory
  80. */
  81. void phy_i2c_master_mem_cfg(phy_i2c_master_command_attribute_t *attr);
  82. #endif
  83. /**
  84. * @brief Store and load PHY digital registers.
  85. *
  86. * @param backup_en if backup_en is true, store PHY digital registers to memory. Otherwise load PHY digital registers from memory
  87. * @param mem_addr Memory address to store and load PHY digital registers
  88. *
  89. * @return memory size
  90. */
  91. uint8_t phy_dig_reg_backup(bool backup_en, uint32_t *mem_addr);
  92. #if CONFIG_MAC_BB_PD
  93. /**
  94. * @brief Store and load baseband registers.
  95. */
  96. void phy_freq_mem_backup(bool backup_en, uint32_t *mem);
  97. #endif
  98. #if CONFIG_ESP_PHY_ENABLE_USB
  99. /**
  100. * @brief Enable or disable USB when phy init.
  101. */
  102. void phy_bbpll_en_usb(bool en);
  103. #endif
  104. #if CONFIG_IDF_TARGET_ESP32S2
  105. /**
  106. * @brief Phy version select for ESP32S2
  107. */
  108. void phy_eco_version_sel(uint8_t chip_ver);
  109. #endif
  110. #if CONFIG_ESP_PHY_IMPROVE_RX_11B
  111. /**
  112. * @brief Improve Wi-Fi receive 11b pkts when modules with high interference.
  113. *
  114. * @attention 1.This is a workaround to improve Wi-Fi receive 11b pkts for some modules using AC-DC power supply with high interference.
  115. * @attention 2.Enable this will sacrifice Wi-Fi OFDM receive performance.But to guarantee 11b receive performance serves as a bottom line in this case.
  116. *
  117. * @param enable Enable or disable.
  118. */
  119. void phy_improve_rx_special(bool enable);
  120. #endif
  121. /**
  122. * @brief Enable phy track pll
  123. *
  124. */
  125. void phy_track_pll_init(void);
  126. /**
  127. * @brief Disable phy track pll
  128. *
  129. */
  130. void phy_track_pll_deinit(void);
  131. /**
  132. * @brief Set the flag recorded which modem has already enabled phy
  133. *
  134. */
  135. void phy_set_modem_flag(esp_phy_modem_t modem);
  136. /**
  137. * @brief Clear the flag to record which modem calls phy disenable
  138. */
  139. void phy_clr_modem_flag(esp_phy_modem_t modem);
  140. /**
  141. * @brief Get the flag recorded which modem has already enabled phy
  142. *
  143. */
  144. esp_phy_modem_t phy_get_modem_flag(void);
  145. /**
  146. * @brief Get the PHY lock, only used in esp_phy, the user should not use this function.
  147. *
  148. */
  149. _lock_t phy_get_lock(void);
  150. #ifdef __cplusplus
  151. }
  152. #endif