5
5
#include <string.h>
6
6
#include "espnet.h"
7
7
#include "esp_wifi.h"
8
+ #include "esp_private/wifi.h"
8
9
#include "freertos/FreeRTOS.h"
9
10
#include "freertos/semphr.h"
10
11
#include "freertos/task.h"
@@ -88,23 +89,27 @@ static void _task_yield_from_isr(void) {
88
89
printf ("called: _task_yield_from_isr\n" );
89
90
}
90
91
static void * _semphr_create (uint32_t max , uint32_t init ) {
91
- printf ("called: _semphr_create\n" );
92
- return NULL ;
92
+ return (void * )xSemaphoreCreateCounting (max , init );
93
93
}
94
94
static void _semphr_delete (void * semphr ) {
95
- printf ( "called: _semphr_delete\n" );
95
+ vSemaphoreDelete ( semphr );
96
96
}
97
97
static int32_t _semphr_take (void * semphr , uint32_t block_time_tick ) {
98
- printf ("called: _semphr_take\n" );
99
- return 0 ;
98
+ if (block_time_tick == OSI_FUNCS_TIME_BLOCKING ) {
99
+ return (int32_t )xSemaphoreTake (semphr , portMAX_DELAY );
100
+ } else {
101
+ return (int32_t )xSemaphoreTake (semphr , block_time_tick );
102
+ }
100
103
}
101
104
static int32_t _semphr_give (void * semphr ) {
102
- printf ("called: _semphr_give\n" );
103
- return 0 ;
105
+ return (int32_t )xSemaphoreGive (semphr );
104
106
}
105
107
static void * _wifi_thread_semphr_get (void ) {
106
- printf ("called: _wifi_thread_semphr_get\n" );
107
- return NULL ;
108
+ static SemaphoreHandle_t sem = NULL ;
109
+ if (!sem ) {
110
+ sem = xSemaphoreCreateCounting (1 , 0 );
111
+ }
112
+ return (void * )sem ;
108
113
}
109
114
static void * _mutex_create (void ) {
110
115
printf ("called: _mutex_create\n" );
@@ -131,8 +136,11 @@ static void _queue_delete(void *queue) {
131
136
printf ("called: _queue_delete\n" );
132
137
}
133
138
static int32_t _queue_send (void * queue , void * item , uint32_t block_time_tick ) {
134
- printf ("called: _queue_send\n" );
135
- return 0 ;
139
+ if (block_time_tick == OSI_FUNCS_TIME_BLOCKING ) {
140
+ return (int32_t )xQueueSend (queue , item , portMAX_DELAY );
141
+ } else {
142
+ return (int32_t )xQueueSend (queue , item , block_time_tick );
143
+ }
136
144
}
137
145
static int32_t _queue_send_from_isr (void * queue , void * item , void * hptw ) {
138
146
printf ("called: _queue_send_from_isr\n" );
@@ -147,12 +155,11 @@ static int32_t _queue_send_to_front(void *queue, void *item, uint32_t block_time
147
155
return 0 ;
148
156
}
149
157
static int32_t _queue_recv (void * queue , void * item , uint32_t block_time_tick ) {
150
- printf ("called: _queue_recv\n" );
151
- return 0 ;
152
- }
153
- static uint32_t _queue_msg_waiting (void * queue ) {
154
- printf ("called: _queue_msg_waiting\n" );
155
- return 0 ;
158
+ if (block_time_tick == OSI_FUNCS_TIME_BLOCKING ) {
159
+ return (int32_t )xQueueReceive (queue , item , portMAX_DELAY );
160
+ } else {
161
+ return (int32_t )xQueueReceive (queue , item , block_time_tick );
162
+ }
156
163
}
157
164
static void * _event_group_create (void ) {
158
165
printf ("called: _event_group_create\n" );
@@ -177,8 +184,8 @@ static uint32_t _event_group_wait_bits(void *event, uint32_t bits_to_wait_for, i
177
184
#define P (x ) printf("called: "#x"\n");
178
185
179
186
static int32_t _task_create_pinned_to_core (void * task_func , const char * name , uint32_t stack_depth , void * param , uint32_t prio , void * task_handle , uint32_t core_id ) {
180
- P ( _task_create_pinned_to_core )
181
- return 0 ;
187
+ // Note: using xTaskCreate instead of xTaskCreatePinnedToCore.
188
+ return ( uint32_t ) xTaskCreate ( task_func , name , stack_depth , param , prio , task_handle ) ;
182
189
}
183
190
static int32_t _task_create (void * task_func , const char * name , uint32_t stack_depth , void * param , uint32_t prio , void * task_handle ) {
184
191
P (_task_create )
@@ -187,16 +194,11 @@ static int32_t _task_create(void *task_func, const char *name, uint32_t stack_de
187
194
static void _task_delete (void * task_handle ) {
188
195
P (_task_delete )
189
196
}
190
- static void _task_delay (uint32_t tick ) {
191
- P (_task_delay )
192
- }
193
197
static int32_t _task_ms_to_tick (uint32_t ms ) {
194
- P (_task_ms_to_tick )
195
- return 0 ;
198
+ return (int32_t )(ms / portTICK_PERIOD_MS );
196
199
}
197
200
static int32_t _task_get_max_priority () {
198
- P (_task_get_max_priority )
199
- return 0 ;
201
+ return configMAX_PRIORITIES ;
200
202
}
201
203
static int32_t _event_post (const char * event_base , int32_t event_id , void * event_data , size_t event_data_size , uint32_t ticks_to_wait ) {
202
204
P (_event_post )
@@ -381,11 +383,12 @@ static void* _wifi_zalloc(size_t size) {
381
383
return calloc (1 , size );
382
384
}
383
385
static void * _wifi_create_queue (int queue_len , int item_size ) {
384
- P (_wifi_create_queue )
385
- return NULL ;
386
+ wifi_static_queue_t * queue = (wifi_static_queue_t * )malloc (sizeof (wifi_static_queue_t ));
387
+ queue -> handle = xQueueCreate ( queue_len , item_size );
388
+ return queue ;
386
389
}
387
390
static void _wifi_delete_queue (void * queue ) {
388
- P ( _wifi_delete_queue )
391
+ vQueueDelete ( queue );
389
392
}
390
393
static int _coex_init (void ) {
391
394
P (_coex_init )
@@ -497,7 +500,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
497
500
._queue_send_to_back = _queue_send_to_back ,
498
501
._queue_send_to_front = _queue_send_to_front ,
499
502
._queue_recv = _queue_recv ,
500
- ._queue_msg_waiting = _queue_msg_waiting ,
503
+ ._queue_msg_waiting = ( uint32_t ( * )( void * )) uxQueueMessagesWaiting ,
501
504
._event_group_create = _event_group_create ,
502
505
._event_group_delete = _event_group_delete ,
503
506
._event_group_set_bits = _event_group_set_bits ,
@@ -506,7 +509,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
506
509
._task_create_pinned_to_core = _task_create_pinned_to_core ,
507
510
._task_create = _task_create ,
508
511
._task_delete = _task_delete ,
509
- ._task_delay = _task_delay ,
512
+ ._task_delay = vTaskDelay ,
510
513
._task_ms_to_tick = _task_ms_to_tick ,
511
514
._task_get_current_task = (void * (* )(void ))xTaskGetCurrentTaskHandle ,
512
515
._task_get_max_priority = _task_get_max_priority ,
0 commit comments