Challenge - 5 Problems
Watchdog Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Watchdog Timer Reset Behavior
What will be the output of the following embedded C code snippet simulating a watchdog timer reset?
Embedded C
#include <stdio.h> #include <stdbool.h> bool watchdog_reset = false; void watchdog_feed() { watchdog_reset = true; } void watchdog_check() { if (!watchdog_reset) { printf("System Reset by Watchdog\n"); } else { printf("System Running Normally\n"); } } int main() { watchdog_reset = true; watchdog_feed(); watchdog_check(); watchdog_reset = false; watchdog_check(); return 0; }
Attempts:
2 left
💡 Hint
Watchdog resets the system if it is not fed (reset) in time.
✗ Incorrect
The first watchdog_check() call happens after watchdog_feed(), so the system is running normally. The second call happens after watchdog_reset is set to false, so the watchdog triggers a reset message.
🧠 Conceptual
intermediate1:30remaining
Purpose of a Watchdog Timer
What is the main purpose of a watchdog timer in embedded systems?
Attempts:
2 left
💡 Hint
Think about what happens when a system freezes or crashes.
✗ Incorrect
A watchdog timer helps recover the system from hangs by resetting it if the software fails to reset the timer periodically.
🔧 Debug
advanced2:30remaining
Identify the Bug in Watchdog Feeding Code
What is the bug in the following watchdog feeding code snippet?
Embedded C
void feed_watchdog() {
// Missing watchdog reset sequence
// supposed to reset the watchdog timer here
}
int main() {
while(1) {
feed_watchdog();
// Other tasks
}
return 0;
}Attempts:
2 left
💡 Hint
Feeding the watchdog means resetting its timer to prevent reset.
✗ Incorrect
The function feed_watchdog() is empty and does not reset the watchdog timer, so the watchdog will eventually reset the system.
📝 Syntax
advanced1:30remaining
Correct Watchdog Timer Initialization Syntax
Which option correctly initializes a watchdog timer with a timeout of 2 seconds in embedded C?
Attempts:
2 left
💡 Hint
Timeouts are usually given in milliseconds as integers.
✗ Incorrect
The function expects an integer value representing milliseconds. Option A passes 2000 (2 seconds) correctly.
🚀 Application
expert3:00remaining
Watchdog Timer Use Case Scenario
In an embedded system controlling a robotic arm, the watchdog timer is set to 1 second. The main control loop takes 1.5 seconds to complete one cycle. What will happen and why?
Attempts:
2 left
💡 Hint
Watchdog timers reset the system if not fed before timeout.
✗ Incorrect
Since the control loop takes longer than the watchdog timeout and the watchdog is not fed in time, the system will reset.