From ad48deccfa65c3314561cb375b74c8f79af1484e Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Mon, 13 Mar 2023 14:33:33 +0800 Subject: [PATCH 1/5] Add functions to get the buffers of statically created objects Added various ...GetStaticBuffer() functions to get the buffers of statically created objects. --- .github/lexicon.txt | 18 +++++++++++++++ event_groups.c | 36 +++++++++++++++++++++++++++++ include/event_groups.h | 23 +++++++++++++++++++ include/message_buffer.h | 31 +++++++++++++++++++++++++ include/queue.h | 41 +++++++++++++++++++++++++++++++++ include/semphr.h | 21 +++++++++++++++++ include/stream_buffer.h | 41 +++++++++++++++++++++++++++++++++ include/task.h | 30 ++++++++++++++++++++++++ include/timers.h | 20 ++++++++++++++++ queue.c | 49 ++++++++++++++++++++++++++++++++++++++++ stream_buffer.c | 28 +++++++++++++++++++++++ tasks.c | 31 +++++++++++++++++++++++++ timers.c | 24 ++++++++++++++++++++ 13 files changed, 393 insertions(+) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index 47d2349bfff..ac9047b8352 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -1464,13 +1464,24 @@ ppdc ppio ppitc ppmc +ppucmessagebufferstoragearea +ppucqueuestorage +ppucstreambufferstoragearea ppudr ppuer ppusr +ppuxstackbuffer ppvdestination ppwm +ppxeventgroupbuffer ppxidletaskstackbuffer ppxidletasktcbbuffer +ppxsemaphorebuffer +ppxstaticmessagebuffer +ppxstaticqueue +ppxstaticstreambuffer +ppxtaskbuffer +ppxtimerbuffer ppxtimertaskstackbuffer ppxtimertasktcbbuffer pr @@ -2723,6 +2734,7 @@ xeventgroupcreatestatic xeventgroupdelete xeventgroupgetbits xeventgroupgetbitsfromisr +xeventgroupgetstaticbuffer xeventgroupsetbits xeventgroupsetbitsfromisr xeventgroupsync @@ -2796,6 +2808,7 @@ xmessage xmessagebuffer xmessagebuffercreate xmessagebuffercreatestatic +xmessagebuffergetstaticbuffers xmessagebufferisempty xmessagebufferisfull xmessagebuffernextlengthbytes @@ -2865,6 +2878,7 @@ xqueuecreatestatic xqueuegenericsend xqueuegenericsendfromisr xqueuegetmutexholder +xqueuegetstaticbuffers xqueuegivefromisr xqueuegivemutexrecursive xqueueorsemaphore @@ -2919,6 +2933,7 @@ xsemaphorecreaterecursivemutex xsemaphorecreaterecursivemutexstatic xsemaphoregetmutexholder xsemaphoregetmutexholderfromisr +xsemaphoregetstaticbuffer xsemaphoregive xsemaphoregivefromisr xsemaphoregivemutexrecursive @@ -2943,6 +2958,7 @@ xstreambuffer xstreambufferbytesavailable xstreambuffercreate xstreambuffercreatestatic +xstreambuffergetstaticbuffers xstreambufferisempty xstreambufferisfull xstreambuffernextmessagelengthbytes @@ -2981,6 +2997,7 @@ xtaskgetcurrenttaskhandle xtaskgethandle xtaskgetidletaskhandle xtaskgetschedulerstate +xtaskgetstaticbuffers xtaskgettickcount xtaskgettickcountfromisr xtaskhandle @@ -3048,6 +3065,7 @@ xtimerdelete xtimergetexpirytime xtimergetperiod xtimergetreloadmode +xtimergetstaticbuffer xtimergettimerdaemontaskhandle xtimeristimeractive xtimerlistitem diff --git a/event_groups.c b/event_groups.c index 7c86e605a88..e52f04f6ff1 100644 --- a/event_groups.c +++ b/event_groups.c @@ -677,6 +677,42 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup ) } /*-----------------------------------------------------------*/ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup, + StaticEventGroup_t ** ppxEventGroupBuffer ) + { + BaseType_t xReturn; + EventGroup_t * pxEventBits = xEventGroup; + + configASSERT( pxEventBits ); + configASSERT( ppxEventGroupBuffer ); + + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Check if the event group was statically allocated */ + if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE ) + { + *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + #else /* configSUPPORT_DYNAMIC_ALLOCATION */ + { + /* Event group must have been statically allocated */ + *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits; + xReturn = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + return xReturn; + } +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + /* For internal use only - execute a 'set bits' command that was pended from * an interrupt. */ void vEventGroupSetBitsCallback( void * pvEventGroup, diff --git a/include/event_groups.h b/include/event_groups.h index 3f37d90be5d..2b8949fd2d2 100644 --- a/include/event_groups.h +++ b/include/event_groups.h @@ -763,6 +763,29 @@ EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEG */ void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; +/** + * event_groups.h + * @code{c} + * BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup, + * StaticEventGroup_t ** ppxEventGroupBuffer ); + * @endcode + * + * This function fetches a pointer to the memory buffer of a statically created + * event group. + * + * @param xEventGroup The handle of the event group + * + * @param ppxEventGroupBuffer Used to pass back a pointer to the event groups's + * data structure buffer. + * + * @return pdTRUE if the buffer were fetched. pdFALSE if the event group was not + * statically created. + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup, + StaticEventGroup_t ** ppxEventGroupBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + /* For internal use only. */ void vEventGroupSetBitsCallback( void * pvEventGroup, const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION; diff --git a/include/message_buffer.h b/include/message_buffer.h index b56dd35964e..8a514efeb67 100644 --- a/include/message_buffer.h +++ b/include/message_buffer.h @@ -245,6 +245,37 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, pdTRUE, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) #endif +/** + * message_buffer.h + * + * @code{c} + * BaseType_t xMessageBufferGetStaticBuffers( MessageBufferHandle_t xMessageBuffer, + * uint8_t ** ppucMessageBufferStorageArea, + * StaticMessageBuffer_t ** ppxStaticMessageBuffer ); + * @endcode + * + * This function fetches the pointers to the memory buffers of a statically + * created message buffer. + * + * @param xMessageBuffer The handle to the message buffer + * + * @param ppucMessageBufferStorageArea Used to pass back a pointer to the + * message buffer's storage area buffer. + * + * @param ppxStaticMessageBuffer Used to pass back a pointer to the message + * buffer's data structure buffer. + * + * @return pdTRUE if buffers were fetched. pdFALSE if the message buffer was not + * statically created. + * + * \defgroup xMessageBufferGetStaticBuffers xMessageBufferGetStaticBuffers + * \ingroup MessageBufferManagement + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xMessageBufferGetStaticBuffers( xMessageBuffer, ppucMessageBufferStorageArea, ppxStaticMessageBuffer ) \ + xStreamBufferGenericGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + /** * message_buffer.h * diff --git a/include/queue.h b/include/queue.h index f488a2e7641..df695c9fa69 100644 --- a/include/queue.h +++ b/include/queue.h @@ -235,6 +235,35 @@ typedef struct QueueDefinition * QueueSetMemberHandle_t; #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) ) #endif /* configSUPPORT_STATIC_ALLOCATION */ +/** + * queue. h + * @code{c} + * BaseType_t xQueueGetStaticBuffers( QueueHandle_t xQueue, + * uint8_t ** ppucQueueStorage, + * StaticQueue_t ** ppxStaticQueue ); + * @endcode + * + * This function fetches the pointers to the memory buffers of a statically + * created queue. + * + * @param xQueue The handle to the queue + * + * @param ppucQueueStorage Used to pass back a pointer to the queue's storage + * area buffer. + * + * @param ppxStaticQueue Used to pass back a pointer to the queue's data + * structure buffer. + * + * @return pdTRUE if buffers were fetched. pdFALSE if the queue was not + * created using xQueueCreateStatic(). + * + * \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers + * \ingroup QueueManagement + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xQueueGetStaticBuffers( xQueue, ppucQueueStorage, ppxStaticQueue ) xQueueGenericGetStaticBuffers( ( xQueue ), ( ppucQueueStorage ), ( ppxStaticQueue ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + /** * queue. h * @code{c} @@ -1542,6 +1571,18 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION; const uint8_t ucQueueType ) PRIVILEGED_FUNCTION; #endif +/* + * Generic version of the function used to get the buffers of statically created + * queues. This is called by other functions and macros that get the buffers + * of other statically created RTOS objects that use the queue structure as + * their base. + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue, + uint8_t ** ppucQueueStorage, + StaticQueue_t ** ppxStaticQueue ) PRIVILEGED_FUNCTION; +#endif + /* * Queue sets provide a mechanism to allow a task to block (pend) on a read * operation from multiple queues or semaphores simultaneously. diff --git a/include/semphr.h b/include/semphr.h index c2206fa98ff..34f49708b72 100644 --- a/include/semphr.h +++ b/include/semphr.h @@ -1190,4 +1190,25 @@ typedef QueueHandle_t SemaphoreHandle_t; */ #define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) ) +/** + * semphr.h + * @code{c} + * BaseType_t xSemaphoreGetStaticBuffer( SemaphoreHandle_t xSemaphore ); + * @endcode + * + * This function fetches a pointer to the memory buffer of a statically created + * binary semaphore, counting semaphore, or mutex semaphore. + * + * @param xSemaphore The handle of the statically created semaphore + * + * @param ppxSemaphoreBuffer Used to pass back a pointer to the semaphore's + * data structure buffer + * + * @return pdTRUE if buffer was fetched. pdFALSE if the semaphore was not + * statically allocated. + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xSemaphoreGetStaticBuffer( xSemaphore, ppxSemaphoreBuffer ) xQueueGenericGetStaticBuffers( ( QueueHandle_t ) ( xSemaphore ), NULL, ( ppxSemaphoreBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + #endif /* SEMAPHORE_H */ diff --git a/include/stream_buffer.h b/include/stream_buffer.h index d65ed9e9cec..28a9e1662bc 100644 --- a/include/stream_buffer.h +++ b/include/stream_buffer.h @@ -260,6 +260,37 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) ) #endif +/** + * stream_buffer.h + * + * @code{c} + * BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, + * uint8_t ** ppucStreamBufferStorageArea, + * StaticStreamBuffer_t ** ppxStaticStreamBuffer ); + * @endcode + * + * This function fetches the pointers to the memory buffers of a statically + * created stream buffer. + * + * @param xStreamBuffer The handle to the stream buffer + * + * @param ppucStreamBufferStorageArea Used to pass back a pointer to the stream + * buffer's storage area buffer. + * + * @param ppxStaticStreamBuffer Used to pass back a pointer to the stream + * buffer's data structure buffer. + * + * @return pdTRUE if buffers were fetched. pdFALSE if the stream buffer was not + * statically created. + * + * \defgroup xStreamBufferGetStaticBuffers xStreamBufferGetStaticBuffers + * \ingroup StreamBufferManagement + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + #define xStreamBufferGetStaticBuffers( xStreamBuffer, ppucStreamBufferStorageArea, ppxStaticStreamBuffer ) \ + xStreamBufferGenericGetStaticBuffers( ( xStreamBuffer ), ( ppucStreamBufferStorageArea ), ( ppxStaticStreamBuffer ) ) +#endif /* configSUPPORT_STATIC_ALLOCATION */ + /** * stream_buffer.h * @@ -895,6 +926,16 @@ StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION; +/* + * Generic version of the function used to get the buffers of statically created + * stream or message buffer. + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xStreamBufferGenericGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, + uint8_t ** ppucStreamBufferStorageArea, + StaticStreamBuffer_t ** ppxStaticStreamBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; #if ( configUSE_TRACE_FACILITY == 1 ) diff --git a/include/task.h b/include/task.h index 08c14dd6ff1..1ca017b5e42 100644 --- a/include/task.h +++ b/include/task.h @@ -1509,6 +1509,36 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e */ TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ +/** + * task. h + * @code{c} + * BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask, + * StackType_t ** ppuxStackBuffer, + * StaticTask_t ** ppxTaskBuffer ); + * @endcode + * + * This function fetches a pointer to the memory buffers of a statically created + * task. + * + * @param xTask The handle of the statically created task + * + * @param ppuxStackBuffer Used to pass back a pointer to the task's stack buffer + * + * @param ppxTaskBuffer Used to pass back a pointer to the task's data structure + * buffer + * + * @return pdTRUE if buffers were fetched. pdFALSE if the task was not + * statically created. + * + * \defgroup xTaskGetStaticBuffers xTaskGetStaticBuffers + * \ingroup TaskUtils + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask, + StackType_t ** ppuxStackBuffer, + StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + /** * task.h * @code{c} diff --git a/include/timers.h b/include/timers.h index 6a064d62a41..94fc37216cf 100644 --- a/include/timers.h +++ b/include/timers.h @@ -1323,6 +1323,26 @@ TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; */ TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; +/** + * BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer, + * StaticTimer_t ** ppxTimerBuffer ); + * + * This function fetches a pointer to the memory buffer of a statically created + * timer. + * + * @param xTimer The handle of the timer + * + * @param ppxTaskBuffer Used to pass back a pointer to the timers's data + * structure buffer. + * + * @return pdTRUE if the buffer were fetched. pdFALSE if the timer was not + * statically created. + */ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer, + StaticTimer_t ** ppxTimerBuffer ) PRIVILEGED_FUNCTION; +#endif /* configSUPPORT_STATIC_ALLOCATION */ + /* * Functions beyond this part are not part of the public API and are intended * for use by the kernel only. diff --git a/queue.c b/queue.c index ca6bfbc60dc..c3fd87141d3 100644 --- a/queue.c +++ b/queue.c @@ -419,6 +419,55 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue, #endif /* configSUPPORT_STATIC_ALLOCATION */ /*-----------------------------------------------------------*/ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue, + uint8_t ** ppucQueueStorage, + StaticQueue_t ** ppxStaticQueue ) + { + BaseType_t xReturn; + Queue_t * const pxQueue = xQueue; + + configASSERT( pxQueue ); + configASSERT( ppxStaticQueue ); + + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) + { + /* Check if the queue was statically allocated */ + if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdTRUE ) + { + if( ppucQueueStorage != NULL ) + { + *ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead; + } + + *ppxStaticQueue = ( StaticQueue_t * ) pxQueue; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + } + #else /* configSUPPORT_DYNAMIC_ALLOCATION */ + { + /* Queue must have been statically allocated */ + if( ppucQueueStorage != NULL ) + { + *ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead; + } + + *ppxStaticQueue = ( StaticQueue_t * ) pxQueue; + xReturn = pdTRUE; + } + #endif /* configSUPPORT_DYNAMIC_ALLOCATION */ + + return xReturn; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, diff --git a/stream_buffer.c b/stream_buffer.c index 0d0b3350acd..3c5f7f7c996 100644 --- a/stream_buffer.c +++ b/stream_buffer.c @@ -472,6 +472,34 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, #endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */ /*-----------------------------------------------------------*/ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xStreamBufferGenericGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, + uint8_t ** ppucStreamBufferStorageArea, + StaticStreamBuffer_t ** ppxStaticStreamBuffer ) + { + BaseType_t xReturn; + const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; + + configASSERT( pxStreamBuffer ); + configASSERT( ppucStreamBufferStorageArea ); + configASSERT( ppxStaticStreamBuffer ); + + if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 ) + { + *ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer; + *ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; + } +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer ) { StreamBuffer_t * pxStreamBuffer = xStreamBuffer; diff --git a/tasks.c b/tasks.c index 0e7a56c6058..687bee51854 100644 --- a/tasks.c +++ b/tasks.c @@ -2489,6 +2489,37 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char #endif /* INCLUDE_xTaskGetHandle */ /*-----------------------------------------------------------*/ +#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + + BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask, + StackType_t ** ppuxStackBuffer, + StaticTask_t ** ppxTaskBuffer ) + { + BaseType_t xReturn; + TCB_t * pxTCB; + + configASSERT( ppuxStackBuffer != NULL ); + configASSERT( ppxTaskBuffer != NULL ); + + pxTCB = prvGetTCBFromHandle( xTask ); + + if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ) + { + *ppuxStackBuffer = pxTCB->pxStack; + *ppxTaskBuffer = ( StaticTask_t * ) pxTCB; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; + } + +#endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + #if ( configUSE_TRACE_FACILITY == 1 ) UBaseType_t uxTaskGetSystemState( TaskStatus_t * const pxTaskStatusArray, diff --git a/timers.c b/timers.c index 06a29279597..76a59a8b999 100644 --- a/timers.c +++ b/timers.c @@ -510,6 +510,30 @@ } /*-----------------------------------------------------------*/ + #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) + BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer, + StaticTimer_t ** ppxTimerBuffer ) + { + BaseType_t xReturn; + Timer_t * pxTimer = xTimer; + + configASSERT( ppxTimerBuffer != NULL ); + + if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) != 0 ) + { + *ppxTimerBuffer = ( StaticTimer_t * ) pxTimer; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + + return xReturn; + } + #endif /* configSUPPORT_STATIC_ALLOCATION */ +/*-----------------------------------------------------------*/ + const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */ { Timer_t * pxTimer = xTimer; From ddeb6b5c0a57a196523aac666f3a604ae565012e Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Tue, 14 Mar 2023 16:52:04 -0700 Subject: [PATCH 2/5] tasks.c: Hanndle tskSTATICALLY_ALLOCATED_STACK_ONLY case in xTaskGetStaticBuffers --- tasks.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tasks.c b/tasks.c index 687bee51854..ecdddce05ca 100644 --- a/tasks.c +++ b/tasks.c @@ -2503,16 +2503,27 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char pxTCB = prvGetTCBFromHandle( xTask ); - if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ) + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 ) + if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ) + #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 */ { *ppuxStackBuffer = pxTCB->pxStack; *ppxTaskBuffer = ( StaticTask_t * ) pxTCB; xReturn = pdTRUE; } - else - { - xReturn = pdFALSE; - } + + #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 ) + else if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY ) + { + *ppuxStackBuffer = pxTCB->pxStack; + *ppxTaskBuffer = NULL; + xReturn = pdTRUE; + } + else + { + xReturn = pdFALSE; + } + #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 */ return xReturn; } From 2587c228c44ae681749d854e742a5b00c8c9eefa Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Tue, 21 Mar 2023 11:37:08 -0700 Subject: [PATCH 3/5] Trigger codecov update --- .github/lexicon.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/lexicon.txt b/.github/lexicon.txt index ac9047b8352..e7ded970dbd 100644 --- a/.github/lexicon.txt +++ b/.github/lexicon.txt @@ -3099,3 +3099,4 @@ xwritevalue xxr xyieldpending xzr + From 74c633ab093d2ca4acb0a38c1eedfda0d67e2604 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Wed, 22 Mar 2023 17:41:31 +0000 Subject: [PATCH 4/5] Code review suggestions Signed-off-by: Gaurav Aggarwal --- event_groups.c | 4 ++-- include/event_groups.h | 11 +++++------ include/message_buffer.h | 20 ++++++++++---------- include/queue.h | 22 +++++++++++----------- include/semphr.h | 14 +++++++------- include/stream_buffer.h | 29 ++++++++++------------------- include/task.h | 16 ++++++++-------- include/timers.h | 12 ++++++------ queue.c | 4 ++-- stream_buffer.c | 6 +++--- tasks.c | 21 +++++++++++++-------- 11 files changed, 77 insertions(+), 82 deletions(-) diff --git a/event_groups.c b/event_groups.c index e52f04f6ff1..5c4b4297baf 100644 --- a/event_groups.c +++ b/event_groups.c @@ -689,7 +689,7 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup ) #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) { - /* Check if the event group was statically allocated */ + /* Check if the event group was statically allocated. */ if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE ) { *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits; @@ -702,7 +702,7 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup ) } #else /* configSUPPORT_DYNAMIC_ALLOCATION */ { - /* Event group must have been statically allocated */ + /* Event group must have been statically allocated. */ *ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits; xReturn = pdTRUE; } diff --git a/include/event_groups.h b/include/event_groups.h index 2b8949fd2d2..47572ce94e4 100644 --- a/include/event_groups.h +++ b/include/event_groups.h @@ -770,16 +770,15 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION; * StaticEventGroup_t ** ppxEventGroupBuffer ); * @endcode * - * This function fetches a pointer to the memory buffer of a statically created - * event group. + * Retrieve a pointer to a statically created event groups's data structure + * buffer. It is the same buffer that is supplied at the time of creation. * - * @param xEventGroup The handle of the event group + * @param xEventGroup The event group for which to retrieve the buffer. * - * @param ppxEventGroupBuffer Used to pass back a pointer to the event groups's + * @param ppxEventGroupBuffer Used to return a pointer to the event groups's * data structure buffer. * - * @return pdTRUE if the buffer were fetched. pdFALSE if the event group was not - * statically created. + * @return pdTRUE if the buffer was retrieved, pdFALSE otherwise. */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup, diff --git a/include/message_buffer.h b/include/message_buffer.h index 8a514efeb67..b9bc3c989fd 100644 --- a/include/message_buffer.h +++ b/include/message_buffer.h @@ -250,30 +250,30 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; * * @code{c} * BaseType_t xMessageBufferGetStaticBuffers( MessageBufferHandle_t xMessageBuffer, - * uint8_t ** ppucMessageBufferStorageArea, - * StaticMessageBuffer_t ** ppxStaticMessageBuffer ); + * uint8_t ** ppucMessageBufferStorageArea, + * StaticMessageBuffer_t ** ppxStaticMessageBuffer ); * @endcode * - * This function fetches the pointers to the memory buffers of a statically - * created message buffer. + * Retrieve pointers to a statically created message buffer's data structure + * buffer and storage area buffer. These are the same buffers that are supplied + * at the time of creation. * - * @param xMessageBuffer The handle to the message buffer + * @param xMessageBuffer The message buffer for which to retrieve the buffers. * - * @param ppucMessageBufferStorageArea Used to pass back a pointer to the + * @param ppucMessageBufferStorageArea Used to return a pointer to the * message buffer's storage area buffer. * - * @param ppxStaticMessageBuffer Used to pass back a pointer to the message + * @param ppxStaticMessageBuffer Used to return a pointer to the message * buffer's data structure buffer. * - * @return pdTRUE if buffers were fetched. pdFALSE if the message buffer was not - * statically created. + * @return pdTRUE if buffers were retrieved, pdFALSE otherwise.. * * \defgroup xMessageBufferGetStaticBuffers xMessageBufferGetStaticBuffers * \ingroup MessageBufferManagement */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) #define xMessageBufferGetStaticBuffers( xMessageBuffer, ppucMessageBufferStorageArea, ppxStaticMessageBuffer ) \ - xStreamBufferGenericGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) ) + xStreamBufferGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) ) #endif /* configSUPPORT_STATIC_ALLOCATION */ /** diff --git a/include/queue.h b/include/queue.h index df695c9fa69..66c8286aef0 100644 --- a/include/queue.h +++ b/include/queue.h @@ -243,19 +243,19 @@ typedef struct QueueDefinition * QueueSetMemberHandle_t; * StaticQueue_t ** ppxStaticQueue ); * @endcode * - * This function fetches the pointers to the memory buffers of a statically - * created queue. + * Retrieve pointers to a statically created queue's data structure buffer + * and storage area buffer. These are the same buffers that are supplied + * at the time of creation. * - * @param xQueue The handle to the queue + * @param xQueue The queue for which to retrieve the buffers. * - * @param ppucQueueStorage Used to pass back a pointer to the queue's storage + * @param ppucQueueStorage Used to return a pointer to the queue's storage * area buffer. * - * @param ppxStaticQueue Used to pass back a pointer to the queue's data + * @param ppxStaticQueue Used to return a pointer to the queue's data * structure buffer. * - * @return pdTRUE if buffers were fetched. pdFALSE if the queue was not - * created using xQueueCreateStatic(). + * @return pdTRUE if buffers were retrieved, pdFALSE otherwise. * * \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers * \ingroup QueueManagement @@ -1572,10 +1572,10 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION; #endif /* - * Generic version of the function used to get the buffers of statically created - * queues. This is called by other functions and macros that get the buffers - * of other statically created RTOS objects that use the queue structure as - * their base. + * Generic version of the function used to retrieve the buffers of statically + * created queues. This is called by other functions and macros that retrieve + * the buffers of other statically created RTOS objects that use the queue + * structure as their base. */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue, diff --git a/include/semphr.h b/include/semphr.h index 34f49708b72..7977a01b84e 100644 --- a/include/semphr.h +++ b/include/semphr.h @@ -1196,16 +1196,16 @@ typedef QueueHandle_t SemaphoreHandle_t; * BaseType_t xSemaphoreGetStaticBuffer( SemaphoreHandle_t xSemaphore ); * @endcode * - * This function fetches a pointer to the memory buffer of a statically created - * binary semaphore, counting semaphore, or mutex semaphore. + * Retrieve pointer to a statically created binary semaphore, counting semaphore, + * or mutex semaphore's data structure buffer. This is the same buffer that is + * supplied at the time of creation. * - * @param xSemaphore The handle of the statically created semaphore + * @param xSemaphore The semaphore for which to retrieve the buffer. * - * @param ppxSemaphoreBuffer Used to pass back a pointer to the semaphore's - * data structure buffer + * @param ppxSemaphoreBuffer Used to return a pointer to the semaphore's + * data structure buffer. * - * @return pdTRUE if buffer was fetched. pdFALSE if the semaphore was not - * statically allocated. + * @return pdTRUE if buffer was retrieved, pdFALSE otherwise. */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) #define xSemaphoreGetStaticBuffer( xSemaphore, ppxSemaphoreBuffer ) xQueueGenericGetStaticBuffers( ( QueueHandle_t ) ( xSemaphore ), NULL, ( ppxSemaphoreBuffer ) ) diff --git a/include/stream_buffer.h b/include/stream_buffer.h index 28a9e1662bc..521c178ef5a 100644 --- a/include/stream_buffer.h +++ b/include/stream_buffer.h @@ -269,26 +269,27 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf * StaticStreamBuffer_t ** ppxStaticStreamBuffer ); * @endcode * - * This function fetches the pointers to the memory buffers of a statically - * created stream buffer. + * Retrieve pointers to a statically created stream buffer's data structure + * buffer and storage area buffer. These are the same buffers that are supplied + * at the time of creation. * - * @param xStreamBuffer The handle to the stream buffer + * @param xStreamBuffer The stream buffer for which to retrieve the buffers. * - * @param ppucStreamBufferStorageArea Used to pass back a pointer to the stream + * @param ppucStreamBufferStorageArea Used to return a pointer to the stream * buffer's storage area buffer. * - * @param ppxStaticStreamBuffer Used to pass back a pointer to the stream + * @param ppxStaticStreamBuffer Used to return a pointer to the stream * buffer's data structure buffer. * - * @return pdTRUE if buffers were fetched. pdFALSE if the stream buffer was not - * statically created. + * @return pdTRUE if buffers were retrieved, pdFALSE otherwise. * * \defgroup xStreamBufferGetStaticBuffers xStreamBufferGetStaticBuffers * \ingroup StreamBufferManagement */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - #define xStreamBufferGetStaticBuffers( xStreamBuffer, ppucStreamBufferStorageArea, ppxStaticStreamBuffer ) \ - xStreamBufferGenericGetStaticBuffers( ( xStreamBuffer ), ( ppucStreamBufferStorageArea ), ( ppxStaticStreamBuffer ) ) + BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, + uint8_t ** ppucStreamBufferStorageArea, + StaticStreamBuffer_t ** ppxStaticStreamBuffer ) PRIVILEGED_FUNCTION; #endif /* configSUPPORT_STATIC_ALLOCATION */ /** @@ -926,16 +927,6 @@ StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION; -/* - * Generic version of the function used to get the buffers of statically created - * stream or message buffer. - */ -#if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - BaseType_t xStreamBufferGenericGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, - uint8_t ** ppucStreamBufferStorageArea, - StaticStreamBuffer_t ** ppxStaticStreamBuffer ) PRIVILEGED_FUNCTION; -#endif /* configSUPPORT_STATIC_ALLOCATION */ - size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION; #if ( configUSE_TRACE_FACILITY == 1 ) diff --git a/include/task.h b/include/task.h index 1ca017b5e42..054f43644a1 100644 --- a/include/task.h +++ b/include/task.h @@ -1517,18 +1517,18 @@ TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; / * StaticTask_t ** ppxTaskBuffer ); * @endcode * - * This function fetches a pointer to the memory buffers of a statically created - * task. + * Retrieve pointers to a statically created task's data structure + * buffer and stack buffer. These are the same buffers that are supplied + * at the time of creation. * - * @param xTask The handle of the statically created task + * @param xTask The task for which to retrieve the buffers. * - * @param ppuxStackBuffer Used to pass back a pointer to the task's stack buffer + * @param ppuxStackBuffer Used to return a pointer to the task's stack buffer. * - * @param ppxTaskBuffer Used to pass back a pointer to the task's data structure - * buffer + * @param ppxTaskBuffer Used to return a pointer to the task's data structure + * buffer. * - * @return pdTRUE if buffers were fetched. pdFALSE if the task was not - * statically created. + * @return pdTRUE if buffers were retrieved, pdFALSE otherwise. * * \defgroup xTaskGetStaticBuffers xTaskGetStaticBuffers * \ingroup TaskUtils diff --git a/include/timers.h b/include/timers.h index 94fc37216cf..2967a4674c7 100644 --- a/include/timers.h +++ b/include/timers.h @@ -1327,16 +1327,16 @@ TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; * BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer, * StaticTimer_t ** ppxTimerBuffer ); * - * This function fetches a pointer to the memory buffer of a statically created - * timer. + * Retrieve pointer to a statically created timer's data structure + * buffer. This is the same buffer that is supplied at the time of + * creation. * - * @param xTimer The handle of the timer + * @param xTimer The timer for which to retrieve the buffer. * - * @param ppxTaskBuffer Used to pass back a pointer to the timers's data + * @param ppxTaskBuffer Used to return a pointer to the timers's data * structure buffer. * - * @return pdTRUE if the buffer were fetched. pdFALSE if the timer was not - * statically created. + * @return pdTRUE if the buffer was retrieved, pdFALSE otherwise. */ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer, diff --git a/queue.c b/queue.c index c3fd87141d3..662052f5ef6 100644 --- a/queue.c +++ b/queue.c @@ -433,7 +433,7 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue, #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) { - /* Check if the queue was statically allocated */ + /* Check if the queue was statically allocated. */ if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdTRUE ) { if( ppucQueueStorage != NULL ) @@ -451,7 +451,7 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue, } #else /* configSUPPORT_DYNAMIC_ALLOCATION */ { - /* Queue must have been statically allocated */ + /* Queue must have been statically allocated. */ if( ppucQueueStorage != NULL ) { *ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead; diff --git a/stream_buffer.c b/stream_buffer.c index 3c5f7f7c996..938c4051cec 100644 --- a/stream_buffer.c +++ b/stream_buffer.c @@ -473,9 +473,9 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer, /*-----------------------------------------------------------*/ #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) - BaseType_t xStreamBufferGenericGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, - uint8_t ** ppucStreamBufferStorageArea, - StaticStreamBuffer_t ** ppxStaticStreamBuffer ) + BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer, + uint8_t ** ppucStreamBufferStorageArea, + StaticStreamBuffer_t ** ppxStaticStreamBuffer ) { BaseType_t xReturn; const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer; diff --git a/tasks.c b/tasks.c index ecdddce05ca..befd63e2279 100644 --- a/tasks.c +++ b/tasks.c @@ -2504,15 +2504,13 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char pxTCB = prvGetTCBFromHandle( xTask ); #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 ) - if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ) - #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 */ { - *ppuxStackBuffer = pxTCB->pxStack; - *ppxTaskBuffer = ( StaticTask_t * ) pxTCB; - xReturn = pdTRUE; - } - - #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 ) + if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_AND_TCB ) + { + *ppuxStackBuffer = pxTCB->pxStack; + *ppxTaskBuffer = ( StaticTask_t * ) pxTCB; + xReturn = pdTRUE; + } else if( pxTCB->ucStaticallyAllocated == tskSTATICALLY_ALLOCATED_STACK_ONLY ) { *ppuxStackBuffer = pxTCB->pxStack; @@ -2523,6 +2521,13 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char { xReturn = pdFALSE; } + } + #else /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 */ + { + *ppuxStackBuffer = pxTCB->pxStack; + *ppxTaskBuffer = ( StaticTask_t * ) pxTCB; + xReturn = pdTRUE; + } #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE == 1 */ return xReturn; From 3550b0d5d876a18546a2332d6ff74426b719fa08 Mon Sep 17 00:00:00 2001 From: Gaurav Aggarwal Date: Wed, 22 Mar 2023 18:02:33 +0000 Subject: [PATCH 5/5] Fix formatting check Signed-off-by: Gaurav Aggarwal --- include/message_buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/message_buffer.h b/include/message_buffer.h index b9bc3c989fd..74fab118f51 100644 --- a/include/message_buffer.h +++ b/include/message_buffer.h @@ -251,7 +251,7 @@ typedef StreamBufferHandle_t MessageBufferHandle_t; * @code{c} * BaseType_t xMessageBufferGetStaticBuffers( MessageBufferHandle_t xMessageBuffer, * uint8_t ** ppucMessageBufferStorageArea, - * StaticMessageBuffer_t ** ppxStaticMessageBuffer ); + * StaticMessageBuffer_t ** ppxStaticMessageBuffer ); * @endcode * * Retrieve pointers to a statically created message buffer's data structure