esp_coexist_internal.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /*
  2. * SPDX-FileCopyrightText: 2018-2023 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 "private/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 WiFi requests coexistence.
  80. *
  81. * @param event : WiFi event
  82. * @param latency : WiFi will request coexistence after latency
  83. * @param duration : duration for WiFi to request coexistence
  84. * @return : 0 - success, other - failed
  85. */
  86. int coex_wifi_request(uint32_t event, uint32_t latency, uint32_t duration);
  87. /**
  88. * @brief WiFi release coexistence.
  89. *
  90. * @param event : WiFi event
  91. * @return : 0 - success, other - failed
  92. */
  93. int coex_wifi_release(uint32_t event);
  94. /**
  95. * @brief Set WiFi channel to coexistence module.
  96. *
  97. * @param primary : WiFi primary channel
  98. * @param secondary : WiFi secondary channel
  99. * @return : 0 - success, other - failed
  100. */
  101. int coex_wifi_channel_set(uint8_t primary, uint8_t secondary);
  102. /**
  103. * @brief Get WiFi channel from coexistence module.
  104. *
  105. * @param primary : pointer to value of WiFi primary channel
  106. * @param secondary : pointer to value of WiFi secondary channel
  107. * @return : 0 - success, other - failed
  108. */
  109. int coex_wifi_channel_get(uint8_t *primary, uint8_t *secondary);
  110. /**
  111. * @brief Register application callback function to Wi-Fi update low power clock module.
  112. *
  113. * @param callback : Wi-Fi update low power clock callback function
  114. */
  115. void coex_wifi_register_update_lpclk_callback(coex_set_lpclk_source_callback_t callback);
  116. /**
  117. * @brief Bluetooth requests coexistence
  118. *
  119. * @param event : Bluetooth event
  120. * @param latency : Bluetooth will request coexistence after latency
  121. * @param duration : duration for Bluetooth to request coexistence
  122. * @return : 0 - success, other - failed
  123. */
  124. int coex_bt_request(uint32_t event, uint32_t latency, uint32_t duration);
  125. /**
  126. * @brief Bluetooth release coexistence.
  127. *
  128. * @param event : Bluetooth event
  129. * @return : 0 - success, other - failed
  130. */
  131. int coex_bt_release(uint32_t event);
  132. #if CONFIG_IDF_TARGET_ESP32
  133. /**
  134. * @brief Bluetooth registers callback function to coexistence module
  135. * This function is only used on ESP32.
  136. *
  137. * @param callback: callback function registered to coexistence module
  138. * @return : 0 - success, other - failed
  139. */
  140. int coex_register_bt_cb(coex_func_cb_t callback);
  141. /**
  142. * @brief To acquire the spin-lock used in resetting Bluetooth baseband.
  143. * This function is only used to workaround ESP32 hardware issue.
  144. *
  145. * @return : value of the spinlock to be restored
  146. */
  147. uint32_t coex_bb_reset_lock(void);
  148. /**
  149. * @brief To release the spin-lock used in resetting Bluetooth baseband.
  150. * This function is only used to workaround ESP32 hardware issue.
  151. *
  152. * @param restore: value of the spinlock returned from previous call of coex_bb_rest_lock
  153. */
  154. void coex_bb_reset_unlock(uint32_t restore);
  155. #endif /* CONFIG_IDF_TARGET_ESP32 */
  156. /**
  157. * @brief Bluetooth registers callback function to receive notification when Wi-Fi channel changes
  158. *
  159. * @param callback: callback function registered to coexistence module
  160. * @return : 0 - success, other - failed
  161. */
  162. int coex_register_wifi_channel_change_callback(coex_wifi_channel_change_cb_t callback);
  163. /**
  164. * @brief Update low power clock interval
  165. */
  166. void coex_update_lpclk_interval(void);
  167. /**
  168. * @brief Get coexistence event duration.
  169. *
  170. * @param event : Coexistence event
  171. * @param duration: Coexistence event duration
  172. * @return : 0 - success, other - failed
  173. */
  174. int coex_event_duration_get(uint32_t event, uint32_t *duration);
  175. #if SOC_COEX_HW_PTI
  176. /**
  177. * @brief Get coexistence event priority.
  178. *
  179. * @param event : Coexistence event
  180. * @param pti: Coexistence event priority
  181. * @return : 0 - success, other - failed
  182. */
  183. int coex_pti_get(uint32_t event, uint8_t *pti);
  184. #endif
  185. /**
  186. * @brief Clear coexistence status.
  187. *
  188. * @param type : Coexistence status type
  189. * @param status: Coexistence status
  190. */
  191. void coex_schm_status_bit_clear(uint32_t type, uint32_t status);
  192. /**
  193. * @brief Set coexistence status.
  194. *
  195. * @param type : Coexistence status type
  196. * @param status: Coexistence status
  197. */
  198. void coex_schm_status_bit_set(uint32_t type, uint32_t status);
  199. /**
  200. * @brief Set coexistence scheme interval.
  201. *
  202. * @param interval : Coexistence scheme interval
  203. * @return : 0 - success, other - failed
  204. */
  205. int coex_schm_interval_set(uint32_t interval);
  206. /**
  207. * @brief Get coexistence scheme interval.
  208. *
  209. * @return : Coexistence scheme interval
  210. */
  211. uint32_t coex_schm_interval_get(void);
  212. /**
  213. * @brief Get current coexistence scheme period.
  214. *
  215. * @return : Coexistence scheme period
  216. */
  217. uint8_t coex_schm_curr_period_get(void);
  218. /**
  219. * @brief Get current coexistence scheme phase.
  220. *
  221. * @return : Coexistence scheme phase
  222. */
  223. void * coex_schm_curr_phase_get(void);
  224. /**
  225. * @brief Set current coexistence scheme phase index.
  226. *
  227. * @param idx : Coexistence scheme phase index
  228. * @return : 0 - success, other - failed
  229. */
  230. int coex_schm_curr_phase_idx_set(int idx);
  231. /**
  232. * @brief Get current coexistence scheme phase index.
  233. *
  234. * @return : Coexistence scheme phase index
  235. */
  236. int coex_schm_curr_phase_idx_get(void);
  237. /**
  238. * @brief Register WiFi callback for coexistence starts.
  239. *
  240. * @param cb : WiFi callback
  241. * @return : 0 - success, other - failed
  242. */
  243. int coex_register_start_cb(int (* cb)(void));
  244. /**
  245. * @brief Restart current coexistence scheme.
  246. *
  247. * @return : 0 - success, other - failed
  248. */
  249. int coex_schm_process_restart(void);
  250. /**
  251. * @brief Register callback for coexistence scheme.
  252. *
  253. * @param type : callback type
  254. * @param callback : callback
  255. * @return : 0 - success, other - failed
  256. */
  257. int coex_schm_register_callback(coex_schm_callback_type_t type, void *callback);
  258. /**
  259. * @brief Register coexistence adapter functions.
  260. *
  261. * @param funcs : coexistence adapter functions
  262. * @return : ESP_OK - success, other - failed
  263. */
  264. esp_err_t esp_coex_adapter_register(coex_adapter_funcs_t *funcs);
  265. #if CONFIG_EXTERNAL_COEX_ENABLE
  266. /**
  267. * @brief Set external coexistence advanced informations, like working mode.
  268. *
  269. * @param out_pti1 This parameter no longer works, will be deprecated and later removed in future releases.
  270. * @param out_pti2 This parameter no longer works, will be deprecated and later removed in future releases.
  271. *
  272. * @return
  273. * - ESP_OK: succeed
  274. */
  275. esp_err_t esp_coex_external_params(esp_external_coex_advance_t coex_info, uint32_t out_pti1, uint32_t out_pti2);
  276. /**
  277. * @brief Set external coexistence pti level and enable it.
  278. *
  279. * @param level1 external coex low pti
  280. * @param level2 external coex mid pti
  281. * @param level3 external coex high pti
  282. *
  283. * @return
  284. * - ESP_OK: succeed
  285. */
  286. esp_err_t esp_coex_external_set(esp_coex_pti_level_t level1,
  287. esp_coex_pti_level_t level2, esp_coex_pti_level_t level3);
  288. /**
  289. * @brief Disable external coexist
  290. *
  291. * @return
  292. * - ESP_OK: succeed
  293. */
  294. void esp_coex_external_stop(void);
  295. /**
  296. * @brief Set external coexistence wire type.
  297. *
  298. * @param wire_type Set external coexistence wire type.
  299. *
  300. */
  301. void esp_coex_external_set_wire_type(external_coex_wire_t wire_type);
  302. #if SOC_EXTERNAL_COEX_LEADER_TX_LINE
  303. /**
  304. * @brief Enable external coexist tx line
  305. *
  306. * @param en Enable external coex tx line
  307. *
  308. * @return
  309. * - ESP_OK: succeed
  310. */
  311. void esp_coex_external_set_txline(bool en);
  312. #endif /*SOC_EXTERNAL_COEX_LEADER_TX_LINE*/
  313. #endif /*External Coex*/
  314. /**
  315. * @brief Check the MD5 values of the coexistence adapter header files in IDF and WiFi library
  316. *
  317. * @attention 1. It is used for internal CI version check
  318. *
  319. * @return
  320. * - ESP_OK : succeed
  321. * - ESP_WIFI_INVALID_ARG : MD5 check fail
  322. */
  323. esp_err_t esp_coex_adapter_funcs_md5_check(const char *md5);
  324. #ifdef __cplusplus
  325. }
  326. #endif
  327. #endif /* __ESP_COEXIST_INTERNAL_H__ */