Challenge - 5 Problems
Watchdog Reset Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Watchdog Reset Cause Detection
What will be the output of this embedded C code snippet that checks the cause of the last reset?
Embedded C
#include <stdio.h> #define WDT_RESET_FLAG 0x01 #define POWER_ON_RESET_FLAG 0x02 unsigned char reset_cause = WDT_RESET_FLAG; int main() { if (reset_cause & WDT_RESET_FLAG) { printf("Watchdog Reset Detected\n"); } else if (reset_cause & POWER_ON_RESET_FLAG) { printf("Power-On Reset Detected\n"); } else { printf("Unknown Reset Cause\n"); } return 0; }
Attempts:
2 left
💡 Hint
Check which reset flag is set in the reset_cause variable.
✗ Incorrect
The reset_cause variable has the WDT_RESET_FLAG bit set, so the first if condition is true and prints "Watchdog Reset Detected".
🧠 Conceptual
intermediate1:30remaining
Purpose of Watchdog Reset Recovery Code
Why is it important to include watchdog reset recovery code in embedded systems?
Attempts:
2 left
💡 Hint
Think about what a watchdog timer does when the system stops responding.
✗ Incorrect
Watchdog reset recovery code helps detect when the system was reset due to a watchdog timeout and allows the program to handle this event safely.
🔧 Debug
advanced2:00remaining
Identify the Bug in Watchdog Reset Handling
What is the bug in this watchdog reset recovery code snippet?
Embedded C
void check_reset_cause() {
if (reset_cause == WDT_RESET_FLAG) {
// Handle watchdog reset
reset_cause = 0;
}
}Attempts:
2 left
💡 Hint
Check the condition inside the if statement carefully.
✗ Incorrect
Using '=' assigns WDT_RESET_FLAG to reset_cause instead of comparing it, causing incorrect behavior.
📝 Syntax
advanced1:30remaining
Correct Syntax for Clearing Watchdog Reset Flag
Which option correctly clears the watchdog reset flag in a hardware register named RESET_FLAGS?
Embedded C
/* Assume RESET_FLAGS is a hardware register where bit 0 is the watchdog reset flag */Attempts:
2 left
💡 Hint
To clear a bit, you use bitwise AND with the inverse mask.
✗ Incorrect
Option D uses bitwise AND with the complement of 0x01 to clear bit 0 correctly.
🚀 Application
expert3:00remaining
Implement Watchdog Reset Recovery Logic
Given a microcontroller with a watchdog reset flag at bit 2 of the RESET_STATUS register, write the correct embedded C code snippet to detect a watchdog reset, clear the flag, and print "Recovered from watchdog reset".
Attempts:
2 left
💡 Hint
Use bitwise AND to check the flag and bitwise AND with complement to clear it.
✗ Incorrect
Option C correctly checks if bit 2 is set, clears it by ANDing with the complement, and prints the message.