From 20575a2986e771d249045c100e2de9a35c8a1908 Mon Sep 17 00:00:00 2001 From: schilkp Date: Fri, 17 May 2024 18:47:03 +0200 Subject: [PATCH] Add traceQUEUE_SEND{_FROM_ISR,}_EXT and traceQUEUE_RESET hooks. The current hooks were not effective at allowing a tracer to track the number of items in a queue, since it could not differentiate between a queueOVERWRITE, queueSEND_TO_BACK, and queueSEND_TO_FRONT send, and could not (efficiently) trace a queue reset. For sends, this adds extended tracing macros that, if not implemented, fall back on the original tracing macros for backwards compatibility, and introduces a new traceQUEUE_RESET hook. Discussed here: https://forums.freertos.org/t/queue-tracing/20054/4 --- include/FreeRTOS.h | 16 ++++++++++++++++ queue.c | 8 +++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/include/FreeRTOS.h b/include/FreeRTOS.h index b972ffd10..02e459a83 100644 --- a/include/FreeRTOS.h +++ b/include/FreeRTOS.h @@ -769,6 +769,12 @@ #define traceQUEUE_SEND( pxQueue ) #endif +/* Extended version of traceQUEUE_SEND that also reports the copy position + * of the sent data. */ +#ifndef traceQUEUE_SEND_EXT + #define traceQUEUE_SEND_EXT( pxQueue, xCopyPosition ) traceQUEUE_SEND( pxQueue ) +#endif + #ifndef traceQUEUE_SEND_FAILED #define traceQUEUE_SEND_FAILED( pxQueue ) #endif @@ -797,6 +803,12 @@ #define traceQUEUE_SEND_FROM_ISR( pxQueue ) #endif +/* Extended version of traceQUEUE_SEND_FROM_ISR that also reports the copy + * position of the sent data. */ +#ifndef traceQUEUE_SEND_FROM_ISR_EXT + #define traceQUEUE_SEND_FROM_ISR_EXT( pxQueue, xCopyPosition ) traceQUEUE_SEND_FROM_ISR( pxQueue ) +#endif + #ifndef traceQUEUE_SEND_FROM_ISR_FAILED #define traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ) #endif @@ -813,6 +825,10 @@ #define traceQUEUE_PEEK_FROM_ISR_FAILED( pxQueue ) #endif +#ifndef traceQUEUE_RESET + #define traceQUEUE_RESET( pxQueue, xNewQueue ) +#endif + #ifndef traceQUEUE_DELETE #define traceQUEUE_DELETE( pxQueue ) #endif diff --git a/queue.c b/queue.c index dd302c908..1ccf96f90 100644 --- a/queue.c +++ b/queue.c @@ -315,6 +315,8 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue, /* Check for multiplication overflow. */ ( ( SIZE_MAX / pxQueue->uxLength ) >= pxQueue->uxItemSize ) ) { + traceQUEUE_RESET( pxQueue, xNewQueue ); + taskENTER_CRITICAL(); { pxQueue->u.xQueue.pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize ); @@ -966,7 +968,7 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue, * queue is full. */ if( ( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) || ( xCopyPosition == queueOVERWRITE ) ) { - traceQUEUE_SEND( pxQueue ); + traceQUEUE_SEND_EXT( pxQueue, xCopyPosition ); #if ( configUSE_QUEUE_SETS == 1 ) { @@ -1200,7 +1202,7 @@ BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const int8_t cTxLock = pxQueue->cTxLock; const UBaseType_t uxPreviousMessagesWaiting = pxQueue->uxMessagesWaiting; - traceQUEUE_SEND_FROM_ISR( pxQueue ); + traceQUEUE_SEND_FROM_ISR_EXT( pxQueue, xCopyPosition ); /* Semaphores use xQueueGiveFromISR(), so pxQueue will not be a * semaphore or mutex. That means prvCopyDataToQueue() cannot result @@ -1382,7 +1384,7 @@ BaseType_t xQueueGiveFromISR( QueueHandle_t xQueue, { const int8_t cTxLock = pxQueue->cTxLock; - traceQUEUE_SEND_FROM_ISR( pxQueue ); + traceQUEUE_SEND_FROM_ISR_EXT( pxQueue, queueSEND_TO_BACK ); /* A task can only have an inherited priority if it is a mutex * holder - and if there is a mutex holder then the mutex cannot be