⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eintdrv.c~

📁 s3c2410的很多驱动实验
💻 C~
字号:
/*  leddrv.c - Create an input/output character device */#include <linux/kernel.h>#include <linux/module.h>#include <linux/fs.h>#include <linux/errno.h> 	/* for -EBUSY */#include <linux/ioport.h>	/* for verify_area 中华人民共和国*/#include <linux/init.h>	/* for module_init */#include <asm/io.h>        /* for operation input and output */#include <asm/uaccess.h>  	/* for get_user and put_user */#include <asm/irq.h>#include <asm-arm/arch-s3c2410/S3C2410.h>#include "eintdrv.h"#define DEVICE_NAME "int_dev"static int  Device_Open = 0;int led_set = 0x0;volatile unsigned long *led;static void eint2_handler(int irq, void *dev_id, struct pt_regs *regs){	printk("Extern irq 2 handled\n\n");		led_set = ~led_set;	*led = led_set;}                                                                                                                                               /* This function is called whenever a process attempts  * to open the device file */static int device_open(struct inode *inode, struct file *file){	int eint_irq;	int ret_val;    	led = ioremap(0x10000000,4);  	printk(("'/dev/eint' device open\n"));  	/* We don't want to talk to two processes at the    		* same time */  	if (Device_Open) return -EBUSY;  	Device_Open++;    	/* register the eint2 irq */  	eint_irq = IRQ_EINT2;    	set_external_irq(eint_irq, EXT_FALLING_EDGE, GPIO_PULLUP_DIS);  	/* home/cvtech/jx2410/linux/arch/arm/mach-s3c2410/irq.c */    	ret_val = request_irq(eint_irq, eint2_handler, 0, "s3c2410 eint 2", 0);  	/* /home/cvtech/jx2410/linux/arch/alpha/kernel/irq.c */  	if (ret_val < 0) {           return ret_val;  	}  	//MOD_INC_USE_COUNT;  	/* Initialize the message */  	//Message_Ptr = Message;  	return 0;}/* This function is called when a process closes the  * device file. It doesn't have a return value because  * it cannot fail. Regardless of what else happens, you  * should always be able to close a device (in 2.0, a 2.2 * device file could be impossible to close). */static int device_release(struct inode *inode, struct file *file){  	printk(("'/dev/eint' device release\n"));  	/* free irqs */  	free_irq(IRQ_EINT2,NULL);    	/* We're now ready for our next caller */  	Device_Open --;  //MOD_DEC_USE_COUNT; /* /home/cvtech/jx2410/linux/drivers/char/drm/drm_drv.h  */  	return 0;}/* Module Declarations *************************** *//* This structure will hold the functions to be called  * when a process does something to the device we  * created. Since a pointer to this structure is kept in  * the devices table, it can't be local to * init_module. NULL is for unimplemented functions. */struct file_operations Fops = {	.open 		= device_open,	.release 	= device_release,	};/* Initialize the module - Register the character device */static int __init eint_module_init( void ){    int ret_val;    	/* Register the character device (atleast try) */  	ret_val = register_chrdev(MAJOR_NUM, DEVICE_NAME, &Fops);  	/* Negative values signify an error */  	if (ret_val < 0) {    		printk ("%s failed with %d\n",            		"Sorry, registering the character device ",            		ret_val);    	return ret_val;  	}  	printk ("%s The major device number is %d.\n",          	"Registeration is a success",           	MAJOR_NUM);          	printk ("If you want to talk to the device driver,\n");  	printk ("you'll have to create a device file. \n");  	printk ("We suggest you use:\n");  	printk ("mknod /dev/%s c %d 0\n", DEVICE_FILE_NAME,MAJOR_NUM);  	printk ("The device file name is important, because\n");  	printk ("the ioctl program assumes that's the\n");  	printk ("file you'll use.\n");  	return 0;};/* Cleanup - unregister the appropriate file from /proc */static void __exit eint_module_cleanup(void){  	int ret;    	/* Unregister the device */  	ret = unregister_chrdev(MAJOR_NUM, DEVICE_NAME);   	/* If there's an error, report it */   	if (ret < 0)    	printk("Error in module_unregister_chrdev: %d\n", ret);};module_init(eint_module_init);module_exit(eint_module_cleanup);MODULE_LICENSE("GPL");MODULE_AUTHOR("Cvtech Co., Ltd <http://www.cvtech.com.cn>");MODULE_DESCRIPTION("EINT char driver");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -