Watchdog Usage Guidelines
- How to Use
- Opening a Watchdog
- Obtaining the Watchdog Status
- Setting the Timeout Duration
- Obtaining the Timeout Duration
- Starting a Watchdog
- Feeding a Watchdog
- Stopping a Watchdog
- Closing a Watchdog
How to Use
Figure 1 illustrates the process of using a watchdog.
Figure 1 Process of using a watchdog
Opening a Watchdog
Use WatchdogOpen to open a watchdog. A system may have multiple watchdogs. You can open a specified watchdog by using the ID.
int32_t WatchdogOpen(int16_t wdtId);
.
Table 1 Description of WatchdogOpen
DevHandle handle = NULL;
handle = WatchdogOpen(0); /* Open watchdog 0.*/
if (handle == NULL) {
HDF_LOGE("WatchdogOpen: failed, ret %d\n", ret);
return;
}
Obtaining the Watchdog Status
int32_t WatchdogGetStatus(DevHandle handle, int32_t *status);
.
Table 2 Description of WatchdogGetStatus
int32_t ret;
int32_t status;
/* Obtain the watchdog status. */
ret = WatchdogGetStatus(handle, &status);
if (ret != 0) {
HDF_LOGE("WatchdogGetStatus: failed, ret %d\n", ret);
return;
}
Setting the Timeout Duration
int32_t WatchdogSetTimeout(PalHandle *handle, uint32_t seconds);
Table 3 Description of WatchdogSetTimeout
int32_t ret;
uint32_t timeOut = 60;
/* Set the timeout duration, in seconds. */
ret = WatchdogSetTimeout(handle, timeOut);
if (ret != 0) {
HDF_LOGE("WatchdogSetTimeout: failed, ret %d\n", ret);
return;
}
Obtaining the Timeout Duration
int32_t WatchdogGetTimeout(PalHandle *handle, uint32_t *seconds);
Table 4 Description of WatchdogGetTimeout
int32_t ret;
uint32_t timeOut;
/* Obtain the timeout duration, in seconds. */
ret = WatchdogGetTimeout(handle, &timeOut);
if (ret != 0) {
HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret);
return;
}
Starting a Watchdog
int32_t WatchdogStart(DevHandle handle);
Table 5 Description of WatchdogStart
int32_t ret;
/* Start the watchdog. */
ret = WatchdogStart(handle);
if (ret != 0) {
HDF_LOGE("WatchdogStart: failed, ret %d\n", ret);
return;
}
Feeding a Watchdog
int32_t WatchdogFeed(DevHandle handle);
Table 6 Description of WatchdogFeed
int32_t ret;
/* Feed the watchdog. */
ret = WatchdogFeed(handle);
if (ret != 0) {
HDF_LOGE("WatchdogFeed: failed, ret %d\n", ret);
return;
}
Stopping a Watchdog
int32_t WatchdogStop(DevHandle handle);
Table 7 Description of WatchdogStop
int32_t ret;
/* Stop the watchdog. */
ret = WatchdogStop(handle);
if (ret != 0) {
HDF_LOGE("WatchdogStop: failed, ret %d\n", ret);
return;
}
Closing a Watchdog
If the watchdog is no longer required, call WatchdogClose to close the watchdog handle.
void WatchdogClose(DevHandle handle);
Table 8 Description of WatchdogClose
/* Close the watchdog. */
ret = WatchdogClose(handle);