阅读:1411回复:0
请大家帮慢看一个驱动程序的问题,读没问题,写不行,
驱动编译没有错误,初始化和read()都没有问题。
但是当我在应用程序中调用write()函数的时候,老是返回-1。应该是static int s3c2410_write(struct file * file,const char * buffer, size_t count, loff_t *ppos)根本就没有执行,狂不解!! 请教大牛们!!急死我了! #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <asm/io.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 <asm/arch/irqs.h> #include <asm/delay.h> #include <asm/arch/S3C2410.h> #include <asm/hardware.h> #define DEVICE_NAME "IIC" #define IIC_MAJOR 233 #define IICBUFSIZE 20 static DECLARE_WAIT_QUEUE_HEAD(s3c2410_wait); static char iic_Data[IICBUFSIZE]; static volatile int iic_DataCount; static int s3c2410_write(struct file * file,const char * buffer, size_t count, loff_t *ppos) { iic_DataCount=count; printk("WRITE\n"); copy_from_user(iic_Data,buffer,count); return 0; } static int s3c2410_read(struct file * file, char * buffer, size_t count, loff_t *ppos) { int i; iic_DataCount=count; printk("READ\n"); for(i=0;i<count;i++) iic_Data=i*2; copy_to_user(buffer,iic_Data,iic_DataCount); return count; } static struct file_operations s3c2410_fops = { owner: THIS_MODULE, read: s3c2410_read, write: s3c2410_write, }; static devfs_handle_t devfs_handle; static int __init s3c2410_init(void) { int ret; ret = register_chrdev(IIC_MAJOR, DEVICE_NAME, &s3c2410_fops); if (ret < 0) { printk(DEVICE_NAME " can't register major number\n"); return ret; } devfs_handle = devfs_register(NULL, DEVICE_NAME, DEVFS_FL_DEFAULT,IIC_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR,&s3c2410_fops, NULL); return 0; } static void __exit s3c2410_exit(void) { devfs_unregister(devfs_handle); unregister_chrdev(IIC_MAJOR, DEVICE_NAME); } module_init(s3c2410_init); module_exit(s3c2410_exit); |
|