1 Star 0 Fork 4.9K

famoustang / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Watchdog使用指导.md 22.38 KB
一键复制 编辑 原始数据 按行查看 历史
wenjun 提交于 2020-09-08 10:08 . add OpenHarmony 1.0 baseline

Watchdog使用指导

使用流程

使用watchdog的一般流程如图1所示。

图 1 watchdog使用流程图

打开Watchdog设备

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

int32_t WatchdogOpen(int16_t wdtId);

表 1 WatchdogOpen参数和返回值描述

参数

参数描述

wdtId

Watchdog设备号

返回值

返回值描述

NULL

打开失败

struct DevHandle类型指针

Watchdog设备句柄

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

参数

参数描述

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;
}

启动Watchdog

int32_t WatchdogStart(struct 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(struct DevHandle *handle);

表 6 WatchdogFeed参数和返回值描述

参数

参数描述

handle

看门狗设备句柄

返回值

返回值描述

0

喂狗成功

负数

喂狗失败

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

参数

参数描述

handle

看门狗设备句柄

返回值

返回值描述

0

停止成功

负数

停止失败

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

参数

参数描述

handle

看门狗设备句柄

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

搜索帮助