0
0
FreeRTOSprogramming~30 mins

vTaskPrioritySet() dynamic priority in FreeRTOS - Mini Project: Build & Apply

Choose your learning style9 modes available
Using vTaskPrioritySet() to Change Task Priority Dynamically
📖 Scenario: You are working on a FreeRTOS-based embedded system with two tasks: a SensorTask and a LoggerTask. Initially, the SensorTask has a higher priority to read sensor data frequently. However, when the LoggerTask needs to write data to storage, it should temporarily get a higher priority to avoid data loss.
🎯 Goal: Build a FreeRTOS program that creates two tasks with initial priorities, then dynamically changes the LoggerTask's priority using vTaskPrioritySet() to a higher priority, and finally prints the current priorities of both tasks.
📋 What You'll Learn
Create two tasks named SensorTask and LoggerTask with initial priorities 2 and 1 respectively.
Create a variable loggerNewPriority and set it to 3.
Use vTaskPrioritySet() to change LoggerTask priority to loggerNewPriority.
Print the priorities of both tasks after the change.
💡 Why This Matters
🌍 Real World
In embedded systems, dynamically changing task priorities helps manage critical operations that need immediate attention, like logging important data or handling interrupts.
💼 Career
Understanding task priority management is essential for embedded software engineers working with real-time operating systems like FreeRTOS to ensure system responsiveness and reliability.
Progress0 / 4 steps
1
Create two tasks with initial priorities
Create two FreeRTOS tasks named SensorTask and LoggerTask with initial priorities 2 and 1 respectively. Use xTaskCreate() to create both tasks and store their handles in variables sensorTaskHandle and loggerTaskHandle.
FreeRTOS
Need a hint?

Use xTaskCreate() with the correct task function, name, stack size, parameters, priority, and handle pointer.

2
Create a variable for the new LoggerTask priority
Create an integer variable called loggerNewPriority and set it to 3.
FreeRTOS
Need a hint?

Declare int loggerNewPriority = 3; inside main() before starting the scheduler.

3
Change LoggerTask priority dynamically
Use vTaskPrioritySet() to change the priority of LoggerTask to the value stored in loggerNewPriority. Place this call inside main() after creating the tasks and before starting the scheduler.
FreeRTOS
Need a hint?

Call vTaskPrioritySet(loggerTaskHandle, loggerNewPriority); inside main() after task creation.

4
Print the priorities of both tasks
Use uxTaskPriorityGet() to get the priorities of SensorTask and LoggerTask. Then print their priorities using printf(). Place this code inside main() after changing the LoggerTask priority and before starting the scheduler.
FreeRTOS
Need a hint?

Use uxTaskPriorityGet() to get priorities and printf() to display them.