0
0
FreeRTOSprogramming~10 mins

Resource manager task pattern in FreeRTOS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Resource manager task pattern
Start Resource Manager Task
Wait for Request Queue
Receive Request
Process Request
Send Response
Loop Back to Wait
The resource manager task waits for requests, processes them one by one, sends responses, and loops back to wait for more.
Execution Sample
FreeRTOS
void ResourceManagerTask(void *pvParameters) {
  Request_t req;
  for (;;) {
    if (xQueueReceive(requestQueue, &req, portMAX_DELAY) == pdTRUE) {
      ProcessRequest(&req);
      xQueueSend(responseQueue, &req.response, 0);
    }
  }
}
This task waits for requests on a queue, processes each request, then sends a response back.
Execution Table
StepActionQueue Receive ResultRequest DataProcess RequestSend ResponseLoop Back
1Wait for requestNo data yet---Waiting
2Receive requestSuccessRequest 1Process Request 1Send Response 1Loop back
3Wait for requestNo data yet---Waiting
4Receive requestSuccessRequest 2Process Request 2Send Response 2Loop back
5Wait for requestNo data yet---Waiting
ExitNo exit in infinite loop----Task runs forever
💡 The task runs in an infinite loop, always waiting for new requests.
Variable Tracker
VariableStartAfter Step 2After Step 4Final
reqemptyRequest 1 dataRequest 2 dataRequest 2 data
requestQueuecontains requestsRequest 2 remainsempty or new requestsvaries
responseQueueemptyResponse 1 addedResponse 2 addedcontains responses
Key Moments - 3 Insights
Why does the task use an infinite loop with xQueueReceive?
Because the task must keep running to handle all incoming requests, as shown in execution_table rows 2 and 4 where it loops back to wait again.
What happens if no request is available in the queue?
The task blocks on xQueueReceive (portMAX_DELAY), waiting without using CPU, as seen in execution_table rows 1, 3, and 5.
How does the task send a response after processing?
It uses xQueueSend to put the response in the responseQueue immediately after processing, as shown in execution_table steps 2 and 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What is the value of 'req' after receiving the request?
Aempty
BRequest 1 data
CResponse 1 data
DRequest 2 data
💡 Hint
Check the 'Request Data' column at step 2 in the execution_table.
At which step does the task send the response for Request 2?
AStep 1
BStep 2
CStep 4
DStep 5
💡 Hint
Look at the 'Send Response' column for Request 2 in the execution_table.
If the requestQueue is empty, what does the task do according to the execution_table?
ABlocks and waits for a request
BExits the loop
CProcesses a default request
DSends an empty response
💡 Hint
See the 'Queue Receive Result' and 'Loop Back' columns in steps 1, 3, and 5.
Concept Snapshot
Resource Manager Task Pattern in FreeRTOS:
- Runs an infinite loop waiting on a request queue
- Uses xQueueReceive with portMAX_DELAY to block until a request arrives
- Processes each request sequentially
- Sends response via a response queue
- Ensures safe, serialized access to shared resources
Full Transcript
The Resource Manager Task pattern in FreeRTOS uses a dedicated task that runs forever in a loop. It waits for requests by blocking on a queue receive call. When a request arrives, the task processes it and sends a response back through another queue. This pattern ensures only one task accesses the shared resource at a time, avoiding conflicts. The task blocks when no requests are available, saving CPU time. After handling each request, it loops back to wait for the next one, running continuously.