+ -
当前位置:首页 → 问答吧 → led驱动编绎能不过?

led驱动编绎能不过?

时间:2010-07-28

来源:互联网

编绎器版本:arm-linux-gcc 2.9.5
内核版本:2.6.12
Make时出错如下提示,请高手指点。
  1. S3C2440_LEDS.C

  2. #include <linux/config.h>
  3. #include <linux/module.h>
  4. #include <linux/kernel.h>
  5. #include <linux/fs.h>
  6. #include <linux/init.h>
  7. #include <linux/devfs_fs_kernel.h>
  8. #include <linux/miscdevice.h>
  9. #include <linux/delay.h>
  10. #include <asm/irq.h>
  11. #include <asm/arch/regs-gpio.h>
  12. #include <asm/hardware.h>


  13. #define DEVICE_NAME        "leds"           //定义设备名
  14. #define LED_MAJOR 231                  //手动定义主设备号

  15. //定义要操作的设备,把每一个led作为结构体的一个成员
  16. static unsigned long led_table [] = {            
  17.     S3C2410_GPF3,
  18.     S3C2410_GPF4,
  19.         S3C2410_GPF5,
  20.         S3C2410_GPF6,
  21.         S3C2410_GPF7,
  22.          
  23. };

  24. //对设备进行设置,结构体的每一个成员是对对应led的设置
  25. static unsigned int led_cfg_table [] = {
  26.         S3C2410_GPF3_OUTP,
  27.         S3C2410_GPF4_OUTP,
  28.         S3C2410_GPF5_OUTP,
  29.         S3C2410_GPF6_OUTP,
  30.         S3C2410_GPF7_OUTP,
  31.          
  32. };
  33. static         struct cdev *cd=NULL;
  34. //设备驱动程序中对设备的I/O通道进行管理的函数,用来实现对led的操作
  35. static int s3c2440_leds_ioctl(
  36.         struct inode *inode,  
  37.         struct file *file,  
  38.         unsigned int cmd,  
  39.         unsigned long arg)
  40. {
  41.         switch(cmd) {
  42.         case 0:
  43.         case 1:
  44.                 if (arg > 4) {
  45.                         return -EINVAL;
  46.                 }
  47.                 s3c2410_gpio_setpin(led_table[arg], !cmd);
  48.                 return 0;
  49.         default:
  50.                 return -EINVAL;
  51.         }
  52. }
  53. static struct file_operations s3c2440_leds_fops = {
  54.         .owner        =        THIS_MODULE,
  55.         .ioctl        =        s3c2440_leds_ioctl,
  56. };

  57. //模块加载函数
  58. static int  s3c2440_leds_init(void)
  59. {
  60.         int ret;
  61.         int i;
  62.   int result;

  63.         dev_t devno = MKDEV(LED_MAJOR, 0);
  64.     //注册设备号

  65.     result = register_chrdev_region(devno, 1, DEVICE_NAME);
  66. if(result<0)
  67.   {
  68.                         printk(DEVICE_NAME " initialized fail :device num busy\n");
  69.                         return result;
  70.   }

  71.                 cd =cdev_alloc();
  72.         if(cd==NULL)
  73.         {
  74.          printk(KERN_NOTICE "CDEV_ALLOC  ERROR");
  75.                
  76. unregister_chrdev_region(MKDEV(LED_MAJOR, 0), 1);
  77.                 return -20;
  78.         }
  79.                   cdev_init(cd, &s3c2440_leds_fops);
  80.                 cd->owner = THIS_MODULE;
  81.                   cd->ops = &s3c2440_leds_fops;
  82.                  ret = cdev_add(cd, devno, 1);
  83.                   if (ret)
  84.           {       
  85.          printk(KERN_NOTICE "CDEV_ADD LED ERROR");
  86.                 kfree(cd);
  87.         unregister_chrdev_region(MKDEV(LED_MAJOR, 0), 1);
  88.                 return -10;
  89.                 }


  90.         devfs_mk_cdev(MKDEV(LED_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, DEVICE_NAME);
  91.          
  92.         for (i = 0; i < 5; i++) {
  93.                 s3c2410_gpio_cfgpin(led_table[i], led_cfg_table[i]);
  94.                 s3c2410_gpio_setpin(led_table[i], 1);
  95.         }

  96.         printk(DEVICE_NAME " initialized OK\n");
  97.         return 0;
  98. }

  99. //模块卸载函数
  100. static void  s3c2440_leds_exit(void)
  101. {
  102.         devfs_remove(DEVICE_NAME);
  103.          cdev_del(cd);
  104.          unregister_chrdev_region(MKDEV(LED_MAJOR, 0), 1);

  105. }


  106. //MODULE_AUTHOR("HeLun);
  107. MODULE_LICENSE("Dual BSD/GPL");



  108. module_init(s3c2440_leds_init);
  109. module_exit(s3c2440_leds_exit);
  110. Makefile
  111. obj-m :=s3c2440_leds.o
  112. KERNELDIR := /helun/driver/linux-2.6.12
  113. default:
  114.         make -C $(KERNELDIR) M=$(shell pwd) modules
  115. install:
  116.         insmod s3c2440_leds.ko
  117. uninstall:
  118.         rmmod s3c2440_leds.ko
  119. clean:
  120.         make -C $(KERNELDIR) M=$(shell pwd) clean

  121. 编绎出错:
  122. >make
  123. make -C /helun/driver/linux-2.6.12 M=/helun/driver/led_Helun modules
  124. make[1]: Entering directory `/helun/driver/linux-2.6.12'
  125.   CC [M]  /helun/driver/led_Helun/s3c2440_leds.o
  126. /helun/driver/led_Helun/s3c2440_leds.c: In function `s3c2440_leds_init':
  127. /helun/driver/led_Helun/s3c2440_leds.c:78: warning: implicit declaration of function `cdev_alloc'
  128. /helun/driver/led_Helun/s3c2440_leds.c:78: warning: assignment makes pointer from integer without a cast
  129. /helun/driver/led_Helun/s3c2440_leds.c:86: warning: implicit declaration of function `cdev_init'
  130. /helun/driver/led_Helun/s3c2440_leds.c:87: dereferencing pointer to incomplete type
  131. /helun/driver/led_Helun/s3c2440_leds.c:88: dereferencing pointer to incomplete type
  132. /helun/driver/led_Helun/s3c2440_leds.c:89: warning: implicit declaration of function `cdev_add'
  133. /helun/driver/led_Helun/s3c2440_leds.c: In function `s3c2440_leds_exit':
  134. /helun/driver/led_Helun/s3c2440_leds.c:114: warning: implicit declaration of function `cdev_del'
  135. make[2]: *** [/helun/driver/led_Helun/s3c2440_leds.o] 错误 1
  136. make[1]: *** [_module_/helun/driver/led_Helun] 错误 2
  137. make[1]: Leaving directory `/helun/driver/linux-2.6.12'
复制代码

作者: helun   发布时间: 2010-07-28

提示信息中有一些Warnig,解决了先。

作者: Godbach   发布时间: 2010-07-28

看样子好像是s3c2440_leds_init里面参数有误

作者: 0vk0   发布时间: 2010-07-28

热门下载

更多