Challenge - 5 Problems
Window Watchdog Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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; }
Attempts:
2 left
💡 Hint
Check if the counter value is inside the allowed window range.
✗ Incorrect
The counter value 7 is between 5 and 10, so the watchdog does not trigger a reset. The program prints "No reset".
🧠 Conceptual
intermediate1: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.
Attempts:
2 left
💡 Hint
Think about why a reset outside a certain time frame might be harmful.
✗ Incorrect
A window watchdog timer requires the system to reset the watchdog only within a specific time window, preventing early or late resets that could hide software faults.
🔧 Debug
advanced2: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 }
Attempts:
2 left
💡 Hint
Check what the function returns inside and outside the window.
✗ Incorrect
The function returns false inside the window, which is interpreted as no reset, but the logic is inverted because the caller expects true for no reset. This causes the reset to always trigger.
📝 Syntax
advanced2: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; } }
Attempts:
2 left
💡 Hint
Remember the syntax for if statements in C requires parentheses around the condition.
✗ Incorrect
Option A correctly uses parentheses around the condition and braces for the if-else block, fixing the syntax error.
🚀 Application
expert3: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; }
Attempts:
2 left
💡 Hint
Count how many values of i are outside the window 4 to 7 inclusive.
✗ Incorrect
The window is from 4 to 7 inclusive. Values 1,2,3 and 8,9,10 are outside. So 6 values cause reset. But the code counts resets when !window_watchdog_reset(i) is true, so resets happen when i is outside the window. That is 6 times.