Skip to content

Commit 1a1265f

Browse files
committed
Implement enough wrappers to start the WiFi task
The Wifi task is started, but it's still failing: [wifi] ioctl: failed to get wifi thread sem So something is wrong with the WiFi semaphore? Presumably the one created in _wifi_thread_semphr_get.
1 parent 9ae6050 commit 1a1265f

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

espnet/espnet.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <string.h>
66
#include "espnet.h"
77
#include "esp_wifi.h"
8+
#include "esp_private/wifi.h"
89
#include "freertos/FreeRTOS.h"
910
#include "freertos/semphr.h"
1011
#include "freertos/task.h"
@@ -88,23 +89,27 @@ static void _task_yield_from_isr(void) {
8889
printf("called: _task_yield_from_isr\n");
8990
}
9091
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);
9393
}
9494
static void _semphr_delete(void *semphr) {
95-
printf("called: _semphr_delete\n");
95+
vSemaphoreDelete(semphr);
9696
}
9797
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+
}
100103
}
101104
static int32_t _semphr_give(void *semphr) {
102-
printf("called: _semphr_give\n");
103-
return 0;
105+
return (int32_t)xSemaphoreGive(semphr);
104106
}
105107
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+
xSemaphoreCreateCounting(1, 0);
111+
}
112+
return (void*)sem;
108113
}
109114
static void *_mutex_create(void) {
110115
printf("called: _mutex_create\n");
@@ -131,8 +136,11 @@ static void _queue_delete(void *queue) {
131136
printf("called: _queue_delete\n");
132137
}
133138
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+
}
136144
}
137145
static int32_t _queue_send_from_isr(void *queue, void *item, void *hptw) {
138146
printf("called: _queue_send_from_isr\n");
@@ -147,8 +155,11 @@ static int32_t _queue_send_to_front(void *queue, void *item, uint32_t block_time
147155
return 0;
148156
}
149157
static int32_t _queue_recv(void *queue, void *item, uint32_t block_time_tick) {
150-
printf("called: _queue_recv\n");
151-
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+
}
152163
}
153164
static uint32_t _queue_msg_waiting(void *queue) {
154165
printf("called: _queue_msg_waiting\n");
@@ -177,8 +188,8 @@ static uint32_t _event_group_wait_bits(void *event, uint32_t bits_to_wait_for, i
177188
#define P(x) printf("called: "#x"\n");
178189

179190
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;
191+
// Note: using xTaskCreate instead of xTaskCreatePinnedToCore.
192+
return (uint32_t)xTaskCreate(task_func, name, stack_depth, param, prio, task_handle);
182193
}
183194
static int32_t _task_create(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle) {
184195
P(_task_create)
@@ -187,16 +198,12 @@ static int32_t _task_create(void *task_func, const char *name, uint32_t stack_de
187198
static void _task_delete(void *task_handle) {
188199
P(_task_delete)
189200
}
190-
static void _task_delay(uint32_t tick) {
191-
P(_task_delay)
192-
}
193201
static int32_t _task_ms_to_tick(uint32_t ms) {
194202
P(_task_ms_to_tick)
195203
return 0;
196204
}
197205
static int32_t _task_get_max_priority() {
198-
P(_task_get_max_priority)
199-
return 0;
206+
return configMAX_PRIORITIES;
200207
}
201208
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) {
202209
P(_event_post)
@@ -381,11 +388,12 @@ static void* _wifi_zalloc(size_t size) {
381388
return calloc(1, size);
382389
}
383390
static void* _wifi_create_queue(int queue_len, int item_size) {
384-
P(_wifi_create_queue)
385-
return NULL;
391+
wifi_static_queue_t *queue = (wifi_static_queue_t*)malloc(sizeof(wifi_static_queue_t));
392+
queue->handle = xQueueCreate( queue_len, item_size);
393+
return queue;
386394
}
387395
static void _wifi_delete_queue(void * queue) {
388-
P(_wifi_delete_queue)
396+
vQueueDelete(queue);
389397
}
390398
static int _coex_init(void) {
391399
P(_coex_init)
@@ -506,7 +514,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
506514
._task_create_pinned_to_core = _task_create_pinned_to_core,
507515
._task_create = _task_create,
508516
._task_delete = _task_delete,
509-
._task_delay = _task_delay,
517+
._task_delay = vTaskDelay,
510518
._task_ms_to_tick = _task_ms_to_tick,
511519
._task_get_current_task = (void *(*)(void))xTaskGetCurrentTaskHandle,
512520
._task_get_max_priority = _task_get_max_priority,

0 commit comments

Comments
 (0)