Complete the code to create a FreeRTOS task that manages a resource.
xTaskCreate([1], "ResourceManager", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, NULL);
The function xTaskCreate needs the task function name as the first argument. Here, ResourceManagerTask is the task function that manages the resource.
Complete the code to wait for a resource request in the resource manager task.
if (xQueueReceive(resourceQueue, &request, [1]) == pdPASS) { // Process request }
Using portMAX_DELAY makes the task wait indefinitely until a request arrives in the queue.
Fix the error in the resource manager task to properly notify the requester after processing.
xTaskNotifyGive([1]);The function xTaskNotifyGive must be called with the handle of the task that requested the resource, so it can be notified.
Fill both blanks to correctly send a resource request and wait for notification.
xQueueSend(resourceQueue, &request, [1]); ulTaskNotifyTake([2], portMAX_DELAY);
portMAX_DELAY for queue send block time which can block indefinitely.pdFALSE for ulTaskNotifyTake which does not clear the notification.When sending to a queue, a zero block time means do not wait if the queue is full. For ulTaskNotifyTake, pdTRUE clears one bit from the notification value before checking or waiting.
Fill the blanks to implement a resource manager task loop that receives requests, processes them, and notifies the requester.
void ResourceManagerTask(void *pvParameters) {
ResourceRequest request;
for (;;) {
if (xQueueReceive(resourceQueue, &request, [1]) == pdPASS) {
// Process the request
processResource(request.data);
xTaskNotifyGive([2]);
}
}
}The task waits indefinitely for requests using portMAX_DELAY. After processing, it notifies the requesting task using request.taskHandle.