producer task that sends numbers 1 to 5 to the queueconsumer task that receives numbers from the queueconsumer taskproducer task that sends numbers 1 to 5 to the queueconsumer task that receives numbers from the queueconsumer taskqueue that can hold 5 integers using xQueueCreate(5, sizeof(int)).Use xQueueCreate with 5 as the number of items and sizeof(int) as the size of each item.
producer using xTaskCreate. The producer task should send numbers 1 to 5 to the queue using xQueueSend inside a loop.Use xTaskCreate with the producer function, a name, stack size 1000, no parameters, priority 1, and no task handle.
consumer using xTaskCreate. The consumer task should receive numbers from the queue using xQueueReceive inside a loop and print each number using printf.Use xTaskCreate to create the consumer task and then start the scheduler with vTaskStartScheduler().
consumer task. The output should show the numbers 1 to 5 received from the producer task.Check that the consumer prints all numbers from 1 to 5 in order.
In FreeRTOS, what is the main role of the queue in the producer-consumer pattern?
Which of the following is the correct FreeRTOS API call for a producer task to send data to a queue?
void producerTask(void *params) {
int data = 10;
// Send data to queue here
}xQueueSend() to send data from a producer to a queue.xQueueReceive() is for receiving data, xTaskCreate() creates tasks, and vTaskDelay() delays tasks, so they are incorrect here.Consider this FreeRTOS code snippet where a producer sends integers 1 to 3 to a queue and a consumer receives them:
int data;
for (int i = 1; i <= 3; i++) {
xQueueSend(queueHandle, &i, 0);
}
for (int j = 0; j < 3; j++) {
xQueueReceive(queueHandle, &data, 0);
printf("%d ", data);
}What will be the output?
Identify the bug in this FreeRTOS consumer task code that causes it to never receive data:
void consumerTask(void *params) {
int receivedData;
while(1) {
if(xQueueReceive(queueHandle, &receivedData, 0) == pdFALSE) {
// No data received
continue;
}
processData(receivedData);
}
}You want to implement a producer-consumer system where the producer sends sensor readings every 100ms, and the consumer processes them. Which FreeRTOS queue configuration and task design is best to avoid data loss and ensure timely processing?
portMAX_DELAY makes consumer wait indefinitely for data, ensuring it processes every reading.Pass the test and this pattern moves unknown