0
0
FreeRTOSprogramming~5 mins

uxTaskPriorityGet() for reading priority in FreeRTOS

Choose your learning style9 modes available
Introduction

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.

When you want to check the priority of a task to debug scheduling issues.
When you need to adjust behavior based on the priority of a task.
When you want to log or display task priorities for monitoring.
When you are creating a task manager and need to show task priorities.
Syntax
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.

Examples
Get the priority of the current running task.
FreeRTOS
UBaseType_t priority = uxTaskPriorityGet( NULL );
Get the priority of a specific task using its handle.
FreeRTOS
UBaseType_t priority = uxTaskPriorityGet( myTaskHandle );
Sample Program

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.

FreeRTOS
#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;
}
OutputSuccess
Important Notes

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.

Summary

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.