Repository: raspberrypi/pico-sdk
File: src/rp2_common/hardware_watchdog/include/hardware/watchdog.h (C/C++)

Code before:
 *
 * This method checks for a special value in watchdog scratch register 4 placed there by \ref watchdog_enable.
 * This would not be present if a watchdog reset is initiated by \ref watchdog_reboot or by the RP-series microcontroller bootrom
 * (e.g. dragging a UF2 onto the RPI-RP2 drive).
 *
 * @return true If the watchdog timer or a watchdog force caused (see \ref watchdog_caused_reboot) the last reboot
 *              and the watchdog reboot happened after \ref watchdog_enable was called
 * @return false If there has been no watchdog reboot since the last power on reset, or the watchdog reboot was not caused
 *               by a watchdog timeout after \ref watchdog_enable was called.
 *               A power on reset is typically caused by a power cycle or the run pin (reset button) being toggled.
 */
bool watchdog_enable_caused_reboot(void);

/**
 * \brief Returns the number of microseconds before the watchdog will reboot the chip.
 * \ingroup hardware_watchdog
 *
 * \if rp2040_specicifc
 * On RP2040 this method returns the last value set instead of the remaining time due to a h/w bug.
 * \endif
 * 
 * @return The number of microseconds before the watchdog will reboot the chip.
 */
uint32_t watchdog_get_time_remaining_ms(void);

// backwards compatibility with SDK < 2.0.0
static inline uint32_t watchdog_get_count(void) {
    return watchdog_get_time_remaining_ms();
}
#ifdef __cplusplus
}
#endif

#endif


Review comment (bug):
@kilograham Do you know which hardware bug this is referring to? The RP2040 datasheet lists RP2040-E1 (which doesn't cover this) as the only watchdog-related errata.

Code after:

/**
 * \brief Did watchdog_enable cause the last reboot?
 * \ingroup hardware_watchdog
 *
 * Perform additional checking along with \ref watchdog_caused_reboot to determine if a watchdog timeout initiated by
 * \ref watchdog_enable caused the last reboot.
 *
 * This method checks for a special value in watchdog scratch register 4 placed there by \ref watchdog_enable.
 * This would not be present if a watchdog reset is initiated by \ref watchdog_reboot or by the RP-series microcontroller bootrom
 * (e.g. dragging a UF2 onto the RPI-RP2 drive).
 *
 * @return true If the watchdog timer or a watchdog force caused (see \ref watchdog_caused_reboot) the last reboot
 *              and the watchdog reboot happened after \ref watchdog_enable was called
 * @return false If there has been no watchdog reboot since the last power on reset, or the watchdog reboot was not caused
 *               by a watchdog timeout after \ref watchdog_enable was called.
 *               A power on reset is typically caused by a power cycle or the run pin (reset button) being toggled.
 */
bool watchdog_enable_caused_reboot(void);

/**
 * \brief Returns the number of microseconds before the watchdog will reboot the chip.
 * \ingroup hardware_watchdog
 *
 * \if rp2040_specific
 * On RP2040 this method returns the last value set instead of the remaining time due to a h/w bug.
 * \endif
 * 
 * @return The number of microseconds before the watchdog will reboot the chip.
 */
uint32_t watchdog_get_time_remaining_ms(void);

// backwards compatibility with SDK < 2.0.0
static inline uint32_t watchdog_get_count(void) {
    return watchdog_get_time_remaining_ms();
}
#ifdef __cplusplus
}
#endif

#endif