0
0
FreeRTOSprogramming~30 mins

Producer-consumer pattern in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Producer-Consumer Pattern with FreeRTOS
📖 Scenario: You are building a simple embedded system using FreeRTOS where one task produces data and another task consumes it. This pattern helps manage data flow safely between tasks.
🎯 Goal: Create two FreeRTOS tasks: a producer task that sends numbers to a queue, and a consumer task that receives and prints those numbers.
📋 What You'll Learn
Create a FreeRTOS queue to hold integers
Create a producer task that sends numbers 1 to 5 to the queue
Create a consumer task that receives numbers from the queue
Print each received number in the consumer task
💡 Why This Matters
🌍 Real World
Producer-consumer patterns are common in embedded systems to manage data flow between sensors and processing tasks without data loss.
💼 Career
Understanding FreeRTOS task communication is essential for embedded software engineers working on real-time applications.
Progress0 / 4 steps
1
Create a FreeRTOS queue
Create a FreeRTOS queue called queue that can hold 5 integers using xQueueCreate(5, sizeof(int)).
FreeRTOS
Need a hint?

Use xQueueCreate with 5 as the number of items and sizeof(int) as the size of each item.

2
Create the producer task
Create a FreeRTOS task called producer using xTaskCreate. The producer task should send numbers 1 to 5 to the queue using xQueueSend inside a loop.
FreeRTOS
Need a hint?

Use xTaskCreate with the producer function, a name, stack size 1000, no parameters, priority 1, and no task handle.

3
Create the consumer task
Create a FreeRTOS task called consumer using xTaskCreate. The consumer task should receive numbers from the queue using xQueueReceive inside a loop and print each number using printf.
FreeRTOS
Need a hint?

Use xTaskCreate to create the consumer task and then start the scheduler with vTaskStartScheduler().

4
Run and observe the output
Run the program and observe the printed output from the consumer task. The output should show the numbers 1 to 5 received from the producer task.
FreeRTOS
Need a hint?

Check that the consumer prints all numbers from 1 to 5 in order.