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