Complete the code to create a queue that can hold 5 integers.
QueueHandle_t queue = xQueueCreate([1], sizeof(int));The function xQueueCreate takes the number of items the queue can hold as the first argument. Here, 5 means the queue can hold 5 integers.
Complete the code to send an integer to the queue without blocking.
int value = 10; BaseType_t result = xQueueSend(queue, &value, [1]);
Using 0 as the block time means the function will not wait if the queue is full and will return immediately.
Fix the error in the code to receive an item from the queue with a 10 tick timeout.
int receivedValue; if (xQueueReceive(queue, &receivedValue, [1]) == pdPASS) { // Process receivedValue }
The block time parameter should be set to 10 ticks to wait up to 10 ticks for an item to be received.
Fill both blanks to check if the queue is full before sending an item.
if (uxQueueSpacesAvailable(queue) [1] 0) { xQueueSend(queue, &item, [2]); }
Checking if available spaces are greater than 0 ensures the queue is not full. Using portMAX_DELAY allows waiting indefinitely to send the item.
Fill all three blanks to create a non-blocking receive with a check for empty queue.
if (uxQueueMessagesWaiting(queue) [1] 0) { xQueueReceive(queue, &data, [2]); } else { // Queue empty, handle accordingly vTaskDelay([3]); }
Checking if messages waiting is greater than 0 confirms the queue is not empty. Using 0 as block time makes receive non-blocking. Using 1 tick delay helps avoid busy waiting.
