This function helps you find out the priority level of a task in FreeRTOS. Knowing a task's priority helps you understand which tasks run first.
uxTaskPriorityGet() for reading priority in FreeRTOS
UBaseType_t uxTaskPriorityGet( TaskHandle_t xTask );
TaskHandle_t xTask is the handle (ID) of the task you want to check. If you pass NULL, it returns the priority of the current task.
The function returns the priority as a number where higher means more important.
UBaseType_t priority = uxTaskPriorityGet( NULL );
UBaseType_t priority = uxTaskPriorityGet( myTaskHandle );
This program creates a task with priority 3. Inside the task, it reads its own priority using uxTaskPriorityGet(NULL) and prints it. Then the task deletes itself.
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void vTaskFunction(void *pvParameters) { UBaseType_t priority = uxTaskPriorityGet(NULL); // Get current task priority printf("Current task priority: %u\n", (unsigned int)priority); vTaskDelete(NULL); // Delete this task after printing } int main(void) { TaskHandle_t taskHandle = NULL; xTaskCreate(vTaskFunction, "Task1", configMINIMAL_STACK_SIZE, NULL, 3, &taskHandle); vTaskStartScheduler(); return 0; }
Passing NULL to uxTaskPriorityGet() returns the priority of the task that calls the function.
Task priorities are numbers where a higher number means higher priority.
Make sure the task handle you pass is valid to avoid errors.
uxTaskPriorityGet() reads the priority of a task in FreeRTOS.
Pass NULL to get the current task's priority.
Useful for debugging and managing task scheduling.