1 /* 2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef _HARDWARE_WATCHDOG_H 8 #define _HARDWARE_WATCHDOG_H 9 10 #include "pico.h" 11 12 /** \file hardware/watchdog.h 13 * \defgroup hardware_watchdog hardware_watchdog 14 * 15 * Hardware Watchdog Timer API 16 * 17 * Supporting functions for the Pico hardware watchdog timer. 18 * 19 * The RP2040 has a built in HW watchdog Timer. This is a countdown timer that can restart parts of the chip if it reaches zero. 20 * For example, this can be used to restart the processor if the software running on it gets stuck in an infinite loop 21 * or similar. The programmer has to periodically write a value to the watchdog to stop it reaching zero. 22 * 23 * \subsection watchdog_example Example 24 * \addtogroup hardware_watchdog 25 * \include hello_watchdog.c 26 */ 27 28 /*! \brief Define actions to perform at watchdog timeout 29 * \ingroup hardware_watchdog 30 * 31 * \note If \ref watchdog_start_tick value does not give a 1MHz clock to the watchdog system, then the \ref delay_ms 32 * parameter will not be in microseconds. See the datasheet for more details. 33 * 34 * By default the SDK assumes a 12MHz XOSC and sets the \ref watchdog_start_tick appropriately. 35 * 36 * \param pc If Zero, a standard boot will be performed, if non-zero this is the program counter to jump to on reset. 37 * \param sp If \p pc is non-zero, this will be the stack pointer used. 38 * \param delay_ms Initial load value. Maximum value 0x7fffff, approximately 8.3s. 39 */ 40 void watchdog_reboot(uint32_t pc, uint32_t sp, uint32_t delay_ms); 41 42 /*! \brief Start the watchdog tick 43 * \ingroup hardware_watchdog 44 * 45 * \param cycles This needs to be a divider that when applied to the XOSC input, produces a 1MHz clock. So if the XOSC is 46 * 12MHz, this will need to be 12. 47 */ 48 void watchdog_start_tick(uint cycles); 49 50 /*! \brief Reload the watchdog counter with the amount of time set in watchdog_enable 51 * \ingroup hardware_watchdog 52 * 53 */ 54 void watchdog_update(void); 55 56 /** 57 * \brief Enable the watchdog 58 * \ingroup hardware_watchdog 59 * 60 * \note If \ref watchdog_start_tick value does not give a 1MHz clock to the watchdog system, then the \ref delay_ms 61 * parameter will not be in microseconds. See the datasheet for more details. 62 * 63 * By default the SDK assumes a 12MHz XOSC and sets the \ref watchdog_start_tick appropriately. 64 * 65 * \param delay_ms Number of milliseconds before watchdog will reboot without watchdog_update being called. Maximum of 0x7fffff, which is approximately 8.3 seconds 66 * \param pause_on_debug If the watchdog should be paused when the debugger is stepping through code 67 */ 68 void watchdog_enable(uint32_t delay_ms, bool pause_on_debug); 69 70 /** 71 * \brief Did the watchdog cause the last reboot? 72 * \ingroup hardware_watchdog 73 * 74 * @return true if the watchdog timer or a watchdog force caused the last reboot 75 * @return false there has been no watchdog reboot since run has been 76 */ 77 bool watchdog_caused_reboot(void); 78 79 /** 80 * @brief Returns the number of microseconds before the watchdog will reboot the chip. 81 * \ingroup hardware_watchdog 82 * 83 * @return The number of microseconds before the watchdog will reboot the chip. 84 */ 85 uint32_t watchdog_get_count(void); 86 87 #endif 88