1 Star 0 Fork 5.1K

youguilin / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
看门狗使用指导.md 22.74 KB
一键复制 编辑 原始数据 按行查看 历史
mamingshuai 提交于 2021-06-02 01:00 . update OpenHarmony 2.0 Canary

看门狗使用指导

使用流程

使用看门狗的一般流程如图1所示。

图 1 看门狗使用流程图

打开看门狗设备

在操作看门狗之前,需要使用WatchdogOpen打开一个看门狗设备,一个系统可能有多个看门狗,通过ID号来打开指定的看门狗设备:

int32_t WatchdogOpen(int16_t wdtId);

表 1 WatchdogOpen参数和返回值描述

参数

参数描述

wdtId

看门狗设备号

返回值

返回值描述

NULL

打开失败

DevHandle类型指针

看门狗设备句柄

DevHandle handle = NULL;
handle = WatchdogOpen(0);  /* 打开0号看门狗设备 */
if (handle == NULL) {
    HDF_LOGE("WatchdogOpen: failed, ret %d\n", ret);
    return;
}

获取看门狗状态

int32_t WatchdogGetStatus(DevHandle handle, int32_t *status);

表 2 WatchdogGetStatus参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

status

获取到的启动状态指针

返回值

返回值描述

0

获取成功

负数

获取失败

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参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

seconds

超时时间,单位为秒

返回值

返回值描述

0

设置成功

负数

设置失败

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参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

seconds

接收超时时间的指针,单位为秒

返回值

返回值描述

0

获取成功

负数

获取失败

int32_t ret;
uint32_t timeOut;
/* 获取超时时间,单位:秒 */
ret = WatchdogGetTimeout(handle, &timeOut);
if (ret != 0) {
    HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret);
    return;
}

启动看门狗

int32_t WatchdogStart(DevHandle handle);

表 5 WatchdogStart参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

返回值

返回值描述

0

启动成功

负数

启动失败

int32_t ret;
/* 启动看门狗 */
ret = WatchdogStart(handle);
if (ret != 0) {
    HDF_LOGE("WatchdogStart: failed, ret %d\n", ret);
    return;
}

喂狗

int32_t WatchdogFeed(DevHandle handle);

表 6 WatchdogFeed参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

返回值

返回值描述

0

喂狗成功

负数

喂狗失败

int32_t ret;
/* 喂狗 */
ret = WatchdogFeed(handle);
if (ret != 0) {
    HDF_LOGE("WatchdogFeed: failed, ret %d\n", ret);
    return;
}

停止看门狗

int32_t WatchdogStop(DevHandle handle);

表 7 WatchdogStop参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

返回值

返回值描述

0

停止成功

负数

停止失败

int32_t ret;
/* 停止看门狗 */
ret = WatchdogStop(handle);
if (ret != 0) {
    HDF_LOGE("WatchdogStop: failed, ret %d\n", ret);
    return;
}

关闭看门狗设备

当操作完毕时,使用WatchdogClose关闭打开的设备句柄:

void WatchdogClose(DevHandle handle);

表 8 WatchdogClose参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

/* 关闭看门狗 */
ret = WatchdogClose(handle);
1
https://gitee.com/yougl/docs.git
git@gitee.com:yougl/docs.git
yougl
docs
docs
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891