1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-26 23:11:19 +01:00

cpu/esp_common/freertos: add xQueueReset function

This commit is contained in:
Gunar Schorcht 2022-06-17 07:13:10 +02:00
parent e4f1a94219
commit 02e52513d1
2 changed files with 49 additions and 2 deletions

View File

@ -110,6 +110,50 @@ void vQueueDelete( QueueHandle_t xQueue )
free(xQueue);
}
BaseType_t IRAM_ATTR xQueueReset( QueueHandle_t xQueue )
{
DEBUG("%s pid=%d queue=%p\n", __func__, thread_getpid(), xQueue);
assert(xQueue != NULL);
vTaskEnterCritical(0);
_queue_t* queue = (_queue_t*)xQueue;
queue->item_front = 0;
queue->item_tail = 0;
queue->item_level = 0;
/* return if there is no waiting sending thread */
if (queue->sending.next == NULL) {
DEBUG("%s pid=%d queue=%p return pdPASS\n", __func__,
thread_getpid(), xQueue);
vTaskExitCritical(0);
return pdPASS;
}
/* otherwise unlock the waiting sending thread */
list_node_t *next = list_remove_head(&queue->sending);
thread_t *proc = container_of((clist_node_t*)next, thread_t, rq_entry);
sched_set_status(proc, STATUS_PENDING);
/* test whether context switch is required */
bool ctx_switch = proc->priority < thread_get_priority(thread_get_active());
DEBUG("%s pid=%d queue=%p unlock waiting pid=%d switch=%d\n",
__func__, thread_getpid(), xQueue, proc->pid, ctx_switch);
if (ctx_switch) {
vTaskExitCritical(0);
/* sets only the sched_context_switch_request in ISRs */
sched_switch(proc->priority);
}
else {
vTaskExitCritical(0);
}
return pdPASS;
}
BaseType_t IRAM_ATTR _queue_generic_send(QueueHandle_t xQueue,
const void * const pvItemToQueue,
const BaseType_t xCopyPosition,

View File

@ -32,7 +32,7 @@ QueueHandle_t xQueueCreateCountingSemaphore (const UBaseType_t uxMaxCount,
void vQueueDelete (QueueHandle_t xQueue);
BaseType_t xQueueGenericReset (QueueHandle_t xQueue, BaseType_t xNewQueue);
BaseType_t xQueueReset (QueueHandle_t xQueue);
BaseType_t xQueueGenericReceive (QueueHandle_t xQueue,
void * const pvBuffer,
@ -108,7 +108,10 @@ UBaseType_t uxQueueMessagesWaiting( QueueHandle_t xQueue );
( pxHigherPriorityTaskWoken ), \
queueSEND_TO_BACK )
#define xQueueReset( xQueue ) xQueueGenericReset( xQueue, pdFALSE )
#define xQueueOverwriteFromISR( xQueue, pvItemToQueue, pxHigherPriorityTaskWoken ) \
xQueueGenericSendFromISR( ( xQueue ), ( pvItemToQueue ), \
( pxHigherPriorityTaskWoken ), \
queueOVERWRITE )
#ifdef __cplusplus
}