Watchdog

概述

看门狗(WDG)实质上是一种定时器,当计时达到设定数值后超时会引起系统复位。

当程序开始运行后,WDG 开始计数,系统会在 WDG 达到设定数值之前发出喂狗信号指示 WDG 置零,并重新开始计数,以保证系统继续正常运行。若 WDG 在设定时间内未收到喂狗信号而导致计数超时,则判定所属系统出现异常,并产生复位信号,从而达到保护系统的目的。

WQ7036 每个 CPU/DSP 有一个 WDG 模块,此外还有一个 PMU WDG 用于 Always ON 检测全局复位。

功能特性

  • 配置密码保护,若写入密码错误则不可进行写入配置。

  • feeddog 操作码保护,写入正确的码才能喂狗成功。

  • 产生 timeout 中断。

  • 计数 counter 和超时状态开关。

工作原理

WDG 计数器在时钟有效和复位撤销后开始计数,计数到设定值时产生 inter_wdg 中断信号并清零计数器,重新开始计数。WDG 每到达一次设定值,timeout、cpurst 和 fullrst 计数器各加 1。这三个计数器到达各自的设定值时产生 timeout 中断、CPU 复位和全局复位请求。

../../_images/WDG_operation_principle.png

WDG 工作原理图

用法流程

  • 初始化 wq_wdt_init() wq_wdt_global_init()

  • 使能看门狗 wq_wdt_enable() wq_wdt_global_enable()

  • 喂狗 wq_wdt_do_feed() wq_wdt_global_do_feed()

  • 设置超时时间 wq_wdt_set_feed_period() wq_wdt_global_set_feed_period()

  • 判断是否需要喂狗 wq_wdt_need_feed() wq_wdt_global_need_feed()

  • 重启看门狗 wq_wdt_do_reset() wq_wdt_global_do_reset()

  • 关闭看门狗 wq_wdt_disable() wq_wdt_global_disable() wq_wdt_disable_all()

API 介绍

This section introduces the WDT module's functions and how to use this driver.

Functions

void wq_wdt_init(void)

This function is to init watchdog moudle.

void wq_wdt_deinit(void)

This function is to deinitialize watchdog module.

bool wq_wdt_need_feed(void)

This function is to confirm whether the used watchdog need the feedback or not.

返回:

bool true or false.

void wq_wdt_do_feed(void)

This function is to set the feedback of the used watchdog.

WQ_RET wq_wdt_auto_feed(bool enable)

Let watchdog feed itself at feed isr.

参数:

enable -- [in] true - enable, false - disable

返回:

WQ_RET

  • WQ_RET_OK SUCC

void wq_wdt_do_reset(void)

This function is to reset the watchdog.

void wq_wdt_set_feed_period(uint32_t period)

This function is to set the period of the watchdog's feedback.

参数:

period -- is feed interval, unit is second.

void wq_wdt_global_init(void)

This function is to init the gobal watchdog module.

void wq_wdt_global_deinit(void)

This function is to deinitialize the gobal watchdog module.

bool wq_wdt_global_need_feed(void)

This function is to confirm whether the global used watchdog need the feedback or not.

返回:

bool true or false.

void wq_wdt_global_do_feed(void)

This function is to set the feedback of the global used WDT.

void wq_wdt_global_do_reset(bool chip_reset)

This function is to reset the global watchdog.

参数:

chip_reset -- is chip reset(reset scratch register) or not(keep scratch register)

void wq_wdt_global_set_feed_period(uint32_t period)

This function is to set the period of the global watchdog's feed.

参数:

period --

uint32_t wq_wdt_global_get_feed_cnt(void)

This function is to get the total feed count of global watchdog. it usually used as feed cnt log to show the system whether itis still alive. if this cnt changed then means it's still alive.

返回:

the totally feed count value

void wq_wdt_disable_all(void)

This function is to disable all system watchdog and global watchdog.

uint32_t wq_wdt_get_feed_cnt(void)

This function is to get the total feed cnt usually used as feed cnt log to show the system is still alive. if this cnt changed then means it's still alive.

返回:

the totally feed count value

bool wq_wdt_is_timeout(uint8_t *id)

This function is to get watchdog timeout's status.

参数:

id -- [out] is timeout watchdog id.

返回:

bool is true if watchdog time occured.

uint32_t wq_wdt_check_timeout(void)

This function is to check any watchdog timeout.

返回:

wdt_id if wdt timeout

void wq_wdt_enable(void)

This function is to enable system watchdog.

void wq_wdt_disable(void)

This function is to disable system watchdog.

void wq_wdt_disable_by_id(uint8_t id)

This function is to disable system watchdog by id.

void wq_wdt_global_enable(void)

This function is to enable global watchdog.

void wq_wdt_global_disable(void)

This function is to disable global watchdog.