核心配置项:CONFIG_HW_WATCHDOG
核心配置项:CONFIG_WDT
// file: drivers/watchdog/Kconfig
config WDT
bool "Enable driver model for watchdog timer drivers"
depends on DM
....
CONFIG_HW_WATCHDOG
CONFIG_WATCHDOG_TIMEOUT_MSECS
CONFIG_DESIGNWARE_WATCHDOG
config DESIGNWARE_WATCHDOG
bool "Designware watchdog timer support"
select HW_WATCHDOG if !WDT
...
//file: drivers/watchdog/designware_wdt.c
static int designware_wdt_settimeout(unsigned int timeout)
{
....
}
static void designware_wdt_enable(void)
{
....
}
static void designware_wdt_disable(void)
{
....
}
static unsigned int designware_wdt_is_enabled(void)
{
....
}
//file: drivers/watchdog/designware_wdt.c
#if defined(CONFIG_HW_WATCHDOG)
void hw_watchdog_reset(void)
{
...
}
void hw_watchdog_init(void)
{
// 初始化wdt,并enable
...
}
void hw_watchdog_disable(void)
{
...
}
#endif
// file: include/watchdog.h
#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
#define INIT_FUNC_WATCHDOG_INIT init_func_watchdog_init,
#define INIT_FUNC_WATCHDOG_RESET init_func_watchdog_reset,
#else
#define INIT_FUNC_WATCHDOG_INIT
#define INIT_FUNC_WATCHDOG_RESET
#endif
#ifdef CONFIG_HW_WATCHDOG
#if defined(__ASSEMBLY__)
#define WATCHDOG_RESET bl hw_watchdog_reset
#else
extern void hw_watchdog_reset(void);
extern void hw_watchdog_disable(void);
#define WATCHDOG_RESET hw_watchdog_reset
#define WATCHDOG_DISABLE hw_watchdog_disable
#endif /* __ASSEMBLY__ */
#else
....
#endif
CONFIG_WDT
CONFIG_WATCHDOG // enable uboot内部使用的喂狗接口,该方式下必需enable
// file: drivers/watchdog/Kconfig
config WDT
bool "Enable driver model for watchdog timer drivers"
depends on DM
imply WATCHDOG
...
CONFIG_WATCHDOG_AUTOSTART=y // 自动启动
CONFIG_WATCHDOG_TIMEOUT_MSECS //wdt timeout时间, 默认60s
CONFIG_DESIGNWARE_WATCHDOG
//file: include/wdt.h
struct wdt_ops {
int (*start)(struct udevice *dev, u64 timeout_ms, ulong flags);
int (*stop)(struct udevice *dev);
int (*reset)(struct udevice *dev);
int (*expire_now)(struct udevice *dev, ulong flags);
}
// file: include/watchdog.h
#ifdef CONFIG_HW_WATCHDOG
...
#else
/*
* Maybe a software watchdog?
*/
#if defined(CONFIG_WATCHDOG)
#if defined(__ASSEMBLY__)
#define WATCHDOG_RESET bl watchdog_reset
#else
/* Don't require the watchdog to be enabled in SPL */
#if defined(CONFIG_SPL_BUILD) && \
!defined(CONFIG_SPL_WATCHDOG)
#define WATCHDOG_RESET() {}
#else
extern void watchdog_reset(void);
#define WATCHDOG_RESET watchdog_reset
#endif
#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 */
CONFIG_CMD_WDT=y // wdt cmd
uboot# wdt
wdt - Watchdog sub-system
Usage:
wdt list - list watchdog devices
wdt dev [] - get/set current watchdog device
wdt start [flags] - start watchdog timer
wdt stop - stop watchdog timer
wdt reset - reset watchdog timer
wdt expire [flags] - expire watchdog timer immediately
uboot# wdt list
dw-wd@0x27000000 (designware_wdt) // dts配置
uboot# wdt dev dw-wd@0x27000000
uboot# wdt start 30000
//file: common/board_f.c
#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
static int init_func_watchdog_init(void)
{
# if defined(CONFIG_HW_WATCHDOG) && \
(defined(CONFIG_M68K) || defined(CONFIG_MICROBLAZE) || \
defined(CONFIG_SH) || \
defined(CONFIG_DESIGNWARE_WATCHDOG) || \
defined(CONFIG_IMX_WATCHDOG))
hw_watchdog_init(); //该函数,默认实现会配置好wdt,并enable
puts(" Watchdog enabled\n");
# endif
WATCHDOG_RESET();
return 0;
}
int init_func_watchdog_reset(void)
{
WATCHDOG_RESET();
return 0;
}
#endif /* CONFIG_WATCHDOG */