Continue to add the ability to create RTOS objects using static rather than dynamic memory allocation - now including all the semaphore types.
Update the StaticAllocation.c standard demo file to exercise the new static allocation functions.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -1482,8 +1482,8 @@ BaseType_t xQueueCRReceive( QueueHandle_t xQueue, void *pvBuffer, TickType_t xTi
|
||||
* xSemaphoreCreateCounting() or xSemaphoreGetMutexHolder() instead of calling
|
||||
* these functions directly.
|
||||
*/
|
||||
QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;
|
||||
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;
|
||||
QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
|
||||
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;
|
||||
void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;
|
||||
|
||||
/*
|
||||
|
@ -699,7 +699,8 @@ typedef QueueHandle_t SemaphoreHandle_t;
|
||||
* \defgroup vSemaphoreCreateMutex vSemaphoreCreateMutex
|
||||
* \ingroup Semaphores
|
||||
*/
|
||||
#define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX )
|
||||
#define xSemaphoreCreateMutex() xQueueCreateMutex( queueQUEUE_TYPE_MUTEX, NULL )
|
||||
#define xSemaphoreCreateMutexStatic( pxStaticQueue ) xQueueCreateMutex( queueQUEUE_TYPE_MUTEX, ( pxStaticQueue ) )
|
||||
|
||||
|
||||
/**
|
||||
@ -754,7 +755,8 @@ typedef QueueHandle_t SemaphoreHandle_t;
|
||||
* \defgroup vSemaphoreCreateMutex vSemaphoreCreateMutex
|
||||
* \ingroup Semaphores
|
||||
*/
|
||||
#define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX )
|
||||
#define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX, NULL )
|
||||
#define xSemaphoreCreateRecursiveMutexStatic( pxStaticSemaphore ) xQueueCreateMutex( queueQUEUE_TYPE_RECURSIVE_MUTEX, pxStaticSemaphore )
|
||||
|
||||
/**
|
||||
* semphr. h
|
||||
@ -817,7 +819,8 @@ typedef QueueHandle_t SemaphoreHandle_t;
|
||||
* \defgroup xSemaphoreCreateCounting xSemaphoreCreateCounting
|
||||
* \ingroup Semaphores
|
||||
*/
|
||||
#define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ) )
|
||||
#define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ), ( NULL ) )
|
||||
#define xSemaphoreCreateCountingStatic( uxMaxCount, uxInitialCount, pxStaticSemaphore ) xQueueCreateCountingSemaphore( ( uxMaxCount ), ( uxInitialCount ), ( pxStaticSemaphore ) )
|
||||
|
||||
/**
|
||||
* semphr. h
|
||||
|
@ -500,51 +500,29 @@ Queue_t *pxNewQueue;
|
||||
|
||||
#if ( configUSE_MUTEXES == 1 )
|
||||
|
||||
QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType )
|
||||
QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue )
|
||||
{
|
||||
Queue_t *pxNewQueue;
|
||||
const UBaseType_t uxMutexLength = ( UBaseType_t ) 1, uxMutexSize = ( UBaseType_t ) 0;
|
||||
|
||||
/* Prevent compiler warnings about unused parameters if
|
||||
configUSE_TRACE_FACILITY does not equal 1. */
|
||||
( void ) ucQueueType;
|
||||
|
||||
pxNewQueue = ( Queue_t * ) xQueueGenericCreate( uxMutexLength, uxMutexSize, NULL, pxStaticQueue, ucQueueType );
|
||||
|
||||
/* Allocate the new queue structure. */
|
||||
pxNewQueue = ( Queue_t * ) pvPortMalloc( sizeof( Queue_t ) );
|
||||
if( pxNewQueue != NULL )
|
||||
{
|
||||
/* Information required for priority inheritance. */
|
||||
/* xQueueGenericCreate() will set all the queue structure members
|
||||
correctly for a generic queue, but this function is creating a
|
||||
mutex. Overwrite those members that need to be set differently -
|
||||
in particular the information required for priority inheritance. */
|
||||
pxNewQueue->pxMutexHolder = NULL;
|
||||
pxNewQueue->uxQueueType = queueQUEUE_IS_MUTEX;
|
||||
|
||||
/* Queues used as a mutex no data is actually copied into or out
|
||||
of the queue. */
|
||||
pxNewQueue->pcWriteTo = NULL;
|
||||
pxNewQueue->u.pcReadFrom = NULL;
|
||||
|
||||
/* Each mutex has a length of 1 (like a binary semaphore) and
|
||||
an item size of 0 as nothing is actually copied into or out
|
||||
of the mutex. */
|
||||
pxNewQueue->uxMessagesWaiting = ( UBaseType_t ) 0U;
|
||||
pxNewQueue->uxLength = ( UBaseType_t ) 1U;
|
||||
pxNewQueue->uxItemSize = ( UBaseType_t ) 0U;
|
||||
pxNewQueue->xRxLock = queueUNLOCKED;
|
||||
pxNewQueue->xTxLock = queueUNLOCKED;
|
||||
|
||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||
{
|
||||
pxNewQueue->ucQueueType = ucQueueType;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ( configUSE_QUEUE_SETS == 1 )
|
||||
{
|
||||
pxNewQueue->pxQueueSetContainer = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Ensure the event queues start with the correct state. */
|
||||
vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
|
||||
vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
|
||||
/* In case this is a recursive mutex. */
|
||||
pxNewQueue->u.uxRecursiveCallCount = 0;
|
||||
|
||||
traceCREATE_MUTEX( pxNewQueue );
|
||||
|
||||
@ -618,7 +596,7 @@ Queue_t *pxNewQueue;
|
||||
uxRecursiveCallCount member. */
|
||||
( pxMutex->u.uxRecursiveCallCount )--;
|
||||
|
||||
/* Have we unwound the call count? */
|
||||
/* Has the recursive call count unwound to 0? */
|
||||
if( pxMutex->u.uxRecursiveCallCount == ( UBaseType_t ) 0 )
|
||||
{
|
||||
/* Return the mutex. This will automatically unblock any other
|
||||
@ -691,14 +669,14 @@ Queue_t *pxNewQueue;
|
||||
|
||||
#if ( configUSE_COUNTING_SEMAPHORES == 1 )
|
||||
|
||||
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount )
|
||||
QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue )
|
||||
{
|
||||
QueueHandle_t xHandle;
|
||||
|
||||
configASSERT( uxMaxCount != 0 );
|
||||
configASSERT( uxInitialCount <= uxMaxCount );
|
||||
|
||||
xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, NULL, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
|
||||
xHandle = xQueueGenericCreate( uxMaxCount, queueSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_COUNTING_SEMAPHORE );
|
||||
|
||||
if( xHandle != NULL )
|
||||
{
|
||||
|
Reference in New Issue
Block a user