0
0
Embedded Cprogramming~20 mins

Watchdog reset recovery in Embedded C - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Watchdog Reset Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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;
}
AWatchdog Reset Detected
BPower-On Reset Detected
CUnknown Reset Cause
DCompilation Error
Attempts:
2 left
💡 Hint
Check which reset flag is set in the reset_cause variable.
🧠 Conceptual
intermediate
1:30remaining
Purpose of Watchdog Reset Recovery Code
Why is it important to include watchdog reset recovery code in embedded systems?
ATo increase the clock speed of the microcontroller
BTo detect and handle system hangs by resetting the system safely
CTo reduce power consumption during sleep mode
DTo enable communication with external sensors
Attempts:
2 left
💡 Hint
Think about what a watchdog timer does when the system stops responding.
🔧 Debug
advanced
2: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;
    }
}
AThe assignment operator '=' is used instead of comparison '==' in the if condition
BThe reset_cause variable is not declared
CThe reset_cause flag is cleared before handling the reset
DThe function does not return a value
Attempts:
2 left
💡 Hint
Check the condition inside the if statement carefully.
📝 Syntax
advanced
1: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 */
ARESET_FLAGS == ~0x01;
BRESET_FLAGS = &~0x01;
CRESET_FLAGS |= 0x01;
DRESET_FLAGS &= ~0x01;
Attempts:
2 left
💡 Hint
To clear a bit, you use bitwise AND with the inverse mask.
🚀 Application
expert
3: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".
A
if (RESET_STATUS &amp; (1 &lt;&lt; 2)) {
    RESET_STATUS |= (1 &lt;&lt; 2);
    printf("Recovered from watchdog reset\n");
}
B
if (RESET_STATUS == (1 &lt;&lt; 2)) {
    RESET_STATUS |= (1 &lt;&lt; 2);
    printf("Recovered from watchdog reset\n");
}
C
if (RESET_STATUS &amp; (1 &lt;&lt; 2)) {
    RESET_STATUS &amp;= ~(1 &lt;&lt; 2);
    printf("Recovered from watchdog reset\n");
}
D
if (RESET_STATUS = (1 &lt;&lt; 2)) {
    RESET_STATUS &amp;= ~(1 &lt;&lt; 2);
    printf("Recovered from watchdog reset\n");
}
Attempts:
2 left
💡 Hint
Use bitwise AND to check the flag and bitwise AND with complement to clear it.