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