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?
/* 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);
Remember that xTaskNotifyWait accumulates bits set by multiple notifications if ulBitsToClearOnEntry is zero.
Since ulBitsToClearOnEntry is zero, the notification value is not cleared before waiting. Both notifications set bits 0x01 and 0x02, so the accumulated value is 0x03. After reading, ulBitsToClearOnExit clears all bits.
What is the main purpose of implementing a watchdog task pattern in a FreeRTOS-based embedded system?
Think about system reliability and fault detection.
The watchdog task monitors the health of other tasks by expecting periodic signals. If a task fails to signal, the watchdog can take corrective action like resetting the system.
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?
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 delayConsider task priorities and CPU time allocation.
If higher priority tasks never block or yield, the lower priority watchdog task will never get CPU time, causing it to starve and never run.
Which of the following code snippets correctly sends a notification bit to a watchdog task from a worker task in FreeRTOS?
Check the notification action parameter to set bits.
Using eSetBits sets the specified bits in the notification value, which is the correct way to signal a watchdog task bit.
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?
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();
}
}
}Think about clearing bits before and after waiting to detect missing notifications each cycle.
Clearing bits on entry ensures only new notifications count each cycle. Clearing on exit resets bits for next cycle. Checking bits 0-3 ensures all workers notified.