一、看门狗设备驱动框架简介
看门狗框架涉及drivers/watchdog/watchdog_dev.c 、drivers/watchdog/watchdog_core.c、drivers/watchdog/watchdog_pretimeout.c 这三个源文件,其本质是misc设备。
- watchdog_dev.c:作为上层,注册字符设备操作函数集file_operations结构体变量,与应用层对接。
- watchdog_core.c:作为看门狗驱动框架核心层,提供看门狗设备的注册、卸载等相关API函数。
- watchdog_pretimeout.c:主要涉及看门狗定时、预超时相关处理。
二、struct watchdog_device结构体(描述看门狗设备)
struct watchdog_device {
int id;
struct device *parent;
const struct attribute_group **groups;
const struct watchdog_info *info;
const struct watchdog_ops *ops;
const struct watchdog_governor *gov;
unsigned int bootstatus;
unsigned int timeout;
unsigned int pretimeout;
unsigned int min_timeout;
unsigned int max_timeout;
unsigned int min_hw_heartbeat_ms;
unsigned int max_hw_heartbeat_ms;
struct notifier_block reboot_nb;
struct notifier_block restart_nb;
void *driver_data;
struct watchdog_core_data *wd_data;
unsigned long status;
/* Bit numbers for status flags */
#define WDOG_ACTIVE 0 /* Is the watchdog running/active */
#define WDOG_NO_WAY_OUT 1 /* Is 'nowayout' feature set ? */
#define WDOG_STOP_ON_REBOOT 2 /* Should be stopped on reboot */
#define WDOG_HW_RUNNING 3 /* True if HW watchdog running */
#define WDOG_STOP_ON_UNREGISTER 4 /* Should be stopped on unregister */
struct list_head deferred;
};
- id:id号,有watchdog_register_device函数注册时自动分配。
- parent:父设备,可填充&p