Functions | |
void | watchdog_reboot (uint32_t pc, uint32_t sp, uint32_t delay_ms) |
Define actions to perform at watchdog timeout. More... | |
void | watchdog_start_tick (uint cycles) |
Start the watchdog tick. More... | |
void | watchdog_update (void) |
Reload the watchdog counter with the amount of time set in watchdog_enable. | |
void | watchdog_enable (uint32_t delay_ms, bool pause_on_debug) |
Enable the watchdog. More... | |
bool | watchdog_caused_reboot (void) |
Did the watchdog cause the last reboot? More... | |
bool | watchdog_enable_caused_reboot (void) |
Did watchdog_enable cause the last reboot? More... | |
uint32_t | watchdog_get_count (void) |
Returns the number of microseconds before the watchdog will reboot the chip. More... | |
Hardware Watchdog Timer API
Supporting functions for the Pico hardware watchdog timer.
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. For example, this can be used to restart the processor if the software running on it gets stuck in an infinite loop or similar. The programmer has to periodically write a value to the watchdog to stop it reaching zero.
bool watchdog_caused_reboot | ( | void | ) |
Did the watchdog cause the last reboot?
void watchdog_enable | ( | uint32_t | delay_ms, |
bool | pause_on_debug | ||
) |
Enable the watchdog.
delay_ms
parameter will not be in microseconds. See the datasheet for more details.By default the SDK assumes a 12MHz XOSC and sets the watchdog_start_tick appropriately.
This method sets a marker in the watchdog scratch register 4 that is checked by watchdog_enable_caused_reboot. If the device is subsequently reset via a call to watchdog_reboot (including for example by dragging a UF2 onto the RPI-RP2), then this value will be cleared, and so watchdog_enable_caused_reboot will return false.
delay_ms | Number of milliseconds before watchdog will reboot without watchdog_update being called. Maximum of 0x7fffff, which is approximately 8.3 seconds |
pause_on_debug | If the watchdog should be paused when the debugger is stepping through code |
bool watchdog_enable_caused_reboot | ( | void | ) |
Did watchdog_enable cause the last reboot?
Perform additional checking along with watchdog_caused_reboot to determine if a watchdog timeout initiated by watchdog_enable caused the last reboot.
This method checks for a special value in watchdog scratch register 4 placed there by watchdog_enable. This would not be present if a watchdog reset is initiated by watchdog_reboot or by the RP2040 bootrom (e.g. dragging a UF2 onto the RPI-RP2 drive).
uint32_t watchdog_get_count | ( | void | ) |
Returns the number of microseconds before the watchdog will reboot the chip.
void watchdog_reboot | ( | uint32_t | pc, |
uint32_t | sp, | ||
uint32_t | delay_ms | ||
) |
Define actions to perform at watchdog timeout.
delay_ms
parameter will not be in microseconds. See the datasheet for more details.By default the SDK assumes a 12MHz XOSC and sets the watchdog_start_tick appropriately.
pc | If Zero, a standard boot will be performed, if non-zero this is the program counter to jump to on reset. |
sp | If pc is non-zero, this will be the stack pointer used. |
delay_ms | Initial load value. Maximum value 0x7fffff, approximately 8.3s. |
void watchdog_start_tick | ( | uint | cycles | ) |
Start the watchdog tick.
cycles | This needs to be a divider that when applied to the XOSC input, produces a 1MHz clock. So if the XOSC is 12MHz, this will need to be 12. |