0
0
FreeRTOSprogramming~30 mins

Task priority assignment in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Task Priority Assignment in FreeRTOS
📖 Scenario: You are working on a simple embedded system using FreeRTOS. You need to create tasks with different priorities to manage how the system handles multiple jobs.
🎯 Goal: Build a FreeRTOS program that creates two tasks with specific priorities and prints messages showing which task is running.
📋 What You'll Learn
Create two tasks named Task1 and Task2
Assign Task1 a priority of 2
Assign Task2 a priority of 1
Each task should print a message indicating it is running
Start the FreeRTOS scheduler
💡 Why This Matters
🌍 Real World
Embedded systems often run multiple tasks like sensor reading, communication, and control. Assigning priorities helps manage which tasks get CPU time first.
💼 Career
Understanding task priority assignment is essential for embedded software engineers working with real-time operating systems like FreeRTOS.
Progress0 / 4 steps
1
Create two task functions
Write two task functions named Task1 and Task2. Each function should be an infinite loop that prints "Task 1 is running" and "Task 2 is running" respectively, then calls vTaskDelay(1000 / portTICK_PERIOD_MS) to wait for 1 second.
FreeRTOS
Need a hint?

Use while(1) loops inside each task function to keep them running. Use printf to print messages and vTaskDelay to pause.

2
Create task handles and priority variables
Declare two task handles named xTask1Handle and xTask2Handle. Also, create two variables task1Priority and task2Priority and set them to 2 and 1 respectively.
FreeRTOS
Need a hint?

Use TaskHandle_t to declare task handles. Use const UBaseType_t for priority variables.

3
Create tasks with assigned priorities
Use xTaskCreate to create Task1 and Task2 with their respective priorities task1Priority and task2Priority. Pass the task handles xTask1Handle and xTask2Handle to store the created tasks.
FreeRTOS
Need a hint?

Use xTaskCreate with parameters: function name, task name string, stack size, parameters (NULL), priority, and task handle address.

4
Start the scheduler and print confirmation
Call vTaskStartScheduler() to start the FreeRTOS scheduler. Then print "Scheduler started" before starting. This will run the tasks with their assigned priorities.
FreeRTOS
Need a hint?

Call vTaskStartScheduler() after printing the message to begin running the tasks.