免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2490 | 回复: 6
打印 上一主题 下一主题

大家来看看这个错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-23 13:52 |只看该作者 |倒序浏览

  1. #include <linux/module.h>
  2. #include <linux/init.h>
  3. #include <linux/fs.h>
  4. #include "khead.h"
  5. MODULE_LICENSE("GPL");

  6. static int Device_Open = 0;
  7. #define SUCCESS 0;
  8. #define CS3 0xD1000000;
  9. static void *cs3_mapped;
  10. static int global_var = 0;


  11. static int cs3_open(struct inode *, struct file *);
  12. static int cs3_close(struct inode *, struct file *);
  13. static int cs3_read(struct file *, char *, size_t, loff_t *);
  14. static int cs3_write(struct file *, const char *, size_t, loff_t *);

  15. static struct file_operations cs3_fops = {
  16.         open:       cs3_open,
  17.         read:                cs3_read,
  18.         write:      cs3_write,
  19.         release:    cs3_close,
  20. };

  21. static int cs3_open (struct inode *inode, struct file *file)
  22. {
  23.          cs3_mapped=ioremap(CS3,8); //出错在此行       
  24.           printk("hello_open\n");
  25.     if(Device_Open)
  26.             return -EBUSY;
  27.        
  28.         Device_Open++;
  29.         MOD_INC_USE_COUNT;
  30.         return SUCCESS;
  31. }
  32. static int cs3_close (struct inode *inode, struct file *file)
  33. {
  34.         printk("hello_close\n");
  35.     Device_Open--;
  36.         MOD_DEC_USE_COUNT;       
  37.         return 0;
  38. }
  39. static int cs3_read (struct file *file, char *buf, size_t count, loff_t *ppos)
  40. {
  41.         printk("hello_read\n");
  42.         return count;
  43. }

  44. static int cs3_write (struct file *file, const char *buf, size_t count, loff_t *ppos)
  45. {  
  46.    void *cs3_buf;
  47.    
  48.   
  49.         printk("CS3: mapped address=%08lx\n", (unsigned long)cs3_mapped);      /* test-only */
  50.   
  51.      
  52.    
  53.     copy_from_user(cs3_buf,buf,count);
  54.     iowrite8_rep(cs3_mapped,cs3_buf,count);
  55.         printk("CS3: mapped address=%08lx\n",(unsigned long)cs3_mapped);      /* test-only */
  56.         printk("hello_write: %p\n", buf);

  57.         return count;       
  58. }


  59. static int __init cs3_init (void)
  60. {
  61.   int result;

  62.   result = register_chrdev(0,"cs3",&cs3_fops);
  63.   if(result<0)
  64.                 {
  65.   printk("cs3 warning:can't get major %d\n", result);
  66.   return -EIO;
  67.            }
  68. return 0;
  69. }           
  70.            
  71.            
  72. static void __exit cs3_exit (void)
  73. {
  74.   if(unregister_chrdev(251,"cs3")!=0)
  75.           printk("cs3 unregistered is failed \n");
  76.             printk("cs3 module exit\n");
  77.                  

  78. }
  79. module_init(cs3_init);
  80. module_exit(cs3_exit);
复制代码

编译后的出错,出错在此行cs3_mapped=ioremap(CS3,; “parse erro before';'token”

论坛徽章:
0
2 [报告]
发表于 2008-04-23 17:22 |只看该作者
#define SUCCESS 0;
#define CS3 0xD1000000;

两行都去掉最后的 ; 符号

论坛徽章:
0
3 [报告]
发表于 2008-04-23 20:14 |只看该作者

回复 #2 scutan 的帖子

呵呵,';'的问题是解决了。谢谢哦!
可是我把头文件一改原来的,<linux/io.h>改为,<asm/io.h>又出现了这个问题,undefined reference to 'printk'和'register_chrdev'

[ 本帖最后由 momojuan 于 2008-4-23 20:49 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2008-04-23 20:59 |只看该作者

回复 #3 momojuan 的帖子

内核开发和应用程序开发都需要特定的头文件啊.

论坛徽章:
0
5 [报告]
发表于 2008-04-23 22:27 |只看该作者

回复 #4 scutan 的帖子

头文件我都有添加,
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/config.h>
#include <linux/string.h>
#include <linux/errno.h>

论坛徽章:
0
6 [报告]
发表于 2008-04-25 23:07 |只看该作者
确认你的linux-header已经正确安装。

论坛徽章:
0
7 [报告]
发表于 2008-05-01 10:45 |只看该作者
大哥,你的编程习惯也太不好了吧。
#define SUCCESS 0;
#define CS3 0xD1000000;
这两句后面是不要分号的了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP