myTaskHandle.taskPriority to store the priority.uxTaskPriorityGet() with myTaskHandle to get the priority.printf().myTaskHandle.taskPriority to store the priority.uxTaskPriorityGet() with myTaskHandle to get the priority.printf().myTaskHandle of type TaskHandle_t and set it to NULL.This variable will hold the handle of the task whose priority you want to read.
taskPriority of type UBaseType_t to store the task priority.This variable will hold the priority value returned by uxTaskPriorityGet().
uxTaskPriorityGet(myTaskHandle) to the variable taskPriority.This function returns the priority of the task whose handle is myTaskHandle.
printf() to display the text "Task priority is: " followed by the value of taskPriority.The printed priority will be 0 because myTaskHandle is NULL (no task assigned).
What does the FreeRTOS function uxTaskPriorityGet() do?
uxTaskPriorityGet() is designed to read the priority of a task, not to modify or manage tasks.Which of the following is the correct way to get the priority of the current task using uxTaskPriorityGet()?
TaskHandle_t xTaskHandle;
UBaseType_t uxPriority = ?;NULL to uxTaskPriorityGet() returns the priority of the current task.uxPriority = uxTaskPriorityGet(xTaskHandle); uses uninitialized xTaskHandle (undefined behavior). uxPriority = uxTaskPriorityGet(&xTaskHandle); passes address (wrong type). uxPriority = uxTaskPriorityGet(*xTaskHandle); dereferences uninitialized handle (crash). Only uxPriority = uxTaskPriorityGet(NULL); is correct.Given the following code snippet, what will be printed?
TaskHandle_t xHandle = xTaskGetHandle("Task1");
UBaseType_t uxPriority = uxTaskPriorityGet(xHandle);
printf("Priority: %u\n", uxPriority);Assume "Task1" exists and has priority 3.
xTaskGetHandle("Task1") returns the handle of the task named "Task1" which exists with priority 3.uxTaskPriorityGet(xHandle) returns the priority of that task, which is 3.Identify the error in this code snippet:
TaskHandle_t xHandle;
UBaseType_t uxPriority = uxTaskPriorityGet(xHandle);
printf("Priority: %u\n", uxPriority);xHandle is declared but not assigned any value before use.uxTaskPriorityGet() leads to undefined behavior or incorrect priority reading.You want to check if the current task has higher priority than another task named "WorkerTask". Which code snippet correctly compares their priorities?
TaskHandle_t xWorkerHandle = xTaskGetHandle("WorkerTask");
UBaseType_t uxCurrentPriority = uxTaskPriorityGet(NULL);
UBaseType_t uxWorkerPriority = uxTaskPriorityGet(xWorkerHandle);
// What next?Pass the test and this pattern moves unknown