0
0
FreeRTOSprogramming~20 mins

uxTaskPriorityGet() for reading priority in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Priority Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of uxTaskPriorityGet() for a created task?

Consider the following FreeRTOS code snippet. What will be the output printed by printf?

FreeRTOS
#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;
}
ATask priority: 3
BTask priority: 0
CCompilation error due to missing task handle
DTask priority: configMAX_PRIORITIES
Attempts:
2 left
💡 Hint

Remember that uxTaskPriorityGet() returns the priority assigned when the task was created.

🧠 Conceptual
intermediate
1:30remaining
What does uxTaskPriorityGet() return if passed NULL?

In FreeRTOS, what is the return value of uxTaskPriorityGet(NULL) when called from within a task?

AThe priority of the calling task
BZero (lowest priority)
CconfigMAX_PRIORITIES
DCauses a runtime error
Attempts:
2 left
💡 Hint

Passing NULL means the function uses the current task handle internally.

🔧 Debug
advanced
2:30remaining
Why does uxTaskPriorityGet() return 0 unexpectedly?

A developer creates a task with priority 4 but uxTaskPriorityGet() returns 0 for that task's handle. What is the most likely cause?

AThe FreeRTOS kernel is not started yet
BThe task priority was set to 0 after creation
CThe task handle passed to <code>uxTaskPriorityGet()</code> is invalid or uninitialized
DThe task was deleted before calling <code>uxTaskPriorityGet()</code>
Attempts:
2 left
💡 Hint

Check if the task handle is properly assigned after task creation.

📝 Syntax
advanced
1:30remaining
Which code snippet correctly reads a task's priority?

Which of the following code snippets correctly uses uxTaskPriorityGet() to read the priority of a task?

AUBaseType_t prio = uxTaskPriorityGet(&xTaskHandle);
BUBaseType_t prio = uxTaskPriorityGet(xTaskHandle);
Cint prio = uxTaskPriorityGet(xTaskHandle);
DUBaseType_t prio = uxTaskPriorityGet(NULL, xTaskHandle);
Attempts:
2 left
💡 Hint

Check the function signature and parameter types.

🚀 Application
expert
3:00remaining
How to check and print the priority of the current task safely?

Write the correct sequence of code lines to get and print the priority of the currently running task in FreeRTOS.

A3,4,1,2,5
B3,1,4,2,5
C1,3,2,4,5
D1,2,3,4,5
Attempts:
2 left
💡 Hint

Declare variables first, then get current task handle, then get priority, then print.