内置看门狗的支持

本文介绍如何在特定硬件平台上启用并配置CPU内置的看门狗功能,包括在bootstrap和U-Boot阶段进行必要的设置,以及在内核层面实现用户程序喂狗功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

2. uboot中增加喂狗。

    1)定义看门狗宏定义:include\configs\at91sam9260ek.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!\n");
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'\n", 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. 内核中修改喂狗驱动,使用户程序可喂狗。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值