看门狗的功能这里不再介绍,自行百度谷歌搜索。这里记录一下Hi3520DV400看门狗的喂狗设置。首先查 include/watchdog.h中的代码,可以发现,如果需要启用硬看门狗,需要定义宏:CONFIG_HW_WATCHDOG
/** Hardware watchdog*/#ifdef CONFIG_HW_WATCHDOG#if defined(__ASSEMBLY__)#define WATCHDOG_RESET bl hw_watchdog_reset#elseextern void hw_watchdog_reset(void);#define WATCHDOG_RESET hw_watchdog_reset#endif /* __ASSEMBLY__ */#else/** Maybe a software watchdog?*/#if defined(CONFIG_WATCHDOG)#if defined(__ASSEMBLY__)#define WATCHDOG_RESET bl watchdog_reset#elseextern void watchdog_reset(void);#define WATCHDOG_RESET watchdog_reset#endif#else/** No hardware or software watchdog.*/#if defined(__ASSEMBLY__)#define WATCHDOG_RESET /*XXX DO_NOT_DEL_THIS_COMMENT*/#else#define WATCHDOG_RESET() {}#endif /* __ASSEMBLY__ */#endif /* CONFIG_WATCHDOG && !__ASSEMBLY__ */#endif /* CONFIG_HW_WATCHDOG */
(一)配置宏
在/include/configs/hi3520dv400.h 中定义宏CONFIG_HW_WATCHDOG
#define CONFIG_HW_WATCHDOG 1
(二)函数实现
回到最前面的代码我们知道,如果定义了硬件看门狗喂狗,则需要实现函数extern int hw_watchdog_reset(void);
找一个位置添加两个文件:hiwtdog.h,hiwtdog.c,然后将这两个文件编译进Uboot就可以了。
hiwtdog.h
#ifndef _Hiwtdog_H#define _Hiwtdog_H#include <common.h>#include <environment.h>#include <command.h>#include <asm/io.h>#define HI_GPIO_MUTI_BASE_ADDR (0x120F0000)#define HI_GPIO6_BASE_ADDR (0x121B0000)#define HI_MUTI_SET_GPIO_WTDOG HI_GPIO_MUTI_BASE_ADDR+0x0F0 // //1:GPIO6_2;#define GPIO_DATA_WTDOG HI_GPIO6_BASE_ADDR+0x03fc // //6.2#define GPIO_DIR_WTDOG HI_GPIO6_BASE_ADDR+0x400 // //1:输出extern int hw_watchdog_reset(void);#endif
注意:如果是其它平台的芯片,HI_GPIO_MUTI_BASE_ADDR 和 HI_GPIO6_BASE_ADDR根据实际修改就可以。
hiwtdog.c
#include"hiwtdog.h"int hw_watchdog_reset(void){unsigned int reg_val = 0;unsigned char bit_val = 0;reg_val=readl(HI_MUTI_SET_GPIO_WTDOG);writel(reg_val | (1<<0),HI_MUTI_SET_GPIO_WTDOG);reg_val=readl(GPIO_DIR_WTDOG);writel(reg_val | (1<<2),GPIO_DIR_WTDOG);reg_val=readl(GPIO_DATA_WTDOG);reg_val = reg_val ^ (1<<2);writel(reg_val,GPIO_DATA_WTDOG);return reg_val;}
uboot 默认ftp ,串口等位置都有添加hw_watchdog_reset()函数进行喂狗,如果启动其它功能时uboot复位了,则可以自己在该功能的合适位置进行喂狗操作就可以了。
-----------------------------------------------.08.28-----------------------------------------------
新的文章内容和附件工程文件
已更新在博客首页和:
:liwen01公众号
为了避免被夹,只能字体中间画横线了
-----------------------------------------------.08.28-----------------------------------------------