Bird
Raised Fist0
Embedded Cprogramming~10 mins

Watchdog reset recovery in Embedded C - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to clear the watchdog reset flag.

Embedded C
if (WDTIFG & [1]) {
    // Clear watchdog reset flag
    WDTIFG &= ~[1];
}
Drag options to blanks, or click blank then click option'
AWDTRST
BWDT_RESET
CWDTIFG
DWDT_FLAG
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong flag name that does not indicate watchdog reset.
Trying to clear the flag incorrectly.
2fill in blank
medium

Complete the code to reset the watchdog timer counter.

Embedded C
void reset_watchdog() {
    [1] = 0x5A;
    WDTCTL = WDTPW | WDTCNTCL;
}
Drag options to blanks, or click blank then click option'
AWDTCTL_RESET
BWDT_RESET
CWDT_COUNTER
DWDTCTL
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to reset the watchdog by writing to the wrong register.
Not including the password when writing to the watchdog control register.
3fill in blank
hard

Fix the error in the watchdog reset detection code.

Embedded C
if ([1] & WDTRST) {
    // Handle watchdog reset
}
Drag options to blanks, or click blank then click option'
AWDTIFG
BWDTCTL
CWDT_FLAG
DWDT_RESET
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the flag in the wrong register.
Using an undefined flag name.
4fill in blank
hard

Fill both blanks to create a dictionary that maps reset causes to messages.

Embedded C
const char* reset_messages[] = {
    [[1]] = "Power On Reset",
    [[2]] = "Watchdog Reset"
};
Drag options to blanks, or click blank then click option'
APORRST
BWDTIFG
CWDTRST
DPWRONRST
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the constants for reset causes.
Using flags instead of reset cause constants.
5fill in blank
hard

Fill all three blanks to implement watchdog reset recovery logic.

Embedded C
void check_reset_cause() {
    if (WDTCTL & [1]) {
        clear_reset_flag([2]);
        log_event([3]);
    }
}
Drag options to blanks, or click blank then click option'
AWDTRST
C"Watchdog reset detected"
DWDTIFG
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the reset flag bit and the flag to clear.
Forgetting to log the reset event.

Practice

(1/5)
1.

What is the main purpose of checking the watchdog reset flag at system startup?

easy
A. To increase the watchdog timer interval
B. To disable the watchdog timer permanently
C. To detect if the system was restarted due to a watchdog timeout
D. To reset all system variables to zero

Solution

  1. Step 1: Understand watchdog reset flag role

    The watchdog reset flag indicates if the last reset was caused by the watchdog timer expiring.
  2. Step 2: Purpose of checking the flag at startup

    Checking this flag helps the program know if it needs to perform recovery actions after an unexpected reset.
  3. Final Answer:

    To detect if the system was restarted due to a watchdog timeout -> Option C
  4. Quick Check:

    Watchdog reset flag = detect watchdog reset [OK]
Hint: Watchdog flag shows if reset was watchdog-caused [OK]
Common Mistakes:
  • Thinking the flag disables the watchdog
  • Assuming it resets variables automatically
  • Confusing flag with timer interval setting
2.

Which of the following code snippets correctly clears the watchdog reset flag in embedded C?

/* Assume WDT_RESET_FLAG is the flag variable */
// Clear the flag
?
easy
A. WDT_RESET_FLAG = 0;
B. clear(WDT_RESET_FLAG);
C. WDT_RESET_FLAG == 0;
D. reset_flag(WDT_RESET_FLAG);

Solution

  1. Step 1: Identify correct syntax to clear a flag

    In embedded C, clearing a flag usually means setting its variable to zero.
  2. Step 2: Analyze each option

    WDT_RESET_FLAG = 0; sets the flag to 0, which clears it. clear(WDT_RESET_FLAG); uses a non-standard function. WDT_RESET_FLAG == 0; uses comparison, not assignment. reset_flag(WDT_RESET_FLAG); uses an undefined function.
  3. Final Answer:

    WDT_RESET_FLAG = 0; -> Option A
  4. Quick Check:

    Clear flag = set to 0 [OK]
Hint: Clear flags by assigning zero directly [OK]
Common Mistakes:
  • Using comparison operator '==' instead of assignment
  • Calling undefined functions to clear flags
  • Confusing clearing with resetting the whole system
3.

Consider the following code snippet that runs at system startup:

if (WDT_RESET_FLAG) {
    recover_from_watchdog();
    WDT_RESET_FLAG = 0;
} else {
    normal_startup();
}

What will happen if the system was reset by the watchdog timer?

medium
A. The system does nothing and hangs
B. The system calls recover_from_watchdog() and clears the flag
C. The system calls normal_startup() only
D. The system resets again immediately

Solution

  1. Step 1: Check condition when watchdog reset flag is set

    If WDT_RESET_FLAG is true (non-zero), the if block executes.
  2. Step 2: Follow code logic inside the if block

    The function recover_from_watchdog() is called, then the flag is cleared by setting it to zero.
  3. Final Answer:

    The system calls recover_from_watchdog() and clears the flag -> Option B
  4. Quick Check:

    Flag set = recover and clear flag [OK]
Hint: If flag set, run recovery then clear flag [OK]
Common Mistakes:
  • Assuming normal_startup() runs after watchdog reset
  • Thinking system hangs without recovery
  • Believing system resets again immediately
4.

Identify the error in this watchdog reset recovery code snippet:

if (WDT_RESET_FLAG = 1) {
    recover_from_watchdog();
    WDT_RESET_FLAG = 0;
}
medium
A. Using assignment '=' instead of comparison '==' in the if condition
B. Not clearing the flag after recovery
C. Calling recover_from_watchdog() before checking the flag
D. Missing semicolon after the if statement

Solution

  1. Step 1: Analyze the if condition syntax

    The condition uses '=' which assigns 1 to the flag instead of comparing it.
  2. Step 2: Understand the impact of assignment in condition

    Assignment always returns true, so the if block runs every time, ignoring actual flag state.
  3. Final Answer:

    Using assignment '=' instead of comparison '==' in the if condition -> Option A
  4. Quick Check:

    Use '==' for comparison in if conditions [OK]
Hint: Use '==' in if conditions, not '=' [OK]
Common Mistakes:
  • Confusing '=' (assign) with '==' (compare)
  • Forgetting to clear the flag after recovery
  • Misplacing semicolons inside if statements
5.

You want to implement a watchdog reset recovery that logs the reset cause and safely restarts the system only if the reset was caused by the watchdog. Which sequence of actions is correct?

hard
A. Clear watchdog reset flag, restart system, then log reset cause
B. Log reset cause only if watchdog reset flag is not set
C. Restart system immediately, then check and clear watchdog reset flag
D. Check watchdog reset flag, log reset cause, clear flag, then restart system

Solution

  1. Step 1: Check the watchdog reset flag at startup

    This tells if the reset was caused by the watchdog timer.
  2. Step 2: Log the reset cause and clear the flag before restarting

    Logging helps diagnose issues; clearing the flag prevents repeated recovery loops.
  3. Step 3: Restart the system safely after handling the flag

    This ensures the system restarts only after recovery steps are done.
  4. Final Answer:

    Check watchdog reset flag, log reset cause, clear flag, then restart system -> Option D
  5. Quick Check:

    Check flag -> log -> clear -> restart [OK]
Hint: Always check flag before logging and restarting [OK]
Common Mistakes:
  • Restarting before clearing the flag
  • Logging after restart (won't execute)
  • Ignoring the flag and restarting blindly
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard