s3c6410在linux下的WATCHDOG TIMER(看门狗定时器)驱动(1)

来源:互联网 发布:零售门店经营数据分析 编辑:程序博客网 时间:2024/04/30 14:20

转自:http://blog.csdn.net/tianxiawuzhei/article/details/7586214

s3c6410在linux下的WATCHDOG TIMER(看门狗定时器)驱动(1)

分类: linux驱动 817人阅读 评论(0)收藏 举报
timerlinuxcstructmodule平台

s3c6410硬件WATCHDOG TIMER(看门狗定时器)的链接地址

如果对看门狗定时器的硬件不太熟悉,可以看上面这篇文章。


还是先说下整体结构,又要说到大家很熟悉的平台设备了,同样看门狗定时器也是作为平台设备存在的,但与以前的不同的地方是,看门狗定时器是一种混杂设备,先介绍下混杂设备。

1、混杂设备

1.1、混杂设备并没有明确的定义。它的主设备号是10,不同的设备用次设备号区分。混杂设备用结构体miscdevice表示,源码如下:

struct miscdevice {
int minor; 次设备号
const char *name; 设备名
const struct file_operations *fops;设备的操作函数,与字符设备相同
struct list_head list; 链接混杂设备的链表
struct device *parent;指向父设备
struct device *this_device;指向设备结构体
};

对应的看下看门狗中的定义:

在S3c2410_wdt.c (linux2.6.28\drivers\watchdog)文件中

static struct miscdevice s3c2410wdt_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &s3c2410wdt_fops,
};

其中还有:

/* kernel interface */
static const struct file_operations s3c2410wdt_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.write = s3c2410wdt_write,
.unlocked_ioctl= s3c2410wdt_ioctl,
.open = s3c2410wdt_open,
.release = s3c2410wdt_release,
};

1.2、混杂设备的注册和注销

内核提供了misc_register用于注册一个混杂设备。

/**
* misc_register-register a miscellaneous device
* @misc: device structure

int misc_register(struct miscdevice * misc)

同样对应的内核提供了misc_deregister用于混杂设备的注销。

/**
* misc_deregister - unregister a miscellaneous device
* @misc: device to unregister

int misc_deregister(struct miscdevice *misc)

2、再来看看门狗定时器作为平台设备存在

static struct platform_driver s3c2410wdt_driver = {
.probe = s3c2410wdt_probe,
.remove = s3c2410wdt_remove,
.shutdown = s3c2410wdt_shutdown,
.suspend = s3c2410wdt_suspend,
.resume = s3c2410wdt_resume,
.driver = {
.owner = THIS_MODULE,
.name = "s3c2410-wdt",
},
};


static char banner[] __initdata =
KERN_INFO "S3C2410 Watchdog Timer, (c) 2004 Simtec Electronics\n";

static int __init watchdog_init(void)
{
printk(banner);
return platform_driver_register(&s3c2410wdt_driver);
}
static void __exit watchdog_exit(void)
{
platform_driver_unregister(&s3c2410wdt_driver);
}
module_init(watchdog_init);
module_exit(watchdog_exit);

看到这些,你可能都看腻了。没办法,接着来,平台设备的资源定义在

Devs.c (linux2.6.28\arch\arm\plat-s3c64xx)文件中:

/* Watchdog */
static struct resource s3c_wdt_resource[] = {
[0] = {
.start = S3C64XX_PA_WATCHDOG,
.end = S3C64XX_PA_WATCHDOG + S3C64XX_SZ_WATCHDOG - 1,
.flags = IORESOURCE_MEM,
},
[1] = {
.start = IRQ_WDT,
.end = IRQ_WDT,
.flags = IORESOURCE_IRQ,
}
};

平台设备定义在同一个文件中:

struct platform_device s3c_device_wdt = {
.name = "s3c2410-wdt",
.id = -1,
.num_resources = ARRAY_SIZE(s3c_wdt_resource),
.resource = s3c_wdt_resource,
};

EXPORT_SYMBOL(s3c_device_wdt);

3、S3c2410_wdt.c (linux2.6.28\drivers\watchdog)文件开头一些变量的含义(参考于网络和书籍),如下所示:

(1)、static int nowayout = WATCHDOG_NOWAYOUT;nowayout为1表示不允许关闭看门狗,为0表示可以关闭。
与CONFIG_WATCHDOG_NOWAYOUT配置相关,当配置为不允许关闭时,应用层调用close函数将不能关闭看门狗
#ifdef CONFIG_WATCHDOG_NOWAYOUT#define WATCHDOG_NOWAYOUT1#else#define WATCHDOG_NOWAYOUT0#endif
(2)、
static int tmr_margin = CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME;默认的喂狗时间
#define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME  (15)
(3)、static int tmr_atboot = CONFIG_S3C2410_WATCHDOG_ATBOOT;表示系统启动时就能使用看门狗。为1表示能,为0表示不能。
 #define CONFIG_S3C2410_WATCHDOG_ATBOOT  (0)
(4)、static int soft_noboot;表示看门狗的工作方式,看门狗可以作为定时器使用,也可以作为复位使用。soft_noboot为1时看门狗将作为一般的中断定时器使用,为0时作为可复位电路的看门狗,默认为0
(5)、static int debug;  调式模式
(6)、
module_param(tmr_margin,  int, 0);module_param(tmr_atboot,  int, 0);module_param(nowayout,    int, 0);module_param(soft_noboot, int, 0);module_param(debug,  int, 0);驱动程序模块参数,如果在加载驱动模块时没有设定这些参数,则这些参数将采用默认值。
(7)、
typedef enum close_state {CLOSE_STATE_NOT,不允许关闭CLOSE_STATE_ALLOW = 0x4021允许关闭} close_state_t;
用来标识看门狗是否允许关闭。
4、万变不离其宗,下一篇就要说平台设备对应的probe函数了,你做好准备了吗?下篇见。
s3c6410在linux下的WATCHDOG TIMER(看门狗定时器)驱动(2)的链接地址
s3c6410在linux下的WATCHDOG TIMER(看门狗定时器)驱动(3)的链接地址