0
0
FreeRTOSprogramming~30 mins

Task pooling for dynamic workloads in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Task pooling for dynamic workloads
📖 Scenario: You are building a FreeRTOS application that needs to handle multiple tasks dynamically. Instead of creating and deleting tasks repeatedly, you want to use a task pool to reuse tasks efficiently. This helps save system resources and improves performance.
🎯 Goal: Build a simple task pool system in FreeRTOS where a fixed number of tasks wait for work from a queue. When new work arrives, a task picks it up, processes it, and then waits for more work. You will create the data structures, configure the queue, implement the task pool logic, and print the results.
📋 What You'll Learn
Create an array of task handles for the task pool
Create a FreeRTOS queue to hold work items
Implement worker tasks that wait on the queue and process work
Print the processed work item IDs from the tasks
💡 Why This Matters
🌍 Real World
Task pooling is used in embedded systems to efficiently manage limited resources by reusing tasks instead of creating and deleting them repeatedly.
💼 Career
Understanding task pooling and FreeRTOS queues is important for embedded software developers working on real-time systems like IoT devices, automotive controllers, and industrial automation.
Progress0 / 4 steps
1
Create the task pool handles array
Create an array called taskPool of type TaskHandle_t with size 3 to hold the task handles.
FreeRTOS
Need a hint?

Use the syntax TaskHandle_t arrayName[size]; to declare the array.

2
Create the work queue
Create a queue handle called workQueue using QueueHandle_t. Then create the queue with xQueueCreate to hold 5 integers representing work item IDs.
FreeRTOS
Need a hint?

Use QueueHandle_t for the queue handle and xQueueCreate(5, sizeof(int)) to create the queue.

3
Implement the worker task function
Write a function called workerTask that takes void *pvParameters. Inside, declare an integer workItem. Use an infinite loop to call xQueueReceive on workQueue with portMAX_DELAY. When a work item is received, print its ID using printf with the format "Task processed work item: %d\n".
FreeRTOS
Need a hint?

Use an infinite loop with for (;;) and xQueueReceive to wait for work.

4
Create tasks and send work items
Create 3 tasks using xTaskCreate with workerTask, names "Worker1", "Worker2", "Worker3", stack size 1000, no parameters, priority 1, and store their handles in taskPool. Then send 5 work items (integers 1 to 5) to workQueue using xQueueSend. Finally, start the scheduler with vTaskStartScheduler().
FreeRTOS
Need a hint?

Use xTaskCreate to create tasks and xQueueSend to send work items.