esp_coexist_internal.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*
  2. * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ESP_COEXIST_INTERNAL_H__
  7. #define __ESP_COEXIST_INTERNAL_H__
  8. #include <stdbool.h>
  9. #include "esp_coexist.h"
  10. #include "esp_coexist_adapter.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef enum {
  15. COEX_PREFER_WIFI = 0,
  16. COEX_PREFER_BT,
  17. COEX_PREFER_BALANCE,
  18. COEX_PREFER_NUM,
  19. } coex_prefer_t;
  20. typedef enum {
  21. COEX_SCHM_CALLBACK_TYPE_WIFI = 0,
  22. COEX_SCHM_CALLBACK_TYPE_BT,
  23. COEX_SCHM_CALLBACK_TYPE_I154,
  24. } coex_schm_callback_type_t;
  25. typedef void (* coex_func_cb_t)(uint32_t event, int sched_cnt);
  26. typedef esp_err_t (* coex_set_lpclk_source_callback_t)(void);
  27. typedef void (* coex_wifi_channel_change_cb_t)(uint8_t primary, uint8_t secondary);
  28. /**
  29. * @brief Pre-Init software coexist
  30. * extern function for internal use.
  31. *
  32. * @return Init ok or failed.
  33. */
  34. esp_err_t coex_pre_init(void);
  35. /**
  36. * @brief Init software coexist
  37. * extern function for internal use.
  38. *
  39. * @return Init ok or failed.
  40. */
  41. esp_err_t coex_init(void);
  42. /**
  43. * @brief De-init software coexist
  44. * extern function for internal use.
  45. */
  46. void coex_deinit(void);
  47. /**
  48. * @brief Enable software coexist
  49. * extern function for internal use.
  50. *
  51. * @return Enable ok or failed.
  52. */
  53. esp_err_t coex_enable(void);
  54. /**
  55. * @brief Disable software coexist
  56. * extern function for internal use.
  57. */
  58. void coex_disable(void);
  59. /**
  60. * @brief Get software coexist version string
  61. * extern function for internal use.
  62. * @return : version string
  63. */
  64. const char *coex_version_get(void);
  65. /**
  66. * @brief Coexist performance preference set from libbt.a
  67. * extern function for internal use.
  68. *
  69. * @param prefer : the prefer enumeration value
  70. * @return : ESP_OK - success, other - failed
  71. */
  72. esp_err_t coex_preference_set(coex_prefer_t prefer);
  73. /**
  74. * @brief Get software coexist status.
  75. * @return : software coexist status
  76. */
  77. uint32_t coex_status_get(void);
  78. /**
  79. * @brief Set software coexist condition.
  80. * @return : software coexist condition
  81. */
  82. void coex_condition_set(uint32_t type, bool dissatisfy);
  83. /**
  84. * @brief WiFi requests coexistence.
  85. *
  86. * @param event : WiFi event
  87. * @param latency : WiFi will request coexistence after latency
  88. * @param duration : duration for WiFi to request coexistence
  89. * @return : 0 - success, other - failed
  90. */
  91. int coex_wifi_request(uint32_t event, uint32_t latency, uint32_t duration);
  92. /**
  93. * @brief WiFi release coexistence.
  94. *
  95. * @param event : WiFi event
  96. * @return : 0 - success, other - failed
  97. */
  98. int coex_wifi_release(uint32_t event);
  99. /**
  100. * @brief Set WiFi channel to coexistence module.
  101. *
  102. * @param primary : WiFi primary channel
  103. * @param secondary : WiFi secondary channel
  104. * @return : 0 - success, other - failed
  105. */
  106. int coex_wifi_channel_set(uint8_t primary, uint8_t secondary);
  107. /**
  108. * @brief Get WiFi channel from coexistence module.
  109. *
  110. * @param primary : pointer to value of WiFi primary channel
  111. * @param secondary : pointer to value of WiFi secondary channel
  112. * @return : 0 - success, other - failed
  113. */
  114. int coex_wifi_channel_get(uint8_t *primary, uint8_t *secondary);
  115. /**
  116. * @brief Register application callback function to Wi-Fi update low power clock module.
  117. *
  118. * @param callback : Wi-Fi update low power clock callback function
  119. */
  120. void coex_wifi_register_update_lpclk_callback(coex_set_lpclk_source_callback_t callback);
  121. /**
  122. * @brief Bluetooth requests coexistence
  123. *
  124. * @param event : Bluetooth event
  125. * @param latency : Bluetooth will request coexistence after latency
  126. * @param duration : duration for Bluetooth to request coexistence
  127. * @return : 0 - success, other - failed
  128. */
  129. int coex_bt_request(uint32_t event, uint32_t latency, uint32_t duration);
  130. /**
  131. * @brief Bluetooth release coexistence.
  132. *
  133. * @param event : Bluetooth event
  134. * @return : 0 - success, other - failed
  135. */
  136. int coex_bt_release(uint32_t event);
  137. #if CONFIG_IDF_TARGET_ESP32
  138. /**
  139. * @brief Bluetooth registers callback function to coexistence module
  140. * This function is only used on ESP32.
  141. *
  142. * @param callback: callback function registered to coexistence module
  143. * @return : 0 - success, other - failed
  144. */
  145. int coex_register_bt_cb(coex_func_cb_t callback);
  146. /**
  147. * @brief To acquire the spin-lock used in resetting Bluetooth baseband.
  148. * This function is only used to workaround ESP32 hardware issue.
  149. *
  150. * @param callback: callback function registered to coexistence module
  151. * @return : value of the spinlock to be restored
  152. */
  153. uint32_t coex_bb_reset_lock(void);
  154. /**
  155. * @brief To release the spin-lock used in resetting Bluetooth baseband.
  156. * This function is only used to workaround ESP32 hardware issue.
  157. *
  158. * @param restore: value of the spinlock returned from previous call of coex_bb_rest_lock
  159. */
  160. void coex_bb_reset_unlock(uint32_t restore);
  161. #endif /* CONFIG_IDF_TARGET_ESP32 */
  162. /**
  163. * @brief Bluetooth registers callback function to receive notification when Wi-Fi channel changes
  164. *
  165. * @param callback: callback function registered to coexistence module
  166. * @return : 0 - success, other - failed
  167. */
  168. int coex_register_wifi_channel_change_callback(coex_wifi_channel_change_cb_t callback);
  169. /**
  170. * @brief Update low power clock interval
  171. */
  172. void coex_update_lpclk_interval(void);
  173. /**
  174. * @brief Get coexistence event duration.
  175. *
  176. * @param event : Coexistence event
  177. * @param duration: Coexistence event duration
  178. * @return : 0 - success, other - failed
  179. */
  180. int coex_event_duration_get(uint32_t event, uint32_t *duration);
  181. #if SOC_COEX_HW_PTI
  182. /**
  183. * @brief Get coexistence event priority.
  184. *
  185. * @param event : Coexistence event
  186. * @param pti: Coexistence event priority
  187. * @return : 0 - success, other - failed
  188. */
  189. int coex_pti_get(uint32_t event, uint8_t *pti);
  190. #endif
  191. /**
  192. * @brief Clear coexistence status.
  193. *
  194. * @param type : Coexistence status type
  195. * @param status: Coexistence status
  196. */
  197. void coex_schm_status_bit_clear(uint32_t type, uint32_t status);
  198. /**
  199. * @brief Set coexistence status.
  200. *
  201. * @param type : Coexistence status type
  202. * @param status: Coexistence status
  203. */
  204. void coex_schm_status_bit_set(uint32_t type, uint32_t status);
  205. /**
  206. * @brief Set coexistence scheme interval.
  207. *
  208. * @param interval : Coexistence scheme interval
  209. * @return : 0 - success, other - failed
  210. */
  211. int coex_schm_interval_set(uint32_t interval);
  212. /**
  213. * @brief Get coexistence scheme interval.
  214. *
  215. * @return : Coexistence scheme interval
  216. */
  217. uint32_t coex_schm_interval_get(void);
  218. /**
  219. * @brief Get current coexistence scheme period.
  220. *
  221. * @return : Coexistence scheme period
  222. */
  223. uint8_t coex_schm_curr_period_get(void);
  224. /**
  225. * @brief Get current coexistence scheme phase.
  226. *
  227. * @return : Coexistence scheme phase
  228. */
  229. void * coex_schm_curr_phase_get(void);
  230. /**
  231. * @brief Set current coexistence scheme phase index.
  232. *
  233. * @param interval : Coexistence scheme phase index
  234. * @return : 0 - success, other - failed
  235. */
  236. int coex_schm_curr_phase_idx_set(int idx);
  237. /**
  238. * @brief Get current coexistence scheme phase index.
  239. *
  240. * @return : Coexistence scheme phase index
  241. */
  242. int coex_schm_curr_phase_idx_get(void);
  243. /**
  244. * @brief Register WiFi callback for coexistence starts.
  245. *
  246. * @param cb : WiFi callback
  247. * @return : 0 - success, other - failed
  248. */
  249. int coex_register_start_cb(int (* cb)(void));
  250. /**
  251. * @brief Restart current coexistence scheme.
  252. *
  253. * @return : 0 - success, other - failed
  254. */
  255. int coex_schm_process_restart(void);
  256. /**
  257. * @brief Register callback for coexistence scheme.
  258. *
  259. * @param type : callback type
  260. * @param callback : callback
  261. * @return : 0 - success, other - failed
  262. */
  263. int coex_schm_register_callback(coex_schm_callback_type_t type, void *callback);
  264. /**
  265. * @brief Register coexistence adapter functions.
  266. *
  267. * @param funcs : coexistence adapter functions
  268. * @return : ESP_OK - success, other - failed
  269. */
  270. esp_err_t esp_coex_adapter_register(coex_adapter_funcs_t *funcs);
  271. #if CONFIG_EXTERNAL_COEX_ENABLE
  272. /**
  273. * @brief Force RX Anttena only in external coex situation.
  274. */
  275. extern void phy_coex_force_rx_ant(void);
  276. /**
  277. * @brief Dismiss RX Anttena only in external coex situation.
  278. */
  279. extern void phy_coex_dismiss_rx_ant(void);
  280. /**
  281. * @brief Set external coexistence advanced informations, like working mode and grant mode in which level.
  282. *
  283. * @param outpti1 Only for slave mode, external coex output priority in level1.
  284. * @param output2 Only for slave mode, external coex output priority in level2.
  285. *
  286. * @return
  287. * - ESP_OK: succeed
  288. */
  289. esp_err_t esp_coex_external_params(esp_external_coex_advance_t coex_info,
  290. uint32_t out_pti1, uint32_t out_pti2);
  291. /**
  292. * @brief Set external coexistence pti level and enable it.
  293. *
  294. * @param level1 external coex low pti
  295. * @param level2 external coex mid pti
  296. * @param level3 external coex high pti
  297. *
  298. * @return
  299. * - ESP_OK: succeed
  300. */
  301. esp_err_t esp_coex_external_set(esp_coex_pti_level_t level1,
  302. esp_coex_pti_level_t level2, esp_coex_pti_level_t level3);
  303. /**
  304. * @brief Disable external coexist
  305. *
  306. * @return
  307. * - ESP_OK: succeed
  308. */
  309. void esp_coex_external_stop(void);
  310. #endif /*External Coex*/
  311. /**
  312. * @brief Check the MD5 values of the coexistence adapter header files in IDF and WiFi library
  313. *
  314. * @attention 1. It is used for internal CI version check
  315. *
  316. * @return
  317. * - ESP_OK : succeed
  318. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  319. */
  320. esp_err_t esp_coex_adapter_funcs_md5_check(const char *md5);
  321. #ifdef __cplusplus
  322. }
  323. #endif
  324. #endif /* __ESP_COEXIST_INTERNAL_H__ */