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