- 论坛徽章:
- 0
|
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/fs.h>
- #include "khead.h"
- MODULE_LICENSE("GPL");
- static int Device_Open = 0;
- #define SUCCESS 0;
- #define CS3 0xD1000000;
- static void *cs3_mapped;
- static int global_var = 0;
- static int cs3_open(struct inode *, struct file *);
- static int cs3_close(struct inode *, struct file *);
- static int cs3_read(struct file *, char *, size_t, loff_t *);
- static int cs3_write(struct file *, const char *, size_t, loff_t *);
- static struct file_operations cs3_fops = {
- open: cs3_open,
- read: cs3_read,
- write: cs3_write,
- release: cs3_close,
- };
- static int cs3_open (struct inode *inode, struct file *file)
- {
- cs3_mapped=ioremap(CS3,8); //出错在此行
- printk("hello_open\n");
- if(Device_Open)
- return -EBUSY;
-
- Device_Open++;
- MOD_INC_USE_COUNT;
- return SUCCESS;
- }
- static int cs3_close (struct inode *inode, struct file *file)
- {
- printk("hello_close\n");
- Device_Open--;
- MOD_DEC_USE_COUNT;
- return 0;
- }
- static int cs3_read (struct file *file, char *buf, size_t count, loff_t *ppos)
- {
- printk("hello_read\n");
- return count;
- }
- static int cs3_write (struct file *file, const char *buf, size_t count, loff_t *ppos)
- {
- void *cs3_buf;
-
-
- printk("CS3: mapped address=%08lx\n", (unsigned long)cs3_mapped); /* test-only */
-
-
-
- copy_from_user(cs3_buf,buf,count);
- iowrite8_rep(cs3_mapped,cs3_buf,count);
- printk("CS3: mapped address=%08lx\n",(unsigned long)cs3_mapped); /* test-only */
- printk("hello_write: %p\n", buf);
- return count;
- }
- static int __init cs3_init (void)
- {
- int result;
-
- result = register_chrdev(0,"cs3",&cs3_fops);
- if(result<0)
- {
- printk("cs3 warning:can't get major %d\n", result);
- return -EIO;
- }
- return 0;
- }
-
-
- static void __exit cs3_exit (void)
- {
- if(unregister_chrdev(251,"cs3")!=0)
- printk("cs3 unregistered is failed \n");
- printk("cs3 module exit\n");
-
- }
- module_init(cs3_init);
- module_exit(cs3_exit);
复制代码
编译后的出错,出错在此行cs3_mapped=ioremap(CS3,; “parse erro before';'token” |
|