📄 s3c2410-watchdog.c
字号:
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/miscdevice.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <linux/irq.h>
#include <linux/delay.h>
#include <linux/vmalloc.h>
#include <linux/Def.h>#include <linux/2410.h>#include <asm/system.h>#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/arch/cpu_s3c2410.h>
#ifdef CONFIG_PM
#include <linux/pm.h>
#endif
#define WATCHDOG_MAJOR 193
#define DEVICE_NAME "watchdog"
devfs_handle_t devfs_watchdog;int wdflag = 1;static ssize_t watchdog_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
return count;
}
static ssize_t watchdog_write (struct file *file, const char *buffer, size_t user_len, loff_t *offset)
{ //printk("wdflag = %d \n" , wdflag); if ( wdflag == 1 ) { printk("wdflag = 1 \n"); WTCON = 0xff39; wdflag = 0; } WTCNT = 0xffff;
return user_len;
}
static int watchdog_open(struct inode *inode, struct file *filp)
{
MOD_INC_USE_COUNT; //计数器加一
return 0;
}
static int watchdog_release(struct inode *inode, struct file *filp)
{
MOD_DEC_USE_COUNT; //计数器减一
return 0;
}
static struct file_operations s3c2410watchdog_fops = {
owner : THIS_MODULE,
read : watchdog_read,
open : watchdog_open,
write : watchdog_write,
release : watchdog_release,
};
static int __init watchdog_init(void)
{
int ret , flags;
local_irq_save (flags); //关闭所有的中断 并保存当前的状态 WTDAT = 0xffff; WTCNT = 0xffff; WTCON = 0xff18;
local_irq_restore(flags); //打开中断,并恢复状态 ret=register_chrdev (WATCHDOG_MAJOR,DEVICE_NAME,&s3c2410watchdog_fops);
if (ret<0)
{
return ret;
}
devfs_watchdog = devfs_register(NULL,"watchdog",DEVFS_FL_DEFAULT,WATCHDOG_MAJOR, 0, S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP, &s3c2410watchdog_fops, NULL);
return 0;
}
static void __exit watchdog_exit(void)
{
devfs_unregister(devfs_watchdog);
}
module_init(watchdog_init);
module_exit(watchdog_exit);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -