0
0
FreeRTOSprogramming~10 mins

Watchdog task pattern in FreeRTOS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a watchdog timer with FreeRTOS API.

FreeRTOS
TimerHandle_t watchdogTimer = xTimerCreate("Watchdog", pdMS_TO_TICKS([1]), pdFALSE, NULL, watchdogCallback);
Drag options to blanks, or click blank then click option'
A2000
B10000
C1000
D5000
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the timeout too short causing false triggers.
Using zero or negative values which are invalid.
2fill in blank
medium

Complete the code to start the watchdog timer after creation.

FreeRTOS
if (xTimerStart(watchdogTimer, [1]) != pdPASS) {
    // Handle error
}
Drag options to blanks, or click blank then click option'
A0
BportMAX_DELAY
C100
DpdMS_TO_TICKS(1000)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a blocking delay unnecessarily.
Passing an invalid block time causing errors.
3fill in blank
hard

Fix the error in the watchdog task function to reset the timer correctly.

FreeRTOS
void WatchdogTask(void *pvParameters) {
    for (;;) {
        if (xTimerReset(watchdogTimer, [1]) != pdPASS) {
            // Handle reset failure
        }
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}
Drag options to blanks, or click blank then click option'
A0
BportMAX_DELAY
CpdMS_TO_TICKS(1000)
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using a blocking delay causing watchdog to miss resets.
Passing incorrect block time values.
4fill in blank
hard

Fill both blanks to create a dictionary of task names and their last heartbeat times.

FreeRTOS
typedef struct {
    char name[16];
    TickType_t lastHeartbeat;
} TaskStatus;

TaskStatus taskStatusArray[[1]];

void updateHeartbeat(const char* taskName, TickType_t tick) {
    for (int i = 0; i < [2]; i++) {
        if (strcmp(taskStatusArray[i].name, taskName) == 0) {
            taskStatusArray[i].lastHeartbeat = tick;
            break;
        }
    }
}
Drag options to blanks, or click blank then click option'
A5
B10
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching array size and loop limit causing out-of-bounds errors.
Using too small array size for the number of tasks.
5fill in blank
hard

Fill all three blanks to implement the watchdog check function that resets system on timeout.

FreeRTOS
void checkWatchdog() {
    TickType_t currentTick = xTaskGetTickCount();
    for (int i = 0; i < [1]; i++) {
        if (currentTick - taskStatusArray[i].lastHeartbeat > [2]) {
            [3]();
        }
    }
}
Drag options to blanks, or click blank then click option'
A5
BpdMS_TO_TICKS(5000)
CsystemReset
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong timeout values causing premature resets.
Calling wrong function or missing reset call.