Watchdog使用指导
使用流程
使用watchdog的一般流程如图1所示。
打开Watchdog设备
在操作Watchdog之前,需要使用WatchdogOpen打开一个Watchdog设备,一个系统可能有多个Watchdog,通过ID号来打开指定的Watchdog设备:
int32_t WatchdogOpen(int16_t wdtId);
表 1 WatchdogOpen参数和返回值描述
struct DevHandle *handle = NULL;
handle = WatchdogOpen(0); /* 打开0号看门狗设备 */
if (handle == NULL) {
HDF_LOGE("WatchdogOpen: failed, ret %d\n", ret);
return;
}
获取Watchdog状态
int32_t WatchdogGetStatus(struct DevHandle *handle, int32_t *status);
表 2 WatchdogGetStatus参数和返回值描述
int32_t ret;
int32_t status;
/* 获取Watchdog启动状态 */
ret = WatchdogGetStatus(handle, &status);
if (ret != 0) {
HDF_LOGE("WatchdogGetStatus: failed, ret %d\n", ret);
return;
}
设置超时时间
int32_t WatchdogSetTimeout(PalHandle *handle, uint32_t seconds);
表 3 WatchdogSetTimeout参数和返回值描述
int32_t ret;
uint32_t timeOut = 60;
/* 设置超时时间,单位:秒 */
ret = WatchdogSetTimeout(handle, timeOut);
if (ret != 0) {
HDF_LOGE("WatchdogSetTimeout: failed, ret %d\n", ret);
return;
}
获取超时时间
int32_t WatchdogGetTimeout(PalHandle *handle, uint32_t *seconds);
表 4 WatchdogGetTimeout参数和返回值描述
int32_t ret;
uint32_t timeOut;
/* 获取超时时间,单位:秒 */
ret = WatchdogGetTimeout(handle, &timeOut);
if (ret != 0) {
HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret);
return;
}
启动Watchdog
int32_t WatchdogStart(struct DevHandle *handle);
表 5 WatchdogStart参数和返回值描述
int32_t ret;
/* 启动看门狗 */
ret = WatchdogStart(handle);
if (ret != 0) {
HDF_LOGE("WatchdogStart: failed, ret %d\n", ret);
return;
}
喂狗
int32_t WatchdogFeed(struct DevHandle *handle);
表 6 WatchdogFeed参数和返回值描述
int32_t ret;
/* 喂狗 */
ret = WatchdogFeed(handle);
if (ret != 0) {
HDF_LOGE("WatchdogFeed: failed, ret %d\n", ret);
return;
}
停止Watchdog
int32_t WatchdogStop(struct DevHandle *handle);
表 7 WatchdogStop参数和返回值描述
int32_t ret;
/* 停止看门狗 */
ret = WatchdogStop(handle);
if (ret != 0) {
HDF_LOGE("WatchdogStop: failed, ret %d\n", ret);
return;
}
关闭Watchdog设备
当操作完毕时,使用WatchdogClose关闭打开的设备句柄:
void WatchdogClose(struct DevHandle *handle);
表 8 WatchdogClose参数和返回值描述
/* 关闭看门狗 */
ret = WatchdogClose(handle);