0
0
FreeRTOSprogramming~30 mins

Resource manager task pattern in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Resource Manager Task Pattern in FreeRTOS
📖 Scenario: You are building a simple embedded system using FreeRTOS. The system has multiple tasks that need to access a shared resource, such as a sensor or communication interface. To avoid conflicts, you will create a resource manager task that controls access to this shared resource.
🎯 Goal: Build a FreeRTOS program where a dedicated ResourceManagerTask manages access requests from other tasks using a queue. The resource manager grants access one task at a time, demonstrating the resource manager task pattern.
📋 What You'll Learn
Create a queue to hold resource access requests
Create a ResourceManagerTask that waits for requests and grants access
Create two tasks (Task1 and Task2) that send access requests to the resource manager
Print messages showing when tasks request and receive the resource
💡 Why This Matters
🌍 Real World
Embedded systems often have multiple tasks needing access to a single hardware resource. Using a resource manager task pattern helps coordinate access safely and efficiently.
💼 Career
Understanding resource management in FreeRTOS is essential for embedded software engineers working on real-time systems like IoT devices, automotive controllers, and industrial automation.
Progress0 / 4 steps
1
Create the queue for resource requests
Create a FreeRTOS queue called resourceQueue that can hold 5 integers. Use xQueueCreate(5, sizeof(int)) and assign it to resourceQueue.
FreeRTOS
Need a hint?

Use xQueueCreate with length 5 and item size sizeof(int).

2
Create the ResourceManagerTask
Create a FreeRTOS task called ResourceManagerTask with priority 2 and stack size 1000. The task should run a function named ResourceManagerTaskFunction. Use xTaskCreate(ResourceManagerTaskFunction, "ResourceManagerTask", 1000, NULL, 2, NULL).
FreeRTOS
Need a hint?

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

3
Implement ResourceManagerTaskFunction to handle requests
Write the function ResourceManagerTaskFunction that runs an infinite loop. Inside the loop, use xQueueReceive(resourceQueue, &request, portMAX_DELAY) to wait for an integer request. When a request is received, print "Resource granted to task %d" with the request value. Use printf for printing.
FreeRTOS
Need a hint?

Use an infinite loop and xQueueReceive to wait for requests. Print the granted message when a request is received.

4
Create two tasks that send requests to the resource manager
Create two tasks named Task1 and Task2 with priority 1 and stack size 1000. Each task runs a function (Task1Function and Task2Function) that sends its task ID (1 or 2) to resourceQueue every 1000 ms using xQueueSend. Print "Task 1 requesting resource" or "Task 2 requesting resource" before sending the request. Use vTaskDelay(pdMS_TO_TICKS(1000)) for delay. Finally, start the scheduler with vTaskStartScheduler().
FreeRTOS
Need a hint?

Create two tasks that send their ID to the queue every second and print a request message. Then start the scheduler.