0
0
FreeRTOSprogramming~20 mins

Watchdog task pattern in FreeRTOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Watchdog Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Watchdog Task Notification Behavior

Consider a FreeRTOS system with a watchdog task waiting for notifications from multiple worker tasks. What will be the output of the watchdog task if it uses xTaskNotifyWait with ulBitsToClearOnEntry = 0 and ulBitsToClearOnExit = 0xFFFFFFFF, and two worker tasks notify it with bits 0x01 and 0x02 respectively before the watchdog calls xTaskNotifyWait?

FreeRTOS
/* Watchdog task snippet */
uint32_t ulNotificationValue = 0;
BaseType_t xResult = xTaskNotifyWait(
    0,          // ulBitsToClearOnEntry
    0xFFFFFFFF, // ulBitsToClearOnExit
    &ulNotificationValue,
    0           // xTicksToWait
);
// Print notification value
printf("Notification value: 0x%02X\n", ulNotificationValue);
ANotification value: 0x01
BNotification value: 0x00
CNotification value: 0x02
DNotification value: 0x03
Attempts:
2 left
💡 Hint

Remember that xTaskNotifyWait accumulates bits set by multiple notifications if ulBitsToClearOnEntry is zero.

🧠 Conceptual
intermediate
1:30remaining
Purpose of Watchdog Task in FreeRTOS

What is the main purpose of implementing a watchdog task pattern in a FreeRTOS-based embedded system?

ATo increase the CPU clock speed dynamically based on workload.
BTo handle all hardware interrupts in the system centrally.
CTo monitor other tasks and detect if any task has stopped responding or is stuck.
DTo allocate memory dynamically to tasks at runtime.
Attempts:
2 left
💡 Hint

Think about system reliability and fault detection.

🔧 Debug
advanced
2:30remaining
Debugging Watchdog Task Starvation

A watchdog task in FreeRTOS is supposed to run every 100ms to check system health. However, it never runs and the system hangs. Which of the following is the most likely cause?

FreeRTOS
void WatchdogTask(void *pvParameters) {
    for (;;) {
        // Check health
        vTaskDelay(pdMS_TO_TICKS(100));
    }
}

// System initialization
xTaskCreate(WatchdogTask, "Watchdog", 128, NULL, 1, NULL);
// Other tasks with priority 2 running continuously without delay
AOther higher priority tasks are starving the watchdog task by never yielding or delaying.
BThe watchdog task stack size is too large causing memory overflow.
CThe watchdog task priority is higher than other tasks causing deadlock.
DThe watchdog task is missing a call to vTaskStartScheduler().
Attempts:
2 left
💡 Hint

Consider task priorities and CPU time allocation.

📝 Syntax
advanced
1:30remaining
Correct Use of Task Notifications for Watchdog

Which of the following code snippets correctly sends a notification bit to a watchdog task from a worker task in FreeRTOS?

AxTaskNotify(watchdogHandle, 0x01, eSetBits);
BxTaskNotify(watchdogHandle, 0x01, eNoAction);
CxTaskNotify(watchdogHandle, 1, eSetValueWithOverwrite);
DxTaskNotify(watchdogHandle, 0x01);
Attempts:
2 left
💡 Hint

Check the notification action parameter to set bits.

🚀 Application
expert
3:00remaining
Designing a Watchdog Task for Multiple Worker Tasks

You need to design a watchdog task that monitors 4 worker tasks. Each worker task must notify the watchdog every 500ms by setting a unique bit (bit 0 to bit 3). The watchdog task runs every 1 second and checks if all bits are set. If any bit is missing, it triggers a system reset.

Which of the following watchdog task code snippets correctly implements this logic?

FreeRTOS
void WatchdogTask(void *pvParameters) {
    uint32_t ulNotificationValue;
    for (;;) {
        if (xTaskNotifyWait(0xFFFFFFFF, 0xFFFFFFFF, &ulNotificationValue, pdMS_TO_TICKS(1000)) == pdTRUE) {
            if ((ulNotificationValue & 0x0F) != 0x0F) {
                // Missing notification from some worker
                SystemReset();
            }
        } else {
            // No notification received
            SystemReset();
        }
    }
}
AThe code should use ulBitsToClearOnEntry = 0 to accumulate bits instead of clearing them before wait.
BThe code correctly waits for notifications, clears bits on entry and exit, and checks all 4 bits are set.
CThe code should not clear bits on exit to preserve notification bits for next cycle.
DThe code should use a timeout of 500ms instead of 1000ms in xTaskNotifyWait.
Attempts:
2 left
💡 Hint

Think about clearing bits before and after waiting to detect missing notifications each cycle.