Esp32 Watchdog Timer Design
A watchdog timer is a hardware counter that forces a reset if nothing in software ever tells it the system is still alive, and its entire value depends on being independent enough of the CPU it's watching that a hang in that same CPU can't also disable the thing meant to recover from the hang. Software can detect plenty of its own error conditions and recover gracefully, but a true hang — an infinite loop, a deadlock between tasks, a corrupted instruction pointer jumping into invalid memory — leaves no software running that's capable of noticing anything is wrong at all; a watchdog exists specifically for that failure class, where the only thing left that can save the device is a piece of hardware that doesn't depend on the hung CPU continuing to execute correctly.
Separate task and interrupt watchdogs exist because a hang inside an interrupt handler and a hang inside a normal task are genuinely different failure modes that deserve different handling, not redundant copies of the same mechanism. An interrupt watchdog catches the specific case of an ISR that never returns — a much more severe condition, since the entire system is blocked from doing anything else while stuck in interrupt context — and typically triggers a faster, more aggressive response than a task watchdog monitoring whether a specific RTOS task is making progress on its own schedule; running both independently means the system can distinguish "one task stalled" from "the whole chip is frozen in an ISR," which matters for both the diagnostic information captured and how urgently the recovery needs to happen.
The panic handler that fires before an actual hardware reset exists to capture diagnostic information in the few moments between "a hang was detected" and "the system restarts and that evidence is gone," because a reset that happens silently turns every field hang into an unexplainable mystery. On detecting a timeout, well-designed firmware runs a panic handler that captures a register dump, a stack backtrace, and often a partial core dump to flash or a debug UART before actually forcing the reset — without that captured state, a developer debugging a field failure has nothing to work with except "the device rebooted sometime, for unknown reasons," which is close to useless for finding the actual root cause of an intermittent hang that may never reproduce on a bench.
A watchdog feed placed in the wrong spot in firmware can defeat the entire mechanism while looking like a correctly-functioning safeguard, which is a subtler failure mode than simply forgetting to feed the watchdog at all. Feeding the watchdog from a low-priority background task that itself keeps running even while the actual application logic the product depends on has deadlocked will keep resetting the countdown forever, masking a real hang that the watchdog was specifically there to catch — correct watchdog usage requires feeding it from a code path that can only execute if the specific logic that matters is actually still making progress, not from any convenient periodic task that happens to still be scheduled.
Watchdog timer and fault recovery design is the mechanism that accepts a basic truth about any sufficiently complex firmware stack — it will eventually hang in a way no amount of software-level error handling can catch from the inside — and answers it with hardware deliberately kept independent of the CPU it watches, task and interrupt watchdogs sized to the different severities of hang they catch, and a panic handler that captures the evidence a developer actually needs before the reset erases it.