# WATCHDOG
- [Overview](#section1290618846165623)
- [Summary](#section1568879816165623)
- [Files](#files)
- [Enumerations](#enum-members)
- [Functions](#func-members)
- [Details](#section403189386165623)
- [Enumeration Type](#section1022114787165623)
- [WatchdogStatus](#ga3c77a35e1051e3f99238029519ac1954)
- [Function](#section1817390180165623)
- [WatchdogClose\(\)](#ga9ba18801b59154c986aef6bb5cc92bf5)
- [WatchdogFeed\(\)](#ga32e7d3939e8682e52502d9112ad6732a)
- [WatchdogGetStatus\(\)](#ga2fc274833b7dd18cc61209454d1fa82b)
- [WatchdogGetTimeout\(\)](#ga525602b8cacd030fb1630ea07f2a5b07)
- [WatchdogOpen\(\)](#ga0a88b7f3b90bf528cdc8b7589b125e85)
- [WatchdogSetTimeout\(\)](#ga508bea0dac2cac12b0819bb7af81e628)
- [WatchdogStart\(\)](#ga6d15226fbc2fe5da184decb6370b0122)
- [WatchdogStop\(\)](#gac41a51b5d663f7963c06cb1241d50239)
## **Overview**
**Description:**
Provides watchdog APIs, such as setting the watchdog timeout duration and feeding a watchdog \(resetting a watchdog timer\).
If an error occurs in the main program of the system, for example, if the program crashes or the watchdog timer is not reset in time, the watchdog timer generates a reset signal, and the system restores from the suspending state to the normal state.
**Since:**
1.0
## **Summary**
## Files
File Name
|
Description
|
watchdog_if.h
|
Declares standard watchdog APIs.
|
## Enumerations
## Functions
## **Details**
## **Enumeration Type **
## WatchdogStatus
```
enum [WatchdogStatus](WATCHDOG.md#ga3c77a35e1051e3f99238029519ac1954)
```
**Description:**
Enumerates watchdog statuses.
To obtain the watchdog status, call the [WatchdogGetStatus](WATCHDOG.md#ga2fc274833b7dd18cc61209454d1fa82b) function.
Enumerator
|
Description
|
| WATCHDOG_STOP |
Stopped
|
| WATCHDOG_START |
Started
|
## **Function **
## WatchdogClose\(\)
```
void WatchdogClose ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle)
```
**Description:**
Closes a watchdog.
If you no longer need a watchdog, call this function to close it and release its device handle to prevent unnecessary use of memory resources.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog device handle. |
## WatchdogFeed\(\)
```
int32_t WatchdogFeed ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle)
```
**Description:**
Feeds a watchdog, that is, resets a watchdog timer.
After a watchdog is started, you must feed it to reset the watchdog timer periodically. If you do not do so, the watchdog hardware will reset the system upon a timeout.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog handle, which is obtained via WatchdogOpen. |
**Returns:**
Returns **0** if the watchdog is fed; returns a negative value otherwise.
## WatchdogGetStatus\(\)
```
int32_t WatchdogGetStatus ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, int32_t * status )
```
**Description:**
Obtains the watchdog status.
For the available watchdog statuses, see [WatchdogStatus](WATCHDOG.md#ga3c77a35e1051e3f99238029519ac1954).
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog handle, which is obtained via WatchdogOpen. |
| status |
Indicates the pointer to the watchdog status. |
**Returns:**
Returns **0** if the watchdog status is obtained; returns a negative value otherwise.
## WatchdogGetTimeout\(\)
```
int32_t WatchdogGetTimeout ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint32_t * seconds )
```
**Description:**
Obtains the watchdog timeout duration.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog handle, which is obtained via WatchdogOpen. |
| seconds |
Indicates the pointer to the timeout duration, in seconds. |
**Returns:**
Returns **0** if the watchdog timeout duration is obtained; returns a negative value otherwise.
## WatchdogOpen\(\)
```
[DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) WatchdogOpen (int16_t wdtId)
```
**Description:**
Opens a watchdog.
Before operating a watchdog, you must call this function to open it and obtain its device handle.
**Parameters:**
Name
|
Description
|
| wdtId |
Indicates the watchdog ID. |
**Returns:**
Returns the pointer to the device handle of the watch dog if the operation is successful; returns **NULL** otherwise.
## WatchdogSetTimeout\(\)
```
int32_t WatchdogSetTimeout ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle, uint32_t seconds )
```
**Description:**
Sets the watchdog timeout duration.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog handle, which is obtained via WatchdogOpen. |
| seconds |
Indicates the timeout duration, in seconds. |
**Returns:**
Returns **0** if the setting is successful; returns a negative value otherwise.
## WatchdogStart\(\)
```
int32_t WatchdogStart ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle)
```
**Description:**
Starts a watchdog.
This function starts the watchdog timer. You must feed the watchdog periodically; otherwise, the watchdog hardware will reset the system upon a timeout.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog handle, which is obtained via WatchdogOpen. |
**Returns:**
Returns **0** if the watchdog is successfully started; returns a negative value otherwise.
**Attention:**
If the watchdog timer has started before this function is called, calling this function will succeed; however, the watchdog hardware determines whether to reset the timer.
## WatchdogStop\(\)
```
int32_t WatchdogStop ([DevHandle](COMMON.md#gab8c2d38e46eec50bd097a27d3d8bf041) handle)
```
**Description:**
Stops a watchdog.
If the watchdog has stopped before this function is called, calling this function will succeed.
**Parameters:**
Name
|
Description
|
| handle |
Indicates the pointer to the watchdog handle, which is obtained via WatchdogOpen. |
**Returns:**
Returns **0** if the watchdog is successfully stopped; returns a negative value otherwise.