esp_adapter.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. // Copyright 2015-2018 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <stddef.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <assert.h>
  18. #include <pthread.h>
  19. #include "freertos/FreeRTOS.h"
  20. #include "freertos/task.h"
  21. #include "freertos/queue.h"
  22. #include "freertos/semphr.h"
  23. #include "freertos/event_groups.h"
  24. #include "freertos/xtensa_api.h"
  25. #include "freertos/portmacro.h"
  26. #include "freertos/xtensa_api.h"
  27. #include "esp_types.h"
  28. #include "esp_system.h"
  29. #include "esp_task.h"
  30. #include "esp_intr_alloc.h"
  31. #include "esp_attr.h"
  32. #include "esp_log.h"
  33. #include "esp_event.h"
  34. #include "esp_heap_caps.h"
  35. #include "esp_private/wifi_os_adapter.h"
  36. #include "esp_private/wifi.h"
  37. #include "esp_phy_init.h"
  38. #include "soc/dport_reg.h"
  39. #include "soc/syscon_reg.h"
  40. #include "hal/interrupt_controller_hal.h"
  41. #include "phy_init_data.h"
  42. #include "driver/periph_ctrl.h"
  43. #include "nvs.h"
  44. #include "os.h"
  45. #include "esp_smartconfig.h"
  46. #include "esp_coexist_internal.h"
  47. #include "esp_coexist_adapter.h"
  48. #include "esp32/dport_access.h"
  49. #include "esp_timer.h"
  50. #define TAG "esp_adapter"
  51. #ifdef CONFIG_PM_ENABLE
  52. extern void wifi_apb80m_request(void);
  53. extern void wifi_apb80m_release(void);
  54. #endif
  55. static void IRAM_ATTR s_esp_dport_access_stall_other_cpu_start(void)
  56. {
  57. DPORT_STALL_OTHER_CPU_START();
  58. }
  59. static void IRAM_ATTR s_esp_dport_access_stall_other_cpu_end(void)
  60. {
  61. DPORT_STALL_OTHER_CPU_END();
  62. }
  63. /*
  64. If CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly.
  65. If failed, try to allocate it in internal memory then.
  66. */
  67. IRAM_ATTR void *wifi_malloc( size_t size )
  68. {
  69. #if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
  70. return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
  71. #else
  72. return malloc(size);
  73. #endif
  74. }
  75. /*
  76. If CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly.
  77. If failed, try to allocate it in internal memory then.
  78. */
  79. IRAM_ATTR void *wifi_realloc( void *ptr, size_t size )
  80. {
  81. #if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
  82. return heap_caps_realloc_prefer(ptr, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
  83. #else
  84. return realloc(ptr, size);
  85. #endif
  86. }
  87. /*
  88. If CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP is enabled. Prefer to allocate a chunk of memory in SPIRAM firstly.
  89. If failed, try to allocate it in internal memory then.
  90. */
  91. IRAM_ATTR void *wifi_calloc( size_t n, size_t size )
  92. {
  93. #if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
  94. return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
  95. #else
  96. return calloc(n, size);
  97. #endif
  98. }
  99. static void * IRAM_ATTR wifi_zalloc_wrapper(size_t size)
  100. {
  101. void *ptr = wifi_calloc(1, size);
  102. return ptr;
  103. }
  104. wifi_static_queue_t* wifi_create_queue( int queue_len, int item_size)
  105. {
  106. wifi_static_queue_t *queue = NULL;
  107. queue = (wifi_static_queue_t*)heap_caps_malloc(sizeof(wifi_static_queue_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
  108. if (!queue) {
  109. return NULL;
  110. }
  111. #if CONFIG_SPIRAM_USE_MALLOC
  112. queue->storage = heap_caps_calloc(1, sizeof(StaticQueue_t) + (queue_len*item_size), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
  113. if (!queue->storage) {
  114. goto _error;
  115. }
  116. queue->handle = xQueueCreateStatic( queue_len, item_size, ((uint8_t*)(queue->storage)) + sizeof(StaticQueue_t), (StaticQueue_t*)(queue->storage));
  117. if (!queue->handle) {
  118. goto _error;
  119. }
  120. return queue;
  121. _error:
  122. if (queue) {
  123. if (queue->storage) {
  124. free(queue->storage);
  125. }
  126. free(queue);
  127. }
  128. return NULL;
  129. #else
  130. queue->handle = xQueueCreate( queue_len, item_size);
  131. return queue;
  132. #endif
  133. }
  134. void wifi_delete_queue(wifi_static_queue_t *queue)
  135. {
  136. if (queue) {
  137. vQueueDelete(queue->handle);
  138. #if CONFIG_SPIRAM_USE_MALLOC
  139. if (queue->storage) {
  140. free(queue->storage);
  141. }
  142. #endif
  143. free(queue);
  144. }
  145. }
  146. static void * wifi_create_queue_wrapper(int queue_len, int item_size)
  147. {
  148. return wifi_create_queue(queue_len, item_size);
  149. }
  150. static void wifi_delete_queue_wrapper(void *queue)
  151. {
  152. wifi_delete_queue(queue);
  153. }
  154. static bool IRAM_ATTR env_is_chip_wrapper(void)
  155. {
  156. #ifdef CONFIG_IDF_ENV_FPGA
  157. return false;
  158. #else
  159. return true;
  160. #endif
  161. }
  162. static void set_intr_wrapper(int32_t cpu_no, uint32_t intr_source, uint32_t intr_num, int32_t intr_prio)
  163. {
  164. intr_matrix_set(cpu_no, intr_source, intr_num);
  165. }
  166. static void clear_intr_wrapper(uint32_t intr_source, uint32_t intr_num)
  167. {
  168. }
  169. static void set_isr_wrapper(int32_t n, void *f, void *arg)
  170. {
  171. xt_set_interrupt_handler(n, (xt_handler)f, arg);
  172. }
  173. static void * spin_lock_create_wrapper(void)
  174. {
  175. portMUX_TYPE tmp = portMUX_INITIALIZER_UNLOCKED;
  176. void *mux = heap_caps_malloc(sizeof(portMUX_TYPE), MALLOC_CAP_8BIT|MALLOC_CAP_INTERNAL);
  177. if (mux) {
  178. memcpy(mux,&tmp,sizeof(portMUX_TYPE));
  179. return mux;
  180. }
  181. return NULL;
  182. }
  183. static uint32_t IRAM_ATTR wifi_int_disable_wrapper(void *wifi_int_mux)
  184. {
  185. if (xPortInIsrContext()) {
  186. portENTER_CRITICAL_ISR(wifi_int_mux);
  187. } else {
  188. portENTER_CRITICAL(wifi_int_mux);
  189. }
  190. return 0;
  191. }
  192. static void IRAM_ATTR wifi_int_restore_wrapper(void *wifi_int_mux, uint32_t tmp)
  193. {
  194. if (xPortInIsrContext()) {
  195. portEXIT_CRITICAL_ISR(wifi_int_mux);
  196. } else {
  197. portEXIT_CRITICAL(wifi_int_mux);
  198. }
  199. }
  200. static bool IRAM_ATTR is_from_isr_wrapper(void)
  201. {
  202. return !xPortCanYield();
  203. }
  204. static void IRAM_ATTR task_yield_from_isr_wrapper(void)
  205. {
  206. portYIELD_FROM_ISR();
  207. }
  208. static void * semphr_create_wrapper(uint32_t max, uint32_t init)
  209. {
  210. return (void *)xSemaphoreCreateCounting(max, init);
  211. }
  212. static void semphr_delete_wrapper(void *semphr)
  213. {
  214. vSemaphoreDelete(semphr);
  215. }
  216. static void wifi_thread_semphr_free(void* data)
  217. {
  218. SemaphoreHandle_t *sem = (SemaphoreHandle_t*)(data);
  219. if (sem) {
  220. vSemaphoreDelete(sem);
  221. }
  222. }
  223. static void * wifi_thread_semphr_get_wrapper(void)
  224. {
  225. static bool s_wifi_thread_sem_key_init = false;
  226. static pthread_key_t s_wifi_thread_sem_key;
  227. SemaphoreHandle_t sem = NULL;
  228. if (s_wifi_thread_sem_key_init == false) {
  229. if (0 != pthread_key_create(&s_wifi_thread_sem_key, wifi_thread_semphr_free)) {
  230. return NULL;
  231. }
  232. s_wifi_thread_sem_key_init = true;
  233. }
  234. sem = pthread_getspecific(s_wifi_thread_sem_key);
  235. if (!sem) {
  236. sem = xSemaphoreCreateCounting(1, 0);
  237. if (sem) {
  238. pthread_setspecific(s_wifi_thread_sem_key, sem);
  239. ESP_LOGV(TAG, "thread sem create: sem=%p", sem);
  240. }
  241. }
  242. ESP_LOGV(TAG, "thread sem get: sem=%p", sem);
  243. return (void*)sem;
  244. }
  245. static int32_t IRAM_ATTR semphr_take_from_isr_wrapper(void *semphr, void *hptw)
  246. {
  247. return (int32_t)xSemaphoreTakeFromISR(semphr, hptw);
  248. }
  249. static int32_t IRAM_ATTR semphr_give_from_isr_wrapper(void *semphr, void *hptw)
  250. {
  251. return (int32_t)xSemaphoreGiveFromISR(semphr, hptw);
  252. }
  253. static int32_t semphr_take_wrapper(void *semphr, uint32_t block_time_tick)
  254. {
  255. if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
  256. return (int32_t)xSemaphoreTake(semphr, portMAX_DELAY);
  257. } else {
  258. return (int32_t)xSemaphoreTake(semphr, block_time_tick);
  259. }
  260. }
  261. static int32_t semphr_give_wrapper(void *semphr)
  262. {
  263. return (int32_t)xSemaphoreGive(semphr);
  264. }
  265. static void * recursive_mutex_create_wrapper(void)
  266. {
  267. return (void *)xSemaphoreCreateRecursiveMutex();
  268. }
  269. static void * mutex_create_wrapper(void)
  270. {
  271. return (void *)xSemaphoreCreateMutex();
  272. }
  273. static void mutex_delete_wrapper(void *mutex)
  274. {
  275. vSemaphoreDelete(mutex);
  276. }
  277. static int32_t IRAM_ATTR mutex_lock_wrapper(void *mutex)
  278. {
  279. return (int32_t)xSemaphoreTakeRecursive(mutex, portMAX_DELAY);
  280. }
  281. static int32_t IRAM_ATTR mutex_unlock_wrapper(void *mutex)
  282. {
  283. return (int32_t)xSemaphoreGiveRecursive(mutex);
  284. }
  285. static void * queue_create_wrapper(uint32_t queue_len, uint32_t item_size)
  286. {
  287. return (void *)xQueueCreate(queue_len, item_size);
  288. }
  289. static int32_t queue_send_wrapper(void *queue, void *item, uint32_t block_time_tick)
  290. {
  291. if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
  292. return (int32_t)xQueueSend(queue, item, portMAX_DELAY);
  293. } else {
  294. return (int32_t)xQueueSend(queue, item, block_time_tick);
  295. }
  296. }
  297. static int32_t IRAM_ATTR queue_send_from_isr_wrapper(void *queue, void *item, void *hptw)
  298. {
  299. return (int32_t)xQueueSendFromISR(queue, item, hptw);
  300. }
  301. static int32_t queue_send_to_back_wrapper(void *queue, void *item, uint32_t block_time_tick)
  302. {
  303. return (int32_t)xQueueGenericSend(queue, item, block_time_tick, queueSEND_TO_BACK);
  304. }
  305. static int32_t queue_send_to_front_wrapper(void *queue, void *item, uint32_t block_time_tick)
  306. {
  307. return (int32_t)xQueueGenericSend(queue, item, block_time_tick, queueSEND_TO_FRONT);
  308. }
  309. static int32_t queue_recv_wrapper(void *queue, void *item, uint32_t block_time_tick)
  310. {
  311. if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
  312. return (int32_t)xQueueReceive(queue, item, portMAX_DELAY);
  313. } else {
  314. return (int32_t)xQueueReceive(queue, item, block_time_tick);
  315. }
  316. }
  317. static uint32_t event_group_wait_bits_wrapper(void *event, uint32_t bits_to_wait_for, int clear_on_exit, int wait_for_all_bits, uint32_t block_time_tick)
  318. {
  319. if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
  320. return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, portMAX_DELAY);
  321. } else {
  322. return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, block_time_tick);
  323. }
  324. }
  325. static int32_t task_create_pinned_to_core_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id)
  326. {
  327. return (uint32_t)xTaskCreatePinnedToCore(task_func, name, stack_depth, param, prio, task_handle, (core_id < portNUM_PROCESSORS ? core_id : tskNO_AFFINITY));
  328. }
  329. static int32_t task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle)
  330. {
  331. return (uint32_t)xTaskCreate(task_func, name, stack_depth, param, prio, task_handle);
  332. }
  333. static int32_t IRAM_ATTR task_ms_to_tick_wrapper(uint32_t ms)
  334. {
  335. return (int32_t)(ms / portTICK_PERIOD_MS);
  336. }
  337. static int32_t task_get_max_priority_wrapper(void)
  338. {
  339. return (int32_t)(configMAX_PRIORITIES);
  340. }
  341. static int32_t esp_event_post_wrapper(const char* event_base, int32_t event_id, void* event_data, size_t event_data_size, uint32_t ticks_to_wait)
  342. {
  343. if (ticks_to_wait == OSI_FUNCS_TIME_BLOCKING) {
  344. return (int32_t)esp_event_post(event_base, event_id, event_data, event_data_size, portMAX_DELAY);
  345. } else {
  346. return (int32_t)esp_event_post(event_base, event_id, event_data, event_data_size, ticks_to_wait);
  347. }
  348. }
  349. static void IRAM_ATTR wifi_apb80m_request_wrapper(void)
  350. {
  351. #ifdef CONFIG_PM_ENABLE
  352. wifi_apb80m_request();
  353. #endif
  354. }
  355. static void IRAM_ATTR wifi_apb80m_release_wrapper(void)
  356. {
  357. #ifdef CONFIG_PM_ENABLE
  358. wifi_apb80m_release();
  359. #endif
  360. }
  361. static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat)
  362. {
  363. ets_timer_arm(timer, tmout, repeat);
  364. }
  365. static void IRAM_ATTR timer_disarm_wrapper(void *timer)
  366. {
  367. ets_timer_disarm(timer);
  368. }
  369. static void timer_done_wrapper(void *ptimer)
  370. {
  371. ets_timer_done(ptimer);
  372. }
  373. static void timer_setfn_wrapper(void *ptimer, void *pfunction, void *parg)
  374. {
  375. ets_timer_setfn(ptimer, pfunction, parg);
  376. }
  377. static void IRAM_ATTR timer_arm_us_wrapper(void *ptimer, uint32_t us, bool repeat)
  378. {
  379. ets_timer_arm_us(ptimer, us, repeat);
  380. }
  381. static void wifi_reset_mac_wrapper(void)
  382. {
  383. DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, DPORT_MAC_RST);
  384. DPORT_CLEAR_PERI_REG_MASK(DPORT_CORE_RST_EN_REG, DPORT_MAC_RST);
  385. }
  386. static void wifi_clock_enable_wrapper(void)
  387. {
  388. wifi_module_enable();
  389. }
  390. static void wifi_clock_disable_wrapper(void)
  391. {
  392. wifi_module_disable();
  393. }
  394. static int get_time_wrapper(void *t)
  395. {
  396. return os_get_time(t);
  397. }
  398. static void * IRAM_ATTR malloc_internal_wrapper(size_t size)
  399. {
  400. return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
  401. }
  402. static void * IRAM_ATTR realloc_internal_wrapper(void *ptr, size_t size)
  403. {
  404. return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
  405. }
  406. static void * IRAM_ATTR calloc_internal_wrapper(size_t n, size_t size)
  407. {
  408. return heap_caps_calloc(n, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
  409. }
  410. static void * IRAM_ATTR zalloc_internal_wrapper(size_t size)
  411. {
  412. void *ptr = heap_caps_calloc(1, size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
  413. return ptr;
  414. }
  415. static int coex_init_wrapper(void)
  416. {
  417. #if CONFIG_SW_COEXIST_ENABLE
  418. return coex_init();
  419. #else
  420. return 0;
  421. #endif
  422. }
  423. static void coex_deinit_wrapper(void)
  424. {
  425. #if CONFIG_SW_COEXIST_ENABLE
  426. coex_deinit();
  427. #endif
  428. }
  429. static int coex_enable_wrapper(void)
  430. {
  431. #if CONFIG_SW_COEXIST_ENABLE
  432. return coex_enable();
  433. #else
  434. return 0;
  435. #endif
  436. }
  437. static void coex_disable_wrapper(void)
  438. {
  439. #if CONFIG_SW_COEXIST_ENABLE
  440. coex_disable();
  441. #endif
  442. }
  443. static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
  444. {
  445. #if CONFIG_SW_COEXIST_ENABLE
  446. return coex_status_get();
  447. #else
  448. return 0;
  449. #endif
  450. }
  451. static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
  452. {
  453. #if CONFIG_SW_COEXIST_ENABLE
  454. coex_condition_set(type, dissatisfy);
  455. #endif
  456. }
  457. static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
  458. {
  459. #if CONFIG_SW_COEXIST_ENABLE
  460. return coex_wifi_request(event, latency, duration);
  461. #else
  462. return 0;
  463. #endif
  464. }
  465. static IRAM_ATTR int coex_wifi_release_wrapper(uint32_t event)
  466. {
  467. #if CONFIG_SW_COEXIST_ENABLE
  468. return coex_wifi_release(event);
  469. #else
  470. return 0;
  471. #endif
  472. }
  473. static int coex_wifi_channel_set_wrapper(uint8_t primary, uint8_t secondary)
  474. {
  475. #if CONFIG_SW_COEXIST_ENABLE
  476. return coex_wifi_channel_set(primary, secondary);
  477. #else
  478. return 0;
  479. #endif
  480. }
  481. static IRAM_ATTR int coex_event_duration_get_wrapper(uint32_t event, uint32_t *duration)
  482. {
  483. #if CONFIG_SW_COEXIST_ENABLE
  484. return coex_event_duration_get(event, duration);
  485. #else
  486. return 0;
  487. #endif
  488. }
  489. static int coex_pti_get_wrapper(uint32_t event, uint8_t *pti)
  490. {
  491. return 0;
  492. }
  493. static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status)
  494. {
  495. #if CONFIG_SW_COEXIST_ENABLE
  496. coex_schm_status_bit_clear(type, status);
  497. #endif
  498. }
  499. static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status)
  500. {
  501. #if CONFIG_SW_COEXIST_ENABLE
  502. coex_schm_status_bit_set(type, status);
  503. #endif
  504. }
  505. static IRAM_ATTR int coex_schm_interval_set_wrapper(uint32_t interval)
  506. {
  507. #if CONFIG_SW_COEXIST_ENABLE
  508. return coex_schm_interval_set(interval);
  509. #else
  510. return 0;
  511. #endif
  512. }
  513. static uint32_t coex_schm_interval_get_wrapper(void)
  514. {
  515. #if CONFIG_SW_COEXIST_ENABLE
  516. return coex_schm_interval_get();
  517. #else
  518. return 0;
  519. #endif
  520. }
  521. static uint8_t coex_schm_curr_period_get_wrapper(void)
  522. {
  523. #if CONFIG_SW_COEXIST_ENABLE
  524. return coex_schm_curr_period_get();
  525. #else
  526. return 0;
  527. #endif
  528. }
  529. static void * coex_schm_curr_phase_get_wrapper(void)
  530. {
  531. #if CONFIG_SW_COEXIST_ENABLE
  532. return coex_schm_curr_phase_get();
  533. #else
  534. return NULL;
  535. #endif
  536. }
  537. static int coex_schm_curr_phase_idx_set_wrapper(int idx)
  538. {
  539. #if CONFIG_SW_COEXIST_ENABLE
  540. return coex_schm_curr_phase_idx_set(idx);
  541. #else
  542. return 0;
  543. #endif
  544. }
  545. static int coex_schm_curr_phase_idx_get_wrapper(void)
  546. {
  547. #if CONFIG_SW_COEXIST_ENABLE
  548. return coex_schm_curr_phase_idx_get();
  549. #else
  550. return 0;
  551. #endif
  552. }
  553. static void IRAM_ATTR esp_empty_wrapper(void)
  554. {
  555. }
  556. int32_t IRAM_ATTR coex_is_in_isr_wrapper(void)
  557. {
  558. return !xPortCanYield();
  559. }
  560. wifi_osi_funcs_t g_wifi_osi_funcs = {
  561. ._version = ESP_WIFI_OS_ADAPTER_VERSION,
  562. ._env_is_chip = env_is_chip_wrapper,
  563. ._set_intr = set_intr_wrapper,
  564. ._clear_intr = clear_intr_wrapper,
  565. ._set_isr = set_isr_wrapper,
  566. ._ints_on = interrupt_controller_hal_enable_interrupts,
  567. ._ints_off = interrupt_controller_hal_disable_interrupts,
  568. ._is_from_isr = is_from_isr_wrapper,
  569. ._spin_lock_create = spin_lock_create_wrapper,
  570. ._spin_lock_delete = free,
  571. ._wifi_int_disable = wifi_int_disable_wrapper,
  572. ._wifi_int_restore = wifi_int_restore_wrapper,
  573. ._task_yield_from_isr = task_yield_from_isr_wrapper,
  574. ._semphr_create = semphr_create_wrapper,
  575. ._semphr_delete = semphr_delete_wrapper,
  576. ._semphr_take = semphr_take_wrapper,
  577. ._semphr_give = semphr_give_wrapper,
  578. ._wifi_thread_semphr_get = wifi_thread_semphr_get_wrapper,
  579. ._mutex_create = mutex_create_wrapper,
  580. ._recursive_mutex_create = recursive_mutex_create_wrapper,
  581. ._mutex_delete = mutex_delete_wrapper,
  582. ._mutex_lock = mutex_lock_wrapper,
  583. ._mutex_unlock = mutex_unlock_wrapper,
  584. ._queue_create = queue_create_wrapper,
  585. ._queue_delete = (void(*)(void *))vQueueDelete,
  586. ._queue_send = queue_send_wrapper,
  587. ._queue_send_from_isr = queue_send_from_isr_wrapper,
  588. ._queue_send_to_back = queue_send_to_back_wrapper,
  589. ._queue_send_to_front = queue_send_to_front_wrapper,
  590. ._queue_recv = queue_recv_wrapper,
  591. ._queue_msg_waiting = (uint32_t(*)(void *))uxQueueMessagesWaiting,
  592. ._event_group_create = (void *(*)(void))xEventGroupCreate,
  593. ._event_group_delete = (void(*)(void *))vEventGroupDelete,
  594. ._event_group_set_bits = (uint32_t(*)(void *,uint32_t))xEventGroupSetBits,
  595. ._event_group_clear_bits = (uint32_t(*)(void *,uint32_t))xEventGroupClearBits,
  596. ._event_group_wait_bits = event_group_wait_bits_wrapper,
  597. ._task_create_pinned_to_core = task_create_pinned_to_core_wrapper,
  598. ._task_create = task_create_wrapper,
  599. ._task_delete = (void(*)(void *))vTaskDelete,
  600. ._task_delay = vTaskDelay,
  601. ._task_ms_to_tick = task_ms_to_tick_wrapper,
  602. ._task_get_current_task = (void *(*)(void))xTaskGetCurrentTaskHandle,
  603. ._task_get_max_priority = task_get_max_priority_wrapper,
  604. ._malloc = malloc,
  605. ._free = free,
  606. ._event_post = esp_event_post_wrapper,
  607. ._get_free_heap_size = esp_get_free_internal_heap_size,
  608. ._rand = esp_random,
  609. ._dport_access_stall_other_cpu_start_wrap = s_esp_dport_access_stall_other_cpu_start,
  610. ._dport_access_stall_other_cpu_end_wrap = s_esp_dport_access_stall_other_cpu_end,
  611. ._wifi_apb80m_request = wifi_apb80m_request_wrapper,
  612. ._wifi_apb80m_release = wifi_apb80m_release_wrapper,
  613. ._phy_disable = esp_phy_disable,
  614. ._phy_enable = esp_phy_enable,
  615. ._phy_common_clock_enable = esp_phy_common_clock_enable,
  616. ._phy_common_clock_disable = esp_phy_common_clock_disable,
  617. ._phy_update_country_info = esp_phy_update_country_info,
  618. ._read_mac = esp_read_mac,
  619. ._timer_arm = timer_arm_wrapper,
  620. ._timer_disarm = timer_disarm_wrapper,
  621. ._timer_done = timer_done_wrapper,
  622. ._timer_setfn = timer_setfn_wrapper,
  623. ._timer_arm_us = timer_arm_us_wrapper,
  624. ._wifi_reset_mac = wifi_reset_mac_wrapper,
  625. ._wifi_clock_enable = wifi_clock_enable_wrapper,
  626. ._wifi_clock_disable = wifi_clock_disable_wrapper,
  627. ._wifi_rtc_enable_iso = esp_empty_wrapper,
  628. ._wifi_rtc_disable_iso = esp_empty_wrapper,
  629. ._esp_timer_get_time = esp_timer_get_time,
  630. ._nvs_set_i8 = nvs_set_i8,
  631. ._nvs_get_i8 = nvs_get_i8,
  632. ._nvs_set_u8 = nvs_set_u8,
  633. ._nvs_get_u8 = nvs_get_u8,
  634. ._nvs_set_u16 = nvs_set_u16,
  635. ._nvs_get_u16 = nvs_get_u16,
  636. ._nvs_open = nvs_open,
  637. ._nvs_close = nvs_close,
  638. ._nvs_commit = nvs_commit,
  639. ._nvs_set_blob = nvs_set_blob,
  640. ._nvs_get_blob = nvs_get_blob,
  641. ._nvs_erase_key = nvs_erase_key,
  642. ._get_random = os_get_random,
  643. ._get_time = get_time_wrapper,
  644. ._random = os_random,
  645. ._log_write = esp_log_write,
  646. ._log_writev = esp_log_writev,
  647. ._log_timestamp = esp_log_timestamp,
  648. ._malloc_internal = malloc_internal_wrapper,
  649. ._realloc_internal = realloc_internal_wrapper,
  650. ._calloc_internal = calloc_internal_wrapper,
  651. ._zalloc_internal = zalloc_internal_wrapper,
  652. ._wifi_malloc = wifi_malloc,
  653. ._wifi_realloc = wifi_realloc,
  654. ._wifi_calloc = wifi_calloc,
  655. ._wifi_zalloc = wifi_zalloc_wrapper,
  656. ._wifi_create_queue = wifi_create_queue_wrapper,
  657. ._wifi_delete_queue = wifi_delete_queue_wrapper,
  658. ._coex_init = coex_init_wrapper,
  659. ._coex_deinit = coex_deinit_wrapper,
  660. ._coex_enable = coex_enable_wrapper,
  661. ._coex_disable = coex_disable_wrapper,
  662. ._coex_status_get = coex_status_get_wrapper,
  663. ._coex_condition_set = coex_condition_set_wrapper,
  664. ._coex_wifi_request = coex_wifi_request_wrapper,
  665. ._coex_wifi_release = coex_wifi_release_wrapper,
  666. ._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,
  667. ._coex_event_duration_get = coex_event_duration_get_wrapper,
  668. ._coex_pti_get = coex_pti_get_wrapper,
  669. ._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper,
  670. ._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper,
  671. ._coex_schm_interval_set = coex_schm_interval_set_wrapper,
  672. ._coex_schm_interval_get = coex_schm_interval_get_wrapper,
  673. ._coex_schm_curr_period_get = coex_schm_curr_period_get_wrapper,
  674. ._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper,
  675. ._coex_schm_curr_phase_idx_set = coex_schm_curr_phase_idx_set_wrapper,
  676. ._coex_schm_curr_phase_idx_get = coex_schm_curr_phase_idx_get_wrapper,
  677. ._magic = ESP_WIFI_OS_ADAPTER_MAGIC,
  678. };
  679. coex_adapter_funcs_t g_coex_adapter_funcs = {
  680. ._version = COEX_ADAPTER_VERSION,
  681. ._spin_lock_create = spin_lock_create_wrapper,
  682. ._spin_lock_delete = free,
  683. ._int_disable = wifi_int_disable_wrapper,
  684. ._int_enable = wifi_int_restore_wrapper,
  685. ._task_yield_from_isr = task_yield_from_isr_wrapper,
  686. ._semphr_create = semphr_create_wrapper,
  687. ._semphr_delete = semphr_delete_wrapper,
  688. ._semphr_take_from_isr = semphr_take_from_isr_wrapper,
  689. ._semphr_give_from_isr = semphr_give_from_isr_wrapper,
  690. ._semphr_take = semphr_take_wrapper,
  691. ._semphr_give = semphr_give_wrapper,
  692. ._is_in_isr = coex_is_in_isr_wrapper,
  693. ._malloc_internal = malloc_internal_wrapper,
  694. ._free = free,
  695. ._timer_disarm = timer_disarm_wrapper,
  696. ._timer_done = timer_done_wrapper,
  697. ._timer_setfn = timer_setfn_wrapper,
  698. ._timer_arm_us = timer_arm_us_wrapper,
  699. ._esp_timer_get_time = esp_timer_get_time,
  700. ._magic = COEX_ADAPTER_MAGIC,
  701. };