Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/rp2_common/pico_async_context/async_context_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ static void async_context_task(__unused void *vself) {
async_context_freertos_release_lock(&self->core);
__sev(); // it is possible regular code is waiting on a WFE on the other core
} while (!self->task_should_exit);
xSemaphoreGive(self->task_complete_sem);
vTaskDelete(NULL);
}

Expand Down Expand Up @@ -113,6 +114,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f
assert(config->task_stack);
self->lock_mutex = xSemaphoreCreateRecursiveMutexStatic(&self->lock_mutex_buf);
self->work_needed_sem = xSemaphoreCreateBinaryStatic(&self->work_needed_sem_buf);
self->task_complete_sem = xSemaphoreCreateBinaryStatic(&self->task_complete_sem_buf);
self->timer_handle = xTimerCreateStatic( "async_context_timer", // Just a text name, not used by the kernel.
portMAX_DELAY,
pdFALSE, // The timers will auto-reload themselves when they expire.
Expand All @@ -129,6 +131,7 @@ bool async_context_freertos_init(async_context_freertos_t *self, async_context_f
#else
self->lock_mutex = xSemaphoreCreateRecursiveMutex();
self->work_needed_sem = xSemaphoreCreateBinary();
self->task_complete_sem = xSemaphoreCreateBinary();
self->timer_handle = xTimerCreate( "async_context_timer", // Just a text name, not used by the kernel.
portMAX_DELAY,
pdFALSE, // The timers will auto-reload themselves when they expire.
Expand Down Expand Up @@ -171,6 +174,9 @@ void async_context_freertos_deinit(async_context_t *self_base) {
async_context_freertos_t *self = (async_context_freertos_t *)self_base;
if (self->task_handle) {
async_context_execute_sync(self_base, end_task_func, self_base);
if (self->task_complete_sem) {
xSemaphoreTake(self->task_complete_sem, portMAX_DELAY);
}
}
if (self->timer_handle) {
xTimerDelete(self->timer_handle, 0);
Expand All @@ -181,6 +187,9 @@ void async_context_freertos_deinit(async_context_t *self_base) {
if (self->work_needed_sem) {
vSemaphoreDelete(self->work_needed_sem);
}
if (self->task_complete_sem) {
vSemaphoreDelete(self->task_complete_sem);
}
memset(self, 0, sizeof(*self));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ struct async_context_freertos {
async_context_t core;
SemaphoreHandle_t lock_mutex;
SemaphoreHandle_t work_needed_sem;
SemaphoreHandle_t task_complete_sem;
TimerHandle_t timer_handle;
TaskHandle_t task_handle;
#if configSUPPORT_STATIC_ALLOCATION
StaticSemaphore_t lock_mutex_buf;
StaticSemaphore_t work_needed_sem_buf;
StaticSemaphore_t task_complete_sem_buf;
StaticTimer_t timer_buf;
StaticTask_t task_buf;
#endif
Expand Down
Loading