0
0
FreeRTOSprogramming~30 mins

Priority-based scheduling in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Priority-based scheduling
📖 Scenario: You are working on a small embedded system that uses FreeRTOS. You want to create tasks with different priorities to see how FreeRTOS schedules them.
🎯 Goal: Create three tasks with different priorities and observe how FreeRTOS runs the highest priority task first.
📋 What You'll Learn
Create three tasks named Task1, Task2, and Task3.
Assign priorities 1, 2, and 3 to Task1, Task2, and Task3 respectively.
Each task should print its name once when it runs.
Start the FreeRTOS scheduler to run the tasks.
💡 Why This Matters
🌍 Real World
Embedded systems often need to run multiple tasks with different importance levels. Priority-based scheduling helps ensure critical tasks run first.
💼 Career
Understanding FreeRTOS task priorities is essential for embedded software developers working on real-time applications like IoT devices, automotive systems, and industrial controllers.
Progress0 / 4 steps
1
Create three tasks with empty functions
Create three task functions called Task1, Task2, and Task3. Each function should have the correct FreeRTOS task signature and an infinite loop with no code inside.
FreeRTOS
Need a hint?

Each task function must have the signature void TaskName(void *pvParameters) and an infinite loop for(;;).

2
Create task handles and add tasks with priorities
Create three task handles called xTask1Handle, xTask2Handle, and xTask3Handle. Use xTaskCreate to create Task1 with priority 1, Task2 with priority 2, and Task3 with priority 3. Use stack size 100 for all tasks and pass NULL as parameters.
FreeRTOS
Need a hint?

Use xTaskCreate with the correct parameters: function, name, stack size, parameters, priority, and handle.

3
Add print statements inside each task
Inside the infinite loop of each task function, add a printf statement that prints the task name: "Running Task1\n" in Task1, "Running Task2\n" in Task2, and "Running Task3\n" in Task3. Add a vTaskDelay(1000 / portTICK_PERIOD_MS); after the print to delay 1 second.
FreeRTOS
Need a hint?

Use printf to print the task name and vTaskDelay to pause the task for 1 second.

4
Start the FreeRTOS scheduler
Add the call vTaskStartScheduler(); after creating the tasks to start the FreeRTOS scheduler.
FreeRTOS
Need a hint?

Call vTaskStartScheduler(); to start running the tasks.