Consider the following FreeRTOS code snippet. What will be the output printed by printf?
#include "FreeRTOS.h" #include "task.h" #include <stdio.h> void vTaskFunction(void *pvParameters) { // Task code here vTaskDelete(NULL); } int main() { TaskHandle_t xTaskHandle = NULL; BaseType_t xReturned; UBaseType_t uxPriority; xReturned = xTaskCreate(vTaskFunction, "Task1", configMINIMAL_STACK_SIZE, NULL, 3, &xTaskHandle); if(xReturned == pdPASS) { uxPriority = uxTaskPriorityGet(xTaskHandle); printf("Task priority: %u\n", (unsigned int)uxPriority); } return 0; }
Remember that uxTaskPriorityGet() returns the priority assigned when the task was created.
The task was created with priority 3, so uxTaskPriorityGet() returns 3. Option A is wrong because 0 is the idle priority. Option A is wrong because configMAX_PRIORITIES is the max allowed, not assigned. Option A is wrong because the task handle is correctly passed.
In FreeRTOS, what is the return value of uxTaskPriorityGet(NULL) when called from within a task?
Passing NULL means the function uses the current task handle internally.
When uxTaskPriorityGet() is called with NULL, it returns the priority of the task that called the function. It does not cause an error or return zero.
A developer creates a task with priority 4 but uxTaskPriorityGet() returns 0 for that task's handle. What is the most likely cause?
Check if the task handle is properly assigned after task creation.
If the task handle is invalid or NULL, uxTaskPriorityGet() may return 0 because it cannot find the task's priority. Other options are less likely because priority 0 means idle, and kernel not started or deleted task would cause different behaviors.
Which of the following code snippets correctly uses uxTaskPriorityGet() to read the priority of a task?
Check the function signature and parameter types.
uxTaskPriorityGet() takes a TaskHandle_t (not a pointer to it) and returns UBaseType_t. Option B matches this. Option B uses wrong return type. Option B passes pointer incorrectly. Option B passes two parameters which is invalid.
Write the correct sequence of code lines to get and print the priority of the currently running task in FreeRTOS.
Declare variables first, then get current task handle, then get priority, then print.
The correct order is to declare variables (1,2), get current task handle (3), get priority (4), then print (5). Options that get handle before declaring variables or mix order are invalid.