内置看门狗的支持

若要板卡支持CPU内置看门狗,可做如下修改。

1. bootstrap中开启cpu内置看门狗。

2. uboot中增加喂狗。

    1)定义看门狗宏定义:includeconfigsat91sam9260ek.h  

       #define CONFIG_HW_WATCHDOG

    2)增加看门狗函数:board/atmel/at91sam9260ek/at91sam9260ek.c

//---------------------------------------------------
#define AT91_WDT (0xfffffd40 - AT91_BASE_SYS)
#define AT91_WDT_CR (AT91_WDT + 0x00) /* Watchdog Control Register */
#define AT91_WDT_WDRSTT (1 << 0) /* Restart */
#define AT91_WDT_KEY (0xa5 << 24) /* KEY Password */


#ifdef CONFIG_HW_WATCHDOG
#include <watchdog.h>
void hw_watchdog_reset(void)
{
writel(AT91_WDT_KEY | AT91_WDT_WDRSTT, AT91_BASE_SYS + AT91_WDT_CR);
}
#endif

    3)common/main.c修改

main_loop ()函数,for()中输入字符处理前后加入以下看门狗

#ifdef CONFIG_HW_WATCHDOG //加看门狗
#include <watchdog.h>
WATCHDOG_RESET();
#endif

len = readline (CFG_PROMPT);

#ifdef CONFIG_HW_WATCHDOG
WATCHDOG_RESET();
#endif

第2处更改
run_command()函数中加入两处处理

if (strlen(cmd) >= CFG_CBSIZE) {
puts ("## Command too long! ");
return -1;
}

#ifdef CONFIG_HW_WATCHDOG
#include <watchdog.h>
WATCHDOG_RESET();
#endif

strcpy (cmdbuf, cmd);


/* Extract arguments */
if ((argc = parse_line (finaltoken, argv)) == 0) {
rc = -1; /* no command at all */
continue;
}

#ifdef CONFIG_HW_WATCHDOG
#include <watchdog.h>
WATCHDOG_RESET();
#endif

/* Look up command in command table */
if ((cmdtp = find_cmd(argv[0])) == NULL) {
printf ("Unknown command '%s' - try 'help' ", argv[0]);

    4)在串口输出/输出字符函数增加看门狗函数:drivers/serial/atmel_usart.c

// 必须加,否则等待命令有问题
int serial_getc(void)
{
while (!(usart3_readl(CSR) & USART3_BIT(RXRDY)))
{
#ifdef CONFIG_HW_WATCHDOG
#include <watchdog.h>
WATCHDOG_RESET();
#endif
}
return usart3_readl(RHR); //读一字节
}

3. 内核中修改喂狗驱动,使用户程序可喂狗。

原文地址:https://www.cnblogs.com/embedded-linux/p/5998219.html