Updated Mar 2025
xQueueCreate
queue. h
1 QueueHandle_t xQueueCreate( UBaseType_t uxQueueLength,2 UBaseType_t uxItemSize );
Creates a new queue and returns a handle by which the queue can be referenced. configSUPPORT_DYNAMIC_ALLOCATION must be set to 1 in FreeRTOSConfig.h, or left undefined (in which case it will default to 1), for this RTOS API function to be available.
Each queue requires RAM that is used to hold the queue state, and to hold the items that are contained in the queue (the queue storage area). If a queue is created using
xQueueCreate()
Parameters:
-
uxQueueLength
The maximum number of items the queue can hold at any one time.
-
uxItemSize
The size, in bytes, required to hold each item in the queue.
Items are queued by copy, not by reference, so this is the number of bytes that will be copied for each queued item. Each item in the queue must be the same size.
Returns:
- If the queue is created successfully then a handle to the created queue is returned. If the memory required to create the queue could not be allocated then NULL is returned.
Example usage:
1struct AMessage2{3 char ucMessageID;4 char ucData[ 20 ];5};67void vATask( void *pvParameters )8{9QueueHandle_t xQueue1, xQueue2;1011 /* Create a queue capable of containing 10 unsigned long values. */12 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );1314 if( xQueue1 == NULL )15 {16 /* Queue was not created and must not be used. */17 }1819 /* Create a queue capable of containing 10 pointers to AMessage20 structures. These are to be queued by pointers as they are21 relatively large structures. */22 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );2324 if( xQueue2 == NULL )25 {26 /* Queue was not created and must not be used. */27 }2829 /* ... Rest of task code. */30 }