0
0
FreeRTOSprogramming~20 mins

Resource manager task pattern in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
FreeRTOS Resource Manager 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 this FreeRTOS resource manager task code?

Consider a FreeRTOS task that manages access to a shared resource using a queue. What will be printed when the task receives a request?

FreeRTOS
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include <stdio.h>

QueueHandle_t resourceQueue;

void ResourceManagerTask(void *pvParameters) {
    char *request;
    while(1) {
        if(xQueueReceive(resourceQueue, &request, portMAX_DELAY) == pdPASS) {
            printf("Processing request: %s\n", request);
            vTaskDelay(pdMS_TO_TICKS(100));
        }
    }
}

int main() {
    resourceQueue = xQueueCreate(5, sizeof(char*));
    xTaskCreate(ResourceManagerTask, "ResMgr", 1000, NULL, 1, NULL);
    char *req = "Task1 Request";
    xQueueSend(resourceQueue, &req, 0);
    vTaskStartScheduler();
    return 0;
}
AProcessing request: Task1 Request
BProcessing request: (null)
CCompilation error due to missing queue initialization
DRuntime error: Queue handle is NULL
Attempts:
2 left
💡 Hint

Check how the queue is created and how the request is sent and received.

🧠 Conceptual
intermediate
1:30remaining
Which synchronization primitive is best for a FreeRTOS resource manager task to protect a shared resource?

In a FreeRTOS resource manager task pattern, which synchronization method ensures exclusive access to a shared resource?

ABinary semaphore
BMutex
CCounting semaphore
DEvent group
Attempts:
2 left
💡 Hint

Think about priority inheritance and exclusive access.

🔧 Debug
advanced
2:30remaining
What error does this FreeRTOS resource manager task code produce?

Analyze the code below. What error will occur when running this resource manager task?

FreeRTOS
QueueHandle_t resourceQueue;

void ResourceManagerTask(void *pvParameters) {
    char request[20];
    while(1) {
        if(xQueueReceive(resourceQueue, &request, portMAX_DELAY) == pdPASS) {
            printf("Request: %s\n", request);
        }
    }
}

int main() {
    resourceQueue = xQueueCreate(5, sizeof(char*));
    xTaskCreate(ResourceManagerTask, "ResMgr", 1000, NULL, 1, NULL);
    char req[] = "Request1";
    xQueueSend(resourceQueue, &req, 0);
    vTaskStartScheduler();
    return 0;
}
AIncorrect output: prints garbage instead of request string
BNo error, prints 'Request1' correctly
CCompilation error: incompatible pointer types
DRuntime error: Stack overflow in ResourceManagerTask
Attempts:
2 left
💡 Hint

Check the queue item size and what is sent/received.

📝 Syntax
advanced
1:30remaining
Which option fixes the syntax error in this FreeRTOS resource manager task snippet?

Identify the correct fix for the syntax error in the following snippet:

if xQueueReceive(resourceQueue, &request, portMAX_DELAY) == pdPASS {
    processRequest(request);
}
A
if (xQueueReceive(resourceQueue, &amp;request, portMAX_DELAY) == pdPASS) then {
    processRequest(request);
}
B
if xQueueReceive(resourceQueue, &amp;request, portMAX_DELAY) == pdPASS then {
    processRequest(request);
}
C
if xQueueReceive(resourceQueue, &amp;request, portMAX_DELAY) == pdPASS:
    processRequest(request);
D
if (xQueueReceive(resourceQueue, &amp;request, portMAX_DELAY) == pdPASS) {
    processRequest(request);
}
Attempts:
2 left
💡 Hint

Remember C syntax for if statements.

🚀 Application
expert
1:00remaining
How many items can the FreeRTOS resource manager queue hold in this configuration?

Given the queue creation below, how many items can it hold?

resourceQueue = xQueueCreate(10, sizeof(int));
ACannot hold any items because size is incorrect
B1 item, size 10 * sizeof(int)
C10 items, each of size int
DDepends on the FreeRTOS heap size only
Attempts:
2 left
💡 Hint

Check the parameters of xQueueCreate.