High level interface to the Watchdog Timer (WDT).
The WDT can be used for recovering from a CPU or firmware failure. The WDT is initialized with a timeout interval. Once the WDT is started, cyhal_wdt_kick must be called at least once within each timeout interval to reset the count. In case the firmware fails to do so, it is considered to be a CPU crash or firmware failure and the device will be reset.
WDT resets the device if the WDT is not "kicked" using cyhal_wdt_kick within the configured timeout interval.
cyhal_wdt_init() is used to initialize the WDT by providing the WDT object (obj) and the timeout (timeout_ms) value in milliseconds. The timeout parameter can have a minimum value of 1ms. The maximum value of the timeout parameter can be obtained using the cyhal_wdt_get_max_timeout_ms().
The following snippet initializes the WDT and illustrates how to reset the WDT within the timeout interval.
API Reference | |
WDT HAL Results | |
WDT specific return codes. | |
Functions | |
cy_rslt_t | cyhal_wdt_init (cyhal_wdt_t *obj, uint32_t timeout_ms) |
Initialize and start the WDT. More... | |
void | cyhal_wdt_free (cyhal_wdt_t *obj) |
Free the WDT. More... | |
void | cyhal_wdt_kick (cyhal_wdt_t *obj) |
Resets the WDT. More... | |
void | cyhal_wdt_start (cyhal_wdt_t *obj) |
Start (enable) the WDT. More... | |
void | cyhal_wdt_stop (cyhal_wdt_t *obj) |
Stop (disable) the WDT. More... | |
uint32_t | cyhal_wdt_get_timeout_ms (cyhal_wdt_t *obj) |
Get the WDT timeout. More... | |
uint32_t | cyhal_wdt_get_max_timeout_ms (void) |
Gets the maximum WDT timeout in milliseconds. More... | |
bool | cyhal_wdt_is_enabled (cyhal_wdt_t *obj) |
Check if WDT is enabled. More... | |
cy_rslt_t cyhal_wdt_init | ( | cyhal_wdt_t * | obj, |
uint32_t | timeout_ms | ||
) |
Initialize and start the WDT.
[out] | obj | Pointer to a WDT object. The caller must allocate the memory for this object but the init function will initialize its contents. |
[in,out] | timeout_ms | The time in milliseconds before the WDT times out (1ms - max) (see cyhal_wdt_get_max_timeout_ms()) |
Returns CY_RSLT_SUCCESS if the operation was successfull.
void cyhal_wdt_free | ( | cyhal_wdt_t * | obj | ) |
Free the WDT.
Powers down the WDT. Releases object (obj). After calling this function no other WDT functions should be called except cyhal_wdt_init().
[in,out] | obj | The WDT object |
void cyhal_wdt_kick | ( | cyhal_wdt_t * | obj | ) |
Resets the WDT.
This function must be called periodically to prevent the WDT from timing out and resetting the device.
See Snippet 1: Initialize the WDT and kick periodically
[in,out] | obj | The WDT object |
void cyhal_wdt_start | ( | cyhal_wdt_t * | obj | ) |
Start (enable) the WDT.
[in,out] | obj | The WDT object |
void cyhal_wdt_stop | ( | cyhal_wdt_t * | obj | ) |
Stop (disable) the WDT.
[in,out] | obj | The WDT object |
uint32_t cyhal_wdt_get_timeout_ms | ( | cyhal_wdt_t * | obj | ) |
Get the WDT timeout.
Gets the configured time, in milliseconds, before the WDT times out.
[in] | obj | The WDT object |
uint32_t cyhal_wdt_get_max_timeout_ms | ( | void | ) |
Gets the maximum WDT timeout in milliseconds.
bool cyhal_wdt_is_enabled | ( | cyhal_wdt_t * | obj | ) |
Check if WDT is enabled.
This will return true after cyhal_wdt_start is called. It will return false before the WDT is started, or after cyhal_wdt_stop is called.
[in] | obj | The WDT object |