Complete the code to create a queue for the producer-consumer pattern.
QueueHandle_t xQueue = xQueueCreate([1], sizeof(int));The queue size must be specified as a number, here 10, to hold 10 items.
Complete the code to send data from the producer to the queue.
xQueueSend([1], &data, portMAX_DELAY);The queue handle xQueue is used to send data to the queue.
Fix the error in the consumer task to receive data from the queue.
if(xQueueReceive([1], &receivedData, portMAX_DELAY) == pdPASS) { // process receivedData }
The queue handle xQueue must be used to receive data from the queue.
Fill both blanks to create a producer task that sends data to the queue and delays.
void vProducerTask(void *pvParameters) {
int data = 0;
for(;;) {
xQueue[1](xQueue, &data, portMAX_DELAY);
data++;
vTask[2](pdMS_TO_TICKS(1000));
}
}The producer sends data with xQueueSend and delays with vTaskDelay.
Fill all three blanks to create a consumer task that receives data, processes it, and delays.
void vConsumerTask(void *pvParameters) {
int receivedData;
for(;;) {
if(xQueue[1](xQueue, &receivedData, portMAX_DELAY) == pdPASS) {
processData([2]);
}
vTask[3](pdMS_TO_TICKS(500));
}
}The consumer receives data with xQueueReceive, processes the receivedData variable, and delays with vTaskDelay.