1 Star 0 Fork 4.9K

fish / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
watchdogusage-guidelines.md 21.52 KB
一键复制 编辑 原始数据 按行查看 历史
NEEN 提交于 2021-03-12 17:59 . !197 Docs Update version 1.0.1

Watchdog Usage Guidelines

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

Parameter

Description

wdtId

Watchdog ID.

Return Value

Description

NULL

Failed to open the watchdog.

DevHandle pointer

Pointer to the watchdog handle.

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

Parameter

Description

handle

Watchdog handle.

status

Pointer to the watchdog status.

Return Value

Description

0

The watchdog status is obtained.

Negative value

Failed to obtain the watchdog status.

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

Parameter

Description

handle

Watchdog handle.

seconds

Timeout duration, in seconds.

Return Value

Description

0

The setting is successful.

Negative value

Setting failed.

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

Parameter

Description

handle

Watchdog handle.

seconds

Pointer to the timeout duration, in seconds.

Return Value

Description

0

The timeout duration is obtained.

Negative value

Failed to obtain the watchdog status.

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

Parameter

Description

handle

Watchdog handle.

Return Value

Description

0

The watchdog is started.

Negative value

Failed to start the watchdog.

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

Parameter

Description

handle

Watchdog handle.

Return Value

Description

0

The watchdog is fed.

Negative value

Failed to feed the watchdog.

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

Parameter

Description

handle

Watchdog handle.

Return Value

Description

0

The watchdog is stopped.

Negative value

Stopping the watchdog failed.

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

Parameter

Description

handle

Watchdog handle.

/* Close the watchdog. */
ret = WatchdogClose(handle);
1
https://gitee.com/fish_neil/docs.git
git@gitee.com:fish_neil/docs.git
fish_neil
docs
docs
master

搜索帮助