System Architect: Key Points – Embedded Technology – 32

Embedded Technology – Watchdog

1. What is a Watchdog? What problem does it solve?

Core Issue: Embedded systems operate in complex environments and may become unresponsive due to software defects (such as infinite loops, stack overflows), external electromagnetic interference, or power disturbances, leading to the program “running away” (i.e., the PC pointer enters an uncontrollable state), causing the entire system to “hang”.

The essence of a Watchdog: An independent hardware timer specifically designed to detect whether the system is functioning normally and to forcibly reset and restart the system in case of anomalies, allowing it to recover from a “hang” state.

Common analogy: A Watchdog is like a “dead loop detector” or a “system guardian”.

You must regularly (before the timer times out) inform it that “I am functioning normally” (this action is called “feeding the dog”).

If you fail to “feed the dog” on time due to the program “hanging”, it will assume the system is out of control and will immediately “take action” (force a system restart).

2. Types of Watchdogs

1. Hardware Watchdog

Form: An independent chip or an independent peripheral integrated within the microcontroller.

Core Feature: Independence. It has its own independent clock source, and its operation does not rely on the system’s main clock and CPU. It can still function even if the system’s main clock fails.

2. Software Watchdog

Form: Composed of a high-priority hardware timer interrupt and the corresponding interrupt service routine.

Working Principle: The main program needs to regularly “feed the dog”. If it times out without feeding the dog, the timer interrupt will trigger, and the interrupt service routine will assess the system status and may execute a reset operation.

Advantages: Flexible, capable of executing more complex recovery logic (not necessarily an immediate reset).

Disadvantages: Reliability is lower than that of hardware watchdogs. If a fault causes all interrupts to be masked or the operating system kernel to crash, the software watchdog will also fail.

Leave a Comment