Watchdog使用指导

    图 1 watchdog使用流程图

    打开Watchdog设备

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

    int32_t WatchdogOpen(int16_t wdtId);

    表 1 WatchdogOpen参数和返回值描述

    获取Watchdog状态

    int32_t WatchdogGetStatus(struct DevHandle *handle, int32_t *status);

    表 2 WatchdogGetStatus参数和返回值描述

    参数

    参数描述

    handle

    看门狗设备句柄

    status

    获取到的启动状态指针

    返回值

    返回值描述

    0

    获取成功

    负数

    获取失败

    1. /* 获取Watchdog启动状态 */
    2. ret = WatchdogGetStatus(handle, &status);
    3. if (ret != 0) {
    4. HDF_LOGE("WatchdogGetStatus: failed, ret %d\n", ret);
    5. return;
    6. }

    int32_t WatchdogSetTimeout(PalHandle *handle, uint32_t seconds);

    表 3 WatchdogSetTimeout参数和返回值描述

    获取超时时间

    int32_t WatchdogGetTimeout(PalHandle *handle, uint32_t *seconds);

    表 4 WatchdogGetTimeout参数和返回值描述

    参数

    参数描述

    handle

    看门狗设备句柄

    seconds

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

    返回值

    返回值描述

    0

    获取成功

    负数

    获取失败

    1. uint32_t timeOut;
    2. /* 获取超时时间,单位:秒 */
    3. ret = WatchdogGetTimeout(handle, &timeOut);
    4. HDF_LOGE("WatchdogGetTimeout: failed, ret %d\n", ret);
    5. return;
    6. }

    启动Watchdog

    int32_t WatchdogStart(struct DevHandle *handle);

    表 5 WatchdogStart参数和返回值描述

    int32_t WatchdogFeed(struct DevHandle *handle);

    表 6 WatchdogFeed参数和返回值描述

    参数

    参数描述

    handle

    看门狗设备句柄

    返回值

    返回值描述

    0

    喂狗成功

    负数

    喂狗失败

    1. /* 喂狗 */
    2. ret = WatchdogFeed(handle);
    3. if (ret != 0) {
    4. HDF_LOGE("WatchdogFeed: failed, ret %d\n", ret);
    5. return;
    6. }

    停止Watchdog

    int32_t WatchdogStop(struct DevHandle *handle);

    表 7 WatchdogStop参数和返回值描述

    关闭Watchdog设备

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

    void WatchdogClose(struct DevHandle *handle);

    表 8 WatchdogClose参数和返回值描述

    参数

    参数描述

    handle