335x uboot 看门狗喂狗
来源:互联网 发布:阿里云网站监控平台 编辑:程序博客网 时间:2024/05/21 10:09
一、说明:
看门狗,又叫watchdog timer,主要用来监控、管理CPU的运行状态,并对处于异常状态中的CPU进行复位操作,使其能重新工作。
看门狗可分为硬件看门狗和软件看门狗两种。
这里使用硬件看门狗:电路图如下:
这个硬件设计,在开机后,系统需要全程喂狗,
喂狗操作:WDI(Watchdog Input)的电平信号超过1.6S不发生跳变时,就会让系统重启,所以只需让WDI在每个1.6s内遇到一个上升沿或者下降沿即可。
其他更详细的内容请自己在网上查找。
二、uboot代码修改
1、
在include/watchdog.h文件中有宏定义
#ifdef CONFIG_HW_WATCHDOG
#if defined(__ASSEMBLY__)
#define WATCHDOG_RESET bl hw_watchdog_reset
#else
extern void hw_watchdog_reset(void);
#define WATCHDOG_RESET hw_watchdog_reset
#endif
所以,需要打开CONFIG_HW_WATCHDOG开关以及实现hw_watchdog_reset喂狗函数。
2、
在板级头文件中include/configs/am335x_evm.h文件中加上宏定义
#define CONFIG_HW_WATCHDOG 1
#define GPIO_WATCHDOG 23
然后在板级文件board/ti/am335x/evm.c中加入喂狗函数hw_watchdog_reset
#ifdef CONFIG_HW_WATCHDOG
#include <watchdog.h>
void gpio0_23_watchdog(void)
{
enable_gpio0_23_pin_mux();
gpio_request(GPIO_WATCHDOG, "gpio_watchdog");
gpio_direction_output(GPIO_WATCHDOG,0);
}
void hw_watchdog_reset(void)
{
gpio_set_value(GPIO_WATCHDOG, 1);
gpio_set_value(GPIO_WATCHDOG, 0);
}
#endif
说明:喂狗使用的是GPIO0_23(根据自己的引脚配置修改)
(1)、在board/ti/am335x/mux.c中加上引脚初始化代码
static struct module_pin_mux gpio0_23_pin_mux[] = {
{OFFSET(gpmc_ad9), (MODE(7) | PULLUDEN)}, /* GPIO0_23 */
{-1},
};
void enable_gpio0_23_pin_mux(void)
{
configure_module_pin_mux(gpio0_23_pin_mux);
}
(2)在board/ti/am335x/common_def.h中加上函数声明
extern void enable_gpio0_23_pin_mux(void);
3、
在uboot启动过程中要执行gpio0_23_watchdog();函数
我加在common/main.c中,也可以加在其他地方
我加在arch/arm/lib/board.c中,也可以加在其他地方
void board_init_f(ulong bootflag)
{
bd_t *bd;
init_fnc_t **init_fnc_ptr;
gd_t *id;
ulong addr, addr_sp;
/*add gpio0_23 for watchdog by liuc of 2013-1-30*/
#ifdef CONFIG_HW_WATCHDOG
gpio0_23_watchdog();
#endif
.......................
}
4、然后编译,uboot烧写成功后,即可使用,用tftp烧写内核和文件系统是正常的。
问题:
用SD卡烧写文件系统即大文件的时候系统会重启,原因应该是读写SD卡文件的函数没有进行喂狗,
解决办法:
SD卡烧写文件系统时喂狗
在drivers/mmc/omap_hsmmc.c文件中加上头文件
#include <watchdog.h>
修改函数如下:
static int mmc_read_data(hsmmc_t *mmc_base, char *buf, unsigned int size)
{
……………………………………..
while (size) {
/*add gpio0_23 for watchdog by liuc of 2013-2-4*/
WATCHDOG_RESET();
ulong start = get_timer(0);
do {
mmc_stat = readl(&mmc_base->stat);
if (get_timer(0) - start > MAX_RETRY_MS) {
printf("%s: timedout waiting for status!\n",
__func__);
return TIMEOUT;
}
} while (mmc_stat == 0);
……………………………….
}
static int mmc_write_data(hsmmc_t *mmc_base, const char *buf, unsigned int size)
{
………………………
while (size) {
/*add gpio0_23 for watchdog by liuc of 2013-2-4*/
WATCHDOG_RESET();
ulong start = get_timer(0);
do {
mmc_stat = readl(&mmc_base->stat);
if (get_timer(0) - start > MAX_RETRY_MS) {
printf("%s: timedout waiting for status!\n",
__func__);
return TIMEOUT;
}
} while (mmc_stat == 0);
……………………….
}
看门狗,又叫watchdog timer,主要用来监控、管理CPU的运行状态,并对处于异常状态中的CPU进行复位操作,使其能重新工作。
看门狗可分为硬件看门狗和软件看门狗两种。
这里使用硬件看门狗:电路图如下:
这个硬件设计,在开机后,系统需要全程喂狗,
喂狗操作:WDI(Watchdog Input)的电平信号超过1.6S不发生跳变时,就会让系统重启,所以只需让WDI在每个1.6s内遇到一个上升沿或者下降沿即可。
其他更详细的内容请自己在网上查找。
二、uboot代码修改
1、
在include/watchdog.h文件中有宏定义
#ifdef CONFIG_HW_WATCHDOG
#if defined(__ASSEMBLY__)
#define WATCHDOG_RESET bl hw_watchdog_reset
#else
extern void hw_watchdog_reset(void);
#define WATCHDOG_RESET hw_watchdog_reset
#endif
所以,需要打开CONFIG_HW_WATCHDOG开关以及实现hw_watchdog_reset喂狗函数。
2、
在板级头文件中include/configs/am335x_evm.h文件中加上宏定义
#define CONFIG_HW_WATCHDOG 1
#define GPIO_WATCHDOG 23
然后在板级文件board/ti/am335x/evm.c中加入喂狗函数hw_watchdog_reset
#ifdef CONFIG_HW_WATCHDOG
#include <watchdog.h>
void gpio0_23_watchdog(void)
{
enable_gpio0_23_pin_mux();
gpio_request(GPIO_WATCHDOG, "gpio_watchdog");
gpio_direction_output(GPIO_WATCHDOG,0);
}
void hw_watchdog_reset(void)
{
gpio_set_value(GPIO_WATCHDOG, 1);
gpio_set_value(GPIO_WATCHDOG, 0);
}
#endif
说明:喂狗使用的是GPIO0_23(根据自己的引脚配置修改)
(1)、在board/ti/am335x/mux.c中加上引脚初始化代码
static struct module_pin_mux gpio0_23_pin_mux[] = {
{OFFSET(gpmc_ad9), (MODE(7) | PULLUDEN)}, /* GPIO0_23 */
{-1},
};
void enable_gpio0_23_pin_mux(void)
{
configure_module_pin_mux(gpio0_23_pin_mux);
}
(2)在board/ti/am335x/common_def.h中加上函数声明
extern void enable_gpio0_23_pin_mux(void);
3、
在uboot启动过程中要执行gpio0_23_watchdog();函数
我加在common/main.c中,也可以加在其他地方
我加在arch/arm/lib/board.c中,也可以加在其他地方
void board_init_f(ulong bootflag)
{
bd_t *bd;
init_fnc_t **init_fnc_ptr;
gd_t *id;
ulong addr, addr_sp;
/*add gpio0_23 for watchdog by liuc of 2013-1-30*/
#ifdef CONFIG_HW_WATCHDOG
gpio0_23_watchdog();
#endif
.......................
}
4、然后编译,uboot烧写成功后,即可使用,用tftp烧写内核和文件系统是正常的。
问题:
用SD卡烧写文件系统即大文件的时候系统会重启,原因应该是读写SD卡文件的函数没有进行喂狗,
解决办法:
SD卡烧写文件系统时喂狗
在drivers/mmc/omap_hsmmc.c文件中加上头文件
#include <watchdog.h>
修改函数如下:
static int mmc_read_data(hsmmc_t *mmc_base, char *buf, unsigned int size)
{
……………………………………..
while (size) {
/*add gpio0_23 for watchdog by liuc of 2013-2-4*/
WATCHDOG_RESET();
ulong start = get_timer(0);
do {
mmc_stat = readl(&mmc_base->stat);
if (get_timer(0) - start > MAX_RETRY_MS) {
printf("%s: timedout waiting for status!\n",
__func__);
return TIMEOUT;
}
} while (mmc_stat == 0);
……………………………….
}
static int mmc_write_data(hsmmc_t *mmc_base, const char *buf, unsigned int size)
{
………………………
while (size) {
/*add gpio0_23 for watchdog by liuc of 2013-2-4*/
WATCHDOG_RESET();
ulong start = get_timer(0);
do {
mmc_stat = readl(&mmc_base->stat);
if (get_timer(0) - start > MAX_RETRY_MS) {
printf("%s: timedout waiting for status!\n",
__func__);
return TIMEOUT;
}
} while (mmc_stat == 0);
……………………….
}
阅读全文
0 0
- 335x uboot 看门狗喂狗
- 335x uboot 看门狗喂狗
- 335x uboot 硬件喂狗
- 多任务看门狗, 喂狗方法
- idea6410看门狗watchdog移植及喂狗
- Uboot之关闭看门狗、设置主机频率、关闭中断
- 嵌入式 在uboot中添加硬件看门狗小示例
- uboot关闭看门狗和中断---嵌入式回归第八篇
- 嵌入式学习-uboot-lesson4.3-关闭看门狗和中断
- uboot详解——cpu内部,外部和软件看门狗
- 看门狗
- 看门狗
- 看门狗
- 看门狗
- 看门狗
- 看门狗
- 看门狗
- 看门狗
- Android 面试宝典
- 『学习laravel』那些坑 (一)之安装
- js-浅析js指向-this绑定优先级及特殊情况说明
- 利用线上yum源,制作本地yum源
- 模糊控制系统模糊控制器模块(一)---模糊化
- 335x uboot 看门狗喂狗
- TCP/UDP
- mybatis中的#和$的区别
- SpringBoot整合Mybatis出现的错误
- 用两个线程玩猜数字游戏,第一个线程负责随机给出1~100之间的一个整数,第二个线程负责猜出这个数。要求每当第二个线程给出自己的猜测后,第一个线程都会提示“猜小了”、“猜大了”或“猜对
- dubbo简介
- MFC显示JPG格式的图片(2-1)
- Android Studio打包apk
- 12Linux安装-CRT安装配置