// =============================================================================
//  safety/watchdog.h -- Task Watchdog Timer (TWDT)
// =============================================================================
//
//  Hooks the ESP32 task watchdog so that if the real-time control tasks
//  (PID inner, PID outer, safety monitor) ever fail to feed the watchdog
//  within AR_WATCHDOG_TIMEOUT_S, the chip resets and reboots cleanly to
//  STANDBY mode.
//
//  Brief section 7: "El ESP32 reinicia automaticamente si el firmware se
//  cuelga >2 segundos. Al reiniciar: Estado del piloto pasa a STANDBY."
// =============================================================================

#pragma once

namespace arautopilot::safety {

/// Configure and start the Task Watchdog Timer. Tasks that want to be
/// monitored must call watchdog_subscribe_current_task() once and then
/// watchdog_feed() at least once per AR_WATCHDOG_TIMEOUT_S.
void watchdog_init();

/// Add the current task to the watchdog's monitored set.
void watchdog_subscribe_current_task();

/// Feed the watchdog from the current task.
void watchdog_feed();

}  // namespace arautopilot::safety
