Skip to content

Commit 46d947c

Browse files
committed
Add functions to get buffers of statically created objects
Added various ...GetStaticBuffer() functions to get the buffers of statically created objects.
1 parent 309a18a commit 46d947c

12 files changed

+348
-0
lines changed

event_groups.c

+25
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,31 @@ void vEventGroupDelete( EventGroupHandle_t xEventGroup )
677677
}
678678
/*-----------------------------------------------------------*/
679679

680+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
681+
BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
682+
StaticEventGroup_t ** ppxEventGroupBuffer )
683+
{
684+
BaseType_t xReturn;
685+
EventGroup_t * pxEventBits = xEventGroup;
686+
687+
configASSERT( pxEventBits );
688+
configASSERT( ppxEventGroupBuffer );
689+
690+
if( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
691+
{
692+
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
693+
xReturn = pdTRUE;
694+
}
695+
else
696+
{
697+
xReturn = pdFALSE;
698+
}
699+
700+
return xReturn;
701+
}
702+
#endif /* configSUPPORT_STATIC_ALLOCATION */
703+
/*-----------------------------------------------------------*/
704+
680705
/* For internal use only - execute a 'set bits' command that was pended from
681706
* an interrupt. */
682707
void vEventGroupSetBitsCallback( void * pvEventGroup,

include/event_groups.h

+23
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,29 @@ EventBits_t xEventGroupGetBitsFromISR( EventGroupHandle_t xEventGroup ) PRIVILEG
763763
*/
764764
void vEventGroupDelete( EventGroupHandle_t xEventGroup ) PRIVILEGED_FUNCTION;
765765

766+
/**
767+
* event_groups.h
768+
* @code{c}
769+
* BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
770+
* StaticEventGroup_t ** ppxEventGroupBuffer );
771+
* @endcode
772+
*
773+
* This function fetches a pointer to the memory buffer of a statically created
774+
* event group.
775+
*
776+
* @param xEventGroup The handle of the event group
777+
*
778+
* @param ppxEventGroupBuffer Used to pass back a pointer to the event groups's
779+
* data structure buffer.
780+
*
781+
* @return pdTRUE if the buffer were fetched. pdFALSE if the event group was not
782+
* statically created.
783+
*/
784+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
785+
BaseType_t xEventGroupGetStaticBuffer( EventGroupHandle_t xEventGroup,
786+
StaticEventGroup_t ** ppxEventGroupBuffer ) PRIVILEGED_FUNCTION;
787+
#endif /* configSUPPORT_STATIC_ALLOCATION */
788+
766789
/* For internal use only. */
767790
void vEventGroupSetBitsCallback( void * pvEventGroup,
768791
const uint32_t ulBitsToSet ) PRIVILEGED_FUNCTION;

include/message_buffer.h

+31
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,37 @@ typedef StreamBufferHandle_t MessageBufferHandle_t;
245245
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), 0, pdTRUE, ( pucMessageBufferStorageArea ), ( pxStaticMessageBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
246246
#endif
247247

248+
/**
249+
* message_buffer.h
250+
*
251+
* @code{c}
252+
* BaseType_t xMessageBufferGetStaticBuffers( MessageBufferHandle_t xMessageBuffer,
253+
* uint8_t ** ppucMessageBufferStorageArea,
254+
* StaticMessageBuffer_t ** ppxStaticMessageBuffer );
255+
* @endcode
256+
*
257+
* This function fetches the pointers to the memory buffers of a statically
258+
* created message buffer.
259+
*
260+
* @param xMessageBuffer The handle to the message buffer
261+
*
262+
* @param ppucMessageBufferStorageArea Used to pass back a pointer to the
263+
* message buffer's storage area buffer.
264+
*
265+
* @param ppxStaticMessageBuffer Used to pass back a pointer to the message
266+
* buffer's data structure buffer.
267+
*
268+
* @return pdTRUE if buffers were fetched. pdFALSE if the message buffer was not
269+
* statically created.
270+
*
271+
* \defgroup xMessageBufferGetStaticBuffers xMessageBufferGetStaticBuffers
272+
* \ingroup MessageBufferManagement
273+
*/
274+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
275+
#define xMessageBufferGetStaticBuffers( xMessageBuffer, ppucMessageBufferStorageArea, ppxStaticMessageBuffer ) \
276+
xStreamBufferGenericGetStaticBuffers( ( xMessageBuffer ), ( ppucMessageBufferStorageArea ), ( ppxStaticMessageBuffer ) )
277+
#endif /* configSUPPORT_STATIC_ALLOCATION */
278+
248279
/**
249280
* message_buffer.h
250281
*

include/queue.h

+41
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,35 @@ typedef struct QueueDefinition * QueueSetMemberHandle_t;
235235
#define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxQueueBuffer ) xQueueGenericCreateStatic( ( uxQueueLength ), ( uxItemSize ), ( pucQueueStorage ), ( pxQueueBuffer ), ( queueQUEUE_TYPE_BASE ) )
236236
#endif /* configSUPPORT_STATIC_ALLOCATION */
237237

238+
/**
239+
* queue. h
240+
* @code{c}
241+
* BaseType_t xQueueGetStaticBuffers( QueueHandle_t xQueue,
242+
* uint8_t ** ppucQueueStorage,
243+
* StaticQueue_t ** ppxStaticQueue );
244+
* @endcode
245+
*
246+
* This function fetches the pointers to the memory buffers of a statically
247+
* created queue.
248+
*
249+
* @param xQueue The handle to the queue
250+
*
251+
* @param ppucQueueStorage Used to pass back a pointer to the queue's storage
252+
* area buffer.
253+
*
254+
* @param ppxStaticQueue Used to pass back a pointer to the queue's data
255+
* structure buffer.
256+
*
257+
* @return pdTRUE if buffers were fetched. pdFALSE if the queue was not
258+
* created using xQueueCreateStatic().
259+
*
260+
* \defgroup xQueueGetStaticBuffers xQueueGetStaticBuffers
261+
* \ingroup QueueManagement
262+
*/
263+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
264+
#define xQueueGetStaticBuffers( xQueue, ppucQueueStorage, ppxStaticQueue ) xQueueGenericGetStaticBuffers( ( xQueue ), ( ppucQueueStorage ), ( ppxStaticQueue ) )
265+
#endif /* configSUPPORT_STATIC_ALLOCATION */
266+
238267
/**
239268
* queue. h
240269
* @code{c}
@@ -1542,6 +1571,18 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t xMutex ) PRIVILEGED_FUNCTION;
15421571
const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
15431572
#endif
15441573

1574+
/*
1575+
* Generic version of the function used to get the buffers of statically created
1576+
* queues. This is called by other functions and macros that get the buffers
1577+
* of other statically created RTOS objects that use the queue structure as
1578+
* their base.
1579+
*/
1580+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1581+
BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
1582+
uint8_t ** ppucQueueStorage,
1583+
StaticQueue_t ** ppxStaticQueue ) PRIVILEGED_FUNCTION;
1584+
#endif
1585+
15451586
/*
15461587
* Queue sets provide a mechanism to allow a task to block (pend) on a read
15471588
* operation from multiple queues or semaphores simultaneously.

include/semphr.h

+21
Original file line numberDiff line numberDiff line change
@@ -1190,4 +1190,25 @@ typedef QueueHandle_t SemaphoreHandle_t;
11901190
*/
11911191
#define uxSemaphoreGetCountFromISR( xSemaphore ) uxQueueMessagesWaitingFromISR( ( QueueHandle_t ) ( xSemaphore ) )
11921192

1193+
/**
1194+
* semphr.h
1195+
* @code{c}
1196+
* BaseType_t xSemaphoreGetStaticBuffer( SemaphoreHandle_t xSemaphore );
1197+
* @endcode
1198+
*
1199+
* This function fetches a pointer to the memory buffer of a statically created
1200+
* binary semaphore, counting semaphore, or mutex semaphore.
1201+
*
1202+
* @param xSemaphore The handle of the statically created semaphore
1203+
*
1204+
* @param ppxSemaphoreBuffer Used to pass back a pointer to the semaphore's
1205+
* data structure buffer
1206+
*
1207+
* @return pdTRUE if buffer was fetched. pdFALSE if the semaphore was not
1208+
* statically allocated.
1209+
*/
1210+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1211+
#define xSemaphoreGetStaticBuffer( xSemaphore, ppxSemaphoreBuffer ) xQueueGenericGetStaticBuffers( ( QueueHandle_t ) ( xSemaphore ), NULL, ( ppxSemaphoreBuffer ) )
1212+
#endif /* configSUPPORT_STATIC_ALLOCATION */
1213+
11931214
#endif /* SEMAPHORE_H */

include/stream_buffer.h

+41
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,37 @@ typedef void (* StreamBufferCallbackFunction_t)( StreamBufferHandle_t xStreamBuf
260260
xStreamBufferGenericCreateStatic( ( xBufferSizeBytes ), ( xTriggerLevelBytes ), pdFALSE, ( pucStreamBufferStorageArea ), ( pxStaticStreamBuffer ), ( pxSendCompletedCallback ), ( pxReceiveCompletedCallback ) )
261261
#endif
262262

263+
/**
264+
* stream_buffer.h
265+
*
266+
* @code{c}
267+
* BaseType_t xStreamBufferGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
268+
* uint8_t ** ppucStreamBufferStorageArea,
269+
* StaticStreamBuffer_t ** ppxStaticStreamBuffer );
270+
* @endcode
271+
*
272+
* This function fetches the pointers to the memory buffers of a statically
273+
* created stream buffer.
274+
*
275+
* @param xStreamBuffer The handle to the stream buffer
276+
*
277+
* @param ppucStreamBufferStorageArea Used to pass back a pointer to the stream
278+
* buffer's storage area buffer.
279+
*
280+
* @param ppxStaticStreamBuffer Used to pass back a pointer to the stream
281+
* buffer's data structure buffer.
282+
*
283+
* @return pdTRUE if buffers were fetched. pdFALSE if the stream buffer was not
284+
* statically created.
285+
*
286+
* \defgroup xStreamBufferGetStaticBuffers xStreamBufferGetStaticBuffers
287+
* \ingroup StreamBufferManagement
288+
*/
289+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
290+
#define xStreamBufferGetStaticBuffers( xStreamBuffer, ppucStreamBufferStorageArea, ppxStaticStreamBuffer ) \
291+
xStreamBufferGenericGetStaticBuffers( ( xStreamBuffer ), ( ppucStreamBufferStorageArea ), ( ppxStaticStreamBuffer ) )
292+
#endif /* configSUPPORT_STATIC_ALLOCATION */
293+
263294
/**
264295
* stream_buffer.h
265296
*
@@ -895,6 +926,16 @@ StreamBufferHandle_t xStreamBufferGenericCreateStatic( size_t xBufferSizeBytes,
895926
StreamBufferCallbackFunction_t pxSendCompletedCallback,
896927
StreamBufferCallbackFunction_t pxReceiveCompletedCallback ) PRIVILEGED_FUNCTION;
897928

929+
/*
930+
* Generic version of the function used to get the buffers of statically created
931+
* stream or message buffer.
932+
*/
933+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
934+
BaseType_t xStreamBufferGenericGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
935+
uint8_t ** ppucStreamBufferStorageArea,
936+
StaticStreamBuffer_t ** ppxStaticStreamBuffer ) PRIVILEGED_FUNCTION;
937+
#endif /* configSUPPORT_STATIC_ALLOCATION */
938+
898939
size_t xStreamBufferNextMessageLengthBytes( StreamBufferHandle_t xStreamBuffer ) PRIVILEGED_FUNCTION;
899940

900941
#if ( configUSE_TRACE_FACILITY == 1 )

include/task.h

+30
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,36 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) PRIVILEGED_FUNCTION; /*lint !e
15091509
*/
15101510
TaskHandle_t xTaskGetHandle( const char * pcNameToQuery ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
15111511

1512+
/**
1513+
* task. h
1514+
* @code{c}
1515+
* BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask,
1516+
* StackType_t ** ppuxStackBuffer,
1517+
* StaticTask_t ** ppxTaskBuffer );
1518+
* @endcode
1519+
*
1520+
* This function fetches a pointer to the memory buffers of a statically created
1521+
* task.
1522+
*
1523+
* @param xTask The handle of the statically created task
1524+
*
1525+
* @param ppuxStackBuffer Used to pass back a pointer to the task's stack buffer
1526+
*
1527+
* @param ppxTaskBuffer Used to pass back a pointer to the task's data structure
1528+
* buffer
1529+
*
1530+
* @return pdTRUE if buffers were fetched. pdFALSE if the task was not
1531+
* statically created.
1532+
*
1533+
* \defgroup xTaskGetStaticBuffers xTaskGetStaticBuffers
1534+
* \ingroup TaskUtils
1535+
*/
1536+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1537+
BaseType_t xTaskGetStaticBuffers( TaskHandle_t xTask,
1538+
StackType_t ** ppuxStackBuffer,
1539+
StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION;
1540+
#endif /* configSUPPORT_STATIC_ALLOCATION */
1541+
15121542
/**
15131543
* task.h
15141544
* @code{c}

include/timers.h

+20
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,26 @@ TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
13231323
*/
13241324
TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
13251325

1326+
/**
1327+
* BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
1328+
* StaticTimer_t ** ppxTimerBuffer );
1329+
*
1330+
* This function fetches a pointer to the memory buffer of a statically created
1331+
* timer.
1332+
*
1333+
* @param xTimer The handle of the timer
1334+
*
1335+
* @param ppxTaskBuffer Used to pass back a pointer to the timers's data
1336+
* structure buffer.
1337+
*
1338+
* @return pdTRUE if the buffer were fetched. pdFALSE if the timer was not
1339+
* statically created.
1340+
*/
1341+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
1342+
BaseType_t xTimerGetStaticBuffer( TimerHandle_t xTimer,
1343+
StaticTimer_t ** ppxTimerBuffer ) PRIVILEGED_FUNCTION;
1344+
#endif /* configSUPPORT_STATIC_ALLOCATION */
1345+
13261346
/*
13271347
* Functions beyond this part are not part of the public API and are intended
13281348
* for use by the kernel only.

queue.c

+33
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,39 @@ BaseType_t xQueueGenericReset( QueueHandle_t xQueue,
419419
#endif /* configSUPPORT_STATIC_ALLOCATION */
420420
/*-----------------------------------------------------------*/
421421

422+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
423+
424+
BaseType_t xQueueGenericGetStaticBuffers( QueueHandle_t xQueue,
425+
uint8_t ** ppucQueueStorage,
426+
StaticQueue_t ** ppxStaticQueue )
427+
{
428+
BaseType_t xReturn;
429+
Queue_t * const pxQueue = xQueue;
430+
431+
configASSERT( pxQueue );
432+
configASSERT( ppxStaticQueue );
433+
434+
if( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
435+
{
436+
if( ppucQueueStorage != NULL )
437+
{
438+
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
439+
}
440+
441+
*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
442+
xReturn = pdTRUE;
443+
}
444+
else
445+
{
446+
xReturn = pdFALSE;
447+
}
448+
449+
return xReturn;
450+
}
451+
452+
#endif /* configSUPPORT_STATIC_ALLOCATION */
453+
/*-----------------------------------------------------------*/
454+
422455
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
423456

424457
QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,

stream_buffer.c

+28
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,34 @@ static void prvInitialiseNewStreamBuffer( StreamBuffer_t * const pxStreamBuffer,
472472
#endif /* ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
473473
/*-----------------------------------------------------------*/
474474

475+
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
476+
BaseType_t xStreamBufferGenericGetStaticBuffers( StreamBufferHandle_t xStreamBuffer,
477+
uint8_t ** ppucStreamBufferStorageArea,
478+
StaticStreamBuffer_t ** ppxStaticStreamBuffer )
479+
{
480+
BaseType_t xReturn;
481+
const StreamBuffer_t * const pxStreamBuffer = xStreamBuffer;
482+
483+
configASSERT( pxStreamBuffer );
484+
configASSERT( ppucStreamBufferStorageArea );
485+
configASSERT( ppxStaticStreamBuffer );
486+
487+
if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_STATICALLY_ALLOCATED ) != ( uint8_t ) 0 )
488+
{
489+
*ppucStreamBufferStorageArea = pxStreamBuffer->pucBuffer;
490+
*ppxStaticStreamBuffer = ( StaticStreamBuffer_t * ) pxStreamBuffer;
491+
xReturn = pdTRUE;
492+
}
493+
else
494+
{
495+
xReturn = pdFALSE;
496+
}
497+
498+
return xReturn;
499+
}
500+
#endif /* configSUPPORT_STATIC_ALLOCATION */
501+
/*-----------------------------------------------------------*/
502+
475503
void vStreamBufferDelete( StreamBufferHandle_t xStreamBuffer )
476504
{
477505
StreamBuffer_t * pxStreamBuffer = xStreamBuffer;

0 commit comments

Comments
 (0)