Skip to content

Commit

Permalink
Add functions to get buffers of statically created objects
Browse files Browse the repository at this point in the history
Added various ...GetStaticBuffer() functions to get the buffers of statically
created objects.
  • Loading branch information
Dazza0 committed Mar 10, 2023
1 parent 309a18a commit 46d947c
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 0 deletions.
25 changes: 25 additions & 0 deletions event_groups.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,31 @@ 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( pxEventBits->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
{
*ppxEventGroupBuffer = ( StaticEventGroup_t * ) pxEventBits;
xReturn = pdTRUE;
}
else
{
xReturn = pdFALSE;
}

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,
Expand Down
23 changes: 23 additions & 0 deletions include/event_groups.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions include/message_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
41 changes: 41 additions & 0 deletions include/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions include/semphr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
41 changes: 41 additions & 0 deletions include/stream_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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 )
Expand Down
30 changes: 30 additions & 0 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
20 changes: 20 additions & 0 deletions include/timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 33 additions & 0 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,39 @@ 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( pxQueue->ucStaticallyAllocated == ( uint8_t ) pdTRUE )
{
if( ppucQueueStorage != NULL )
{
*ppucQueueStorage = ( uint8_t * ) pxQueue->pcHead;
}

*ppxStaticQueue = ( StaticQueue_t * ) pxQueue;
xReturn = pdTRUE;
}
else
{
xReturn = pdFALSE;
}

return xReturn;
}

#endif /* configSUPPORT_STATIC_ALLOCATION */
/*-----------------------------------------------------------*/

#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )

QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength,
Expand Down
28 changes: 28 additions & 0 deletions stream_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 46d947c

Please sign in to comment.