0
0
Embedded Cprogramming~20 mins

Window watchdog concept in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Window Watchdog 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 watchdog timer reset code?
Consider this embedded C code snippet that simulates a window watchdog reset. What will be printed when the program runs?
Embedded C
#include <stdio.h>
#include <stdbool.h>

bool window_watchdog_reset(unsigned int counter) {
    const unsigned int window_start = 5;
    const unsigned int window_end = 10;
    if (counter < window_start || counter > window_end) {
        return false; // Reset triggered
    }
    return true; // No reset
}

int main() {
    unsigned int counter = 7;
    if (window_watchdog_reset(counter)) {
        printf("No reset\n");
    } else {
        printf("Reset triggered\n");
    }
    return 0;
}
AReset triggered
BNo reset
CCompilation error
DNo output
Attempts:
2 left
💡 Hint
Check if the counter value is inside the allowed window range.
🧠 Conceptual
intermediate
1:30remaining
What does the window watchdog timer prevent in embedded systems?
Choose the best description of what a window watchdog timer helps to prevent in embedded systems.
AIt prevents the system from resetting too early or too late by enforcing a time window for resets.
BIt increases the clock speed of the microcontroller to improve performance.
CIt stores data permanently in non-volatile memory.
DIt manages power consumption by shutting down unused peripherals.
Attempts:
2 left
💡 Hint
Think about why a reset outside a certain time frame might be harmful.
🔧 Debug
advanced
2:30remaining
Identify the bug causing the watchdog reset to always trigger
This code is supposed to reset the watchdog only if the counter is within the window 3 to 8. However, it always triggers a reset. What is the bug?
Embedded C
bool window_watchdog_reset(unsigned int counter) {
    const unsigned int window_start = 3;
    const unsigned int window_end = 8;
    if (counter > window_start && counter < window_end) {
        return false; // No reset
    }
    return true; // Reset triggered
}
AThe function is missing a counter increment causing infinite reset.
BThe window boundaries are incorrect; they should be inclusive using >= and <=.
CThe function returns wrong boolean values; it should return true for reset and false for no reset.
DThe condition logic is inverted; it should return true inside the window and false outside.
Attempts:
2 left
💡 Hint
Check what the function returns inside and outside the window.
📝 Syntax
advanced
2:00remaining
Which option fixes the syntax error in this watchdog timer code?
This code snippet has a syntax error. Which option fixes it correctly?
Embedded C
bool check_watchdog(unsigned int count) {
    if count >= 2 && count <= 6 {
        return true;
    } else {
        return false;
    }
}
Aif (count >= 2 && count <= 6) { return true; } else { return false; }
Bif count >= 2 && count <= 6: return true else return false
Cif (count >= 2 && count <= 6) return true; else return false;
Dif [count >= 2 && count <= 6] { return true; } else { return false; }
Attempts:
2 left
💡 Hint
Remember the syntax for if statements in C requires parentheses around the condition.
🚀 Application
expert
3:00remaining
How many times will the watchdog reset be triggered in this loop?
Given this code simulating a watchdog reset check in a loop, how many times will "Reset triggered" be printed?
Embedded C
#include <stdio.h>
#include <stdbool.h>

bool window_watchdog_reset(unsigned int counter) {
    const unsigned int window_start = 4;
    const unsigned int window_end = 7;
    return (counter >= window_start && counter <= window_end);
}

int main() {
    unsigned int resets = 0;
    for (unsigned int i = 1; i <= 10; i++) {
        if (!window_watchdog_reset(i)) {
            printf("Reset triggered at %u\n", i);
            resets++;
        }
    }
    printf("Total resets: %u\n", resets);
    return 0;
}
A4
B5
C6
D3
Attempts:
2 left
💡 Hint
Count how many values of i are outside the window 4 to 7 inclusive.