What is the purpose of the xQueueCreate() function in FreeRTOS?
The xQueueCreate() function creates a new queue that can hold a fixed number of items, each of a fixed size. It is used to pass data safely between tasks or between interrupts and tasks.
Click to reveal answer
beginner
What are the two main parameters of xQueueCreate()?
The two main parameters are: 1. uxQueueLength: The maximum number of items the queue can hold. 2. uxItemSize: The size in bytes of each item stored in the queue.
Click to reveal answer
beginner
What does xQueueCreate() return if the queue creation is successful?
It returns a handle to the created queue, which is used in other queue API functions to reference this queue.
Click to reveal answer
intermediate
What happens if xQueueCreate() fails to create a queue?
If the queue cannot be created (for example, due to insufficient memory), xQueueCreate() returns NULL.
Click to reveal answer
intermediate
Why is it important to specify the item size correctly when using xQueueCreate()?
Because the queue stores copies of items, specifying the correct item size ensures that the entire data item is copied and retrieved correctly. If the size is too small, data may be truncated; if too large, memory is wasted.
Click to reveal answer
What does the uxQueueLength parameter specify in xQueueCreate()?
AThe size of each item in bytes
BThe timeout for queue operations
CThe priority of the queue
DThe maximum number of items the queue can hold
✗ Incorrect
The uxQueueLength parameter sets how many items the queue can hold at once.
What is returned by xQueueCreate() if the queue is created successfully?
AAn error code
BNULL
CA queue handle
DThe size of the queue
✗ Incorrect
A handle to the queue is returned to be used in other queue functions.
If xQueueCreate() returns NULL, what does it mean?
AQueue creation failed due to insufficient memory
BQueue was created successfully
CThe queue is empty
DThe queue is full
✗ Incorrect
NULL indicates failure to create the queue, often due to lack of memory.
Why must the uxItemSize parameter be set correctly?
ATo define the queue timeout
BTo ensure the entire data item is copied into the queue
CTo specify the number of items in the queue
DTo set the queue priority
✗ Incorrect
The item size tells the queue how many bytes to copy for each item.
Which of the following is NOT a use of xQueueCreate()?
ACreating a queue to store task priorities
BCreating a queue for passing data from interrupts to tasks
CCreating a queue for inter-task communication
DCreating a queue to hold fixed-size data items
✗ Incorrect
Queues do not store task priorities; they store data items for communication.
Explain how to use xQueueCreate() to create a queue and what each parameter means.
Think about how you set the size and capacity of a mailbox to hold letters.
You got /3 concepts.
Describe what happens if xQueueCreate() fails and how you can detect this in your code.
Consider what you do if you try to open a mailbox but it doesn't exist.
You got /3 concepts.
Practice
(1/5)
1. What does the xQueueCreate() function do in FreeRTOS?
easy
A. Sends data to a queue
B. Creates a new queue to hold data items between tasks
C. Deletes an existing queue
D. Receives data from a queue
Solution
Step 1: Understand the purpose of xQueueCreate()
The function is designed to create a new queue in FreeRTOS for inter-task communication.
Step 2: Differentiate from other queue functions
Functions like sending or receiving data operate on existing queues, not create them.
Final Answer:
Creates a new queue to hold data items between tasks -> Option B
Quick Check:
xQueueCreate() = create queue [OK]
Hint: xQueueCreate() always makes a new queue [OK]
Common Mistakes:
Confusing creation with sending or receiving data
Thinking it deletes a queue
Assuming it initializes queue data
2. Which of the following is the correct syntax to create a queue for 10 items, each of size sizeof(int)?
easy
A. xQueueCreate(10, sizeof(int));
B. xQueueCreate(sizeof(int), 10);
C. xQueueCreate(10);
D. xQueueCreate(sizeof(int));
Solution
Step 1: Recall xQueueCreate() parameters
The first parameter is the number of items, the second is the size of each item.
Step 2: Match parameters to options
xQueueCreate(10, sizeof(int)); correctly uses 10 items and sizeof(int) as size per item.
Final Answer:
xQueueCreate(10, sizeof(int)); -> Option A
Quick Check:
Parameters = (number, size) [OK]
Hint: First param = count, second = size [OK]
Common Mistakes:
Swapping the order of parameters
Providing only one parameter
Using raw numbers instead of sizeof()
3. Consider this code snippet:
QueueHandle_t q = xQueueCreate(5, sizeof(char));
if (q == NULL) {
printf("Queue creation failed\n");
} else {
printf("Queue created successfully\n");
}
What will be printed if the queue is created successfully?
medium
A. Queue creation failed
B. Compilation error
C. Queue created successfully
D. No output
Solution
Step 1: Check the return value of xQueueCreate()
If queue creation succeeds, it returns a non-NULL handle.
Step 2: Analyze the if condition
The code prints "Queue created successfully" when q is not NULL.
Final Answer:
Queue created successfully -> Option C
Quick Check:
q != NULL means success [OK]
Hint: Check if queue handle is NULL for failure [OK]