mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-23 06:51:58 -04:00
Add xQueueReset() function.
This commit is contained in:
parent
e3276fc282
commit
637045468b
|
@ -1234,6 +1234,14 @@ xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue,
|
||||||
portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
|
portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle pxMutex, portTickType xBlockTime );
|
||||||
portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
|
portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset a queue back to its original empty state. pdPASS is returned if the
|
||||||
|
* queue is successfully reset. pdFAIL is returned if the queue could not be
|
||||||
|
* reset because there are tasks blocked on the queue waiting to either
|
||||||
|
* receive from the queue or send to the queue.
|
||||||
|
*/
|
||||||
|
#define xQueueReset( pxQueue ) xQueueGenericReset( pxQueue, pdFALSE )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The registry is provided as a means for kernel aware debuggers to
|
* The registry is provided as a means for kernel aware debuggers to
|
||||||
* locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
|
* locate queues, semaphores and mutexes. Call vQueueAddToRegistry() add
|
||||||
|
@ -1264,10 +1272,9 @@ portBASE_TYPE xQueueGiveMutexRecursive( xQueueHandle pxMutex );
|
||||||
*/
|
*/
|
||||||
xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType );
|
xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType );
|
||||||
|
|
||||||
/*
|
/* Not public API functions. */
|
||||||
* Not a public API function, hence the 'Restricted' in the name.
|
|
||||||
*/
|
|
||||||
void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
|
void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksToWait );
|
||||||
|
portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue );
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -163,6 +163,7 @@ void vQueueWaitForMessageRestricted( xQueueHandle pxQueue, portTickType xTicksTo
|
||||||
unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
|
unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
|
||||||
void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;
|
void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ) PRIVILEGED_FUNCTION;
|
||||||
unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
|
unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ) PRIVILEGED_FUNCTION;
|
||||||
|
portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Co-routine queue functions differ from task queue functions. Co-routines are
|
* Co-routine queue functions differ from task queue functions. Co-routines are
|
||||||
|
@ -261,6 +262,45 @@ static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void *pvBuffer )
|
||||||
* PUBLIC QUEUE MANAGEMENT API documented in queue.h
|
* PUBLIC QUEUE MANAGEMENT API documented in queue.h
|
||||||
*----------------------------------------------------------*/
|
*----------------------------------------------------------*/
|
||||||
|
|
||||||
|
portBASE_TYPE xQueueGenericReset( xQueueHandle pxQueue, portBASE_TYPE xNewQueue )
|
||||||
|
{
|
||||||
|
portBASE_TYPE xReturn = pdPASS;
|
||||||
|
|
||||||
|
configASSERT( pxQueue );
|
||||||
|
|
||||||
|
/* If the queue being reset has already been used (has not just been
|
||||||
|
created), then only reset the queue if its event lists are empty. */
|
||||||
|
if( xNewQueue != pdTRUE )
|
||||||
|
{
|
||||||
|
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
|
||||||
|
{
|
||||||
|
xReturn = pdFAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )
|
||||||
|
{
|
||||||
|
xReturn = pdFAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( xReturn == pdPASS )
|
||||||
|
{
|
||||||
|
pxQueue->pcTail = pxQueue->pcHead + ( pxQueue->uxLength * pxQueue->uxItemSize );
|
||||||
|
pxQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;
|
||||||
|
pxQueue->pcWriteTo = pxQueue->pcHead;
|
||||||
|
pxQueue->pcReadFrom = pxQueue->pcHead + ( ( pxQueue->uxLength - ( unsigned portBASE_TYPE ) 1U ) * pxQueue->uxItemSize );
|
||||||
|
pxQueue->xRxLock = queueUNLOCKED;
|
||||||
|
pxQueue->xTxLock = queueUNLOCKED;
|
||||||
|
|
||||||
|
/* Ensure the event queues start with the correct state. */
|
||||||
|
vListInitialise( &( pxQueue->xTasksWaitingToSend ) );
|
||||||
|
vListInitialise( &( pxQueue->xTasksWaitingToReceive ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return xReturn;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType )
|
xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType )
|
||||||
{
|
{
|
||||||
xQUEUE *pxNewQueue;
|
xQUEUE *pxNewQueue;
|
||||||
|
@ -286,24 +326,15 @@ xQueueHandle xReturn = NULL;
|
||||||
{
|
{
|
||||||
/* Initialise the queue members as described above where the
|
/* Initialise the queue members as described above where the
|
||||||
queue type is defined. */
|
queue type is defined. */
|
||||||
pxNewQueue->pcTail = pxNewQueue->pcHead + ( uxQueueLength * uxItemSize );
|
|
||||||
pxNewQueue->uxMessagesWaiting = ( unsigned portBASE_TYPE ) 0U;
|
|
||||||
pxNewQueue->pcWriteTo = pxNewQueue->pcHead;
|
|
||||||
pxNewQueue->pcReadFrom = pxNewQueue->pcHead + ( ( uxQueueLength - ( unsigned portBASE_TYPE ) 1U ) * uxItemSize );
|
|
||||||
pxNewQueue->uxLength = uxQueueLength;
|
pxNewQueue->uxLength = uxQueueLength;
|
||||||
pxNewQueue->uxItemSize = uxItemSize;
|
pxNewQueue->uxItemSize = uxItemSize;
|
||||||
pxNewQueue->xRxLock = queueUNLOCKED;
|
xQueueGenericReset( pxNewQueue, pdTRUE );
|
||||||
pxNewQueue->xTxLock = queueUNLOCKED;
|
|
||||||
#if ( configUSE_TRACE_FACILITY == 1 )
|
#if ( configUSE_TRACE_FACILITY == 1 )
|
||||||
{
|
{
|
||||||
pxNewQueue->ucQueueType = ucQueueType;
|
pxNewQueue->ucQueueType = ucQueueType;
|
||||||
}
|
}
|
||||||
#endif /* configUSE_TRACE_FACILITY */
|
#endif /* configUSE_TRACE_FACILITY */
|
||||||
|
|
||||||
/* Likewise ensure the event queues start with the correct state. */
|
|
||||||
vListInitialise( &( pxNewQueue->xTasksWaitingToSend ) );
|
|
||||||
vListInitialise( &( pxNewQueue->xTasksWaitingToReceive ) );
|
|
||||||
|
|
||||||
traceQUEUE_CREATE( pxNewQueue );
|
traceQUEUE_CREATE( pxNewQueue );
|
||||||
xReturn = pxNewQueue;
|
xReturn = pxNewQueue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue