Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Updated Mar 2025

xQueueCreate

[Queue Management]

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()
then the required RAM is automatically allocated from the FreeRTOS heap. If a queue is created using xQueueCreateStatic() then the RAM is provided by the application writer, which results in a greater number of parameters, but allows the RAM to be statically allocated at compile time. See the Static Vs Dynamic allocation page for more information.

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 AMessage
2{
3 char ucMessageID;
4 char ucData[ 20 ];
5};
6
7void vATask( void *pvParameters )
8{
9QueueHandle_t xQueue1, xQueue2;
10
11 /* Create a queue capable of containing 10 unsigned long values. */
12 xQueue1 = xQueueCreate( 10, sizeof( unsigned long ) );
13
14 if( xQueue1 == NULL )
15 {
16 /* Queue was not created and must not be used. */
17 }
18
19 /* Create a queue capable of containing 10 pointers to AMessage
20 structures. These are to be queued by pointers as they are
21 relatively large structures. */
22 xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
23
24 if( xQueue2 == NULL )
25 {
26 /* Queue was not created and must not be used. */
27 }
28
29 /* ... Rest of task code. */
30 }