0
0
FreeRTOSprogramming~10 mins

uxTaskPriorityGet() for reading priority in FreeRTOS - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - uxTaskPriorityGet() for reading priority
Call uxTaskPriorityGet(taskHandle)
Check if taskHandle is NULL?
NoAccess task's priority
Return task priority
Return current task's priority
Output priority value
The function checks if a task handle is given. If NULL, it returns the priority of the current task. Otherwise, it returns the priority of the specified task.
Execution Sample
FreeRTOS
TaskHandle_t myTask = xTaskGetCurrentTaskHandle();
UBaseType_t prio = uxTaskPriorityGet(myTask);
printf("Priority: %u\n", prio);
This code gets the current task handle, reads its priority using uxTaskPriorityGet(), and prints it.
Execution Table
StepInput taskHandleCheck if NULLPriority AccessedReturned PriorityOutput
1myTask (valid handle)NoSpecified task's priority read5Priority: 5
2NULLYesCurrent task's priority read5Priority: 5
3invalid handleNoUndefined behavior (not shown)--
💡 Function returns the priority of the given task or current task if NULL.
Variable Tracker
VariableStartAfter uxTaskPriorityGet callFinal
myTaskValid task handleValid task handleValid task handle
prioUndefined55
Key Moments - 2 Insights
What happens if we pass NULL as the task handle?
If NULL is passed, uxTaskPriorityGet() returns the priority of the current running task, as shown in execution_table row 2.
Can uxTaskPriorityGet() be used with an invalid task handle?
No, passing an invalid handle leads to undefined behavior, which is not safe and not shown in the execution table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what priority is returned when passing a valid task handle?
A5
B0
CUndefined
DNULL
💡 Hint
See execution_table row 1 under 'Returned Priority' column.
At which step does the function return the current task's priority because the input is NULL?
AStep 1
BStep 3
CStep 2
DNever
💡 Hint
Check execution_table row 2 where 'Input taskHandle' is NULL.
If the variable 'prio' is 5 after the call, what was the likely input task handle?
ANULL
BValid task handle
CInvalid handle
DUninitialized
💡 Hint
Refer to variable_tracker and execution_table rows 1 and 2.
Concept Snapshot
uxTaskPriorityGet(taskHandle) returns the priority of the given task.
If taskHandle is NULL, it returns the current task's priority.
Priority is of type UBaseType_t (usually an unsigned int).
Passing invalid handles causes undefined behavior.
Use this to check task priority safely.
Full Transcript
The uxTaskPriorityGet() function reads the priority of a FreeRTOS task. When you call it with a task handle, it checks if the handle is NULL. If it is NULL, it returns the priority of the current running task. Otherwise, it returns the priority of the specified task. The priority is returned as an unsigned integer. Passing an invalid task handle is unsafe and can cause errors. This function helps you know the priority level of tasks in your system.