watchdog看门狗使用说明*
1. watchdog概述*
-
Watchdog,又称watchdog timer,是计算机可靠性(dependability)领域中一个极为简单同时非常有效的检测(detection)工具。
-
Watchdog的基本思想是针对被监视的目标设置一个计数器和一个阈值,watchdog会自己增加计数值,并等待被监视的目标周期性地重置计数值。一旦目标发生错误,没来得及重置计数值,watchdog会检测到计数值溢出,并采取恢复措施(通常情况下是重启)。
2. watchdog功能特性*
- 支持自动喂狗
- 支持手动喂狗
- 支持手动重启系统
3. watchdog相关API*
/*******************************************
* 看门狗初始化
*
* Parameters:
* reset_timeout_ms 看门狗复位芯片超时时间
* level_timeout_ms 看门狗产生超时时间
* irq_handler 中断服务回调函数
* pdata 中断服务回调函数私有参数
*******************************************/
void gx_watchdog_init(
uint16_t reset_timeout_ms,
uint16_t level_timeout_ms,
irq_handler_t irq_handler,
void *pdata
)
/*******************************************
* 看门狗喂狗
*******************************************/
void gx_watchdog_ping(void)
/******************************************
* 重启
*
* Returns:
* int 复位函数,不会返回
******************************************/
int gx_reboot(void)
/*****************************************
* 看门狗关闭
******************************************/
void gx_watchdog_stop(void)
4. watchdog代码示例*
- 在App中使用看门狗
lvp_tws/app/sample/lvp_app_sample.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
int watchdog_callback(int irq, void *pdata) // 看门狗中断服务函数 { gx_reboot(); // 重启 return 0; } static int SampleAppSuspend(void *priv) { // 关闭看门狗,如果有休眠,休眠前关闭看门狗会降低一些功耗 gx_watchdog_stop(); return 0; } static int SampleAppResume(void *priv) { return 0; } static int SampleAppInit(void) { printf(LOG_TAG" ---- %s ----\n", __func__); // 超时时间都设置为3s gx_watchdog_init(3000, 3000, watchdog_callback, NULL); return 0; } // App Event Process static int SampleAppEventResponse(APP_EVENT *app_event) { // 喂狗,每次audio in中断都会调用这个接口,audio in 中断一般在60ms // 也可以通过定时器来喂狗,在超时时间内喂狗就可以 gx_watchdog_ping(); return 0; } // APP Main Loop static int SampleAppTaskLoop(void) { return 0; } LVP_APP sample_app = { .app_name = "sample app", .AppInit = SampleAppInit, .AppEventResponse = SampleAppEventResponse, .AppTaskLoop = SampleAppTaskLoop, .AppSuspend = SampleAppSuspend, .suspend_priv = "SampleAppSuspend", .AppResume = SampleAppResume, .resume_priv = "SampleAppResume", }; LVP_REGISTER_APP(sample_app);