0
0
FreeRTOSprogramming~10 mins

Producer-consumer pattern in FreeRTOS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a queue for the producer-consumer pattern.

FreeRTOS
QueueHandle_t xQueue = xQueueCreate([1], sizeof(int));
Drag options to blanks, or click blank then click option'
A10
BxQueueSend
CvTaskDelay
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name instead of a number for queue size.
Passing NULL instead of a number.
2fill in blank
medium

Complete the code to send data from the producer to the queue.

FreeRTOS
xQueueSend([1], &data, portMAX_DELAY);
Drag options to blanks, or click blank then click option'
AxSemaphore
BxQueue
CxTaskHandle
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semaphore handle instead of the queue handle.
Passing NULL as the queue handle.
3fill in blank
hard

Fix the error in the consumer task to receive data from the queue.

FreeRTOS
if(xQueueReceive([1], &receivedData, portMAX_DELAY) == pdPASS) {
    // process receivedData
}
Drag options to blanks, or click blank then click option'
AxSemaphore
BxTaskHandle
CxQueue
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semaphore handle instead of the queue handle.
Passing NULL as the queue handle.
4fill in blank
hard

Fill both blanks to create a producer task that sends data to the queue and delays.

FreeRTOS
void vProducerTask(void *pvParameters) {
    int data = 0;
    for(;;) {
        xQueue[1](xQueue, &data, portMAX_DELAY);
        data++;
        vTask[2](pdMS_TO_TICKS(1000));
    }
}
Drag options to blanks, or click blank then click option'
ASend
BDelay
CReceive
DDelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using xQueueReceive in the producer task.
Using vTaskDelete instead of vTaskDelay.
5fill in blank
hard

Fill all three blanks to create a consumer task that receives data, processes it, and delays.

FreeRTOS
void vConsumerTask(void *pvParameters) {
    int receivedData;
    for(;;) {
        if(xQueue[1](xQueue, &receivedData, portMAX_DELAY) == pdPASS) {
            processData([2]);
        }
        vTask[3](pdMS_TO_TICKS(500));
    }
}
Drag options to blanks, or click blank then click option'
ASend
BreceivedData
CDelay
DReceive
Attempts:
3 left
💡 Hint
Common Mistakes
Using xQueueSend instead of xQueueReceive in the consumer.
Passing wrong variable to processData.
Using vTaskDelete instead of vTaskDelay.