天嵌 ARM开发社区

 找回密码
 注册
查看: 1879|回复: 4

今天写LED驱动,总是出现两个警告,帮忙看看

[复制链接]
wang12zhedi 发表于 2012-9-11 21:55:18 | 显示全部楼层 |阅读模式
驱动源码:
#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>


#define DEVICE_NAME "LEDS"
int HELLO_MAJOR;

//使用mdev机制自动创建设备节点
static struct class *myfrist_hello_class;
static struct class_devicd *myfrist_hello_class_devs;



/* 用来指定LED所用的GPIO引脚 */
static unsigned long gpio_table [] =
{
        S3C2410_GPB5,
        S3C2410_GPB6,
        S3C2410_GPB7,
        S3C2410_GPB8,
};

/* 用来指定GPIO引脚的功能:输出 */
static unsigned int gpio_cfg_table [] =
{
        S3C2410_GPB5_OUTP,
        S3C2410_GPB6_OUTP,
        S3C2410_GPB7_OUTP,
        S3C2410_GPB8_OUTP,
};

static int LEDSgpio_ioctl(
        struct inode *inode,
        struct file *file,
        unsigned int cmd,
        unsigned long arg)
{
        int i;
        if (arg > 5)
        {
                return -EINVAL;
        }

        switch(arg)
        {
                case 0:
                  for(i=0;i<4;i++)
                     s3c2410_gpio_setpin(gpio_table[i],cmd);
                     if(cmd == 1)
                       printk("LED1~LED4  on\n");
                     else
                              printk("LED1~LED4  off\n");
                   return 0;
                     
                case 1:
                        {
                                        // 设置指定引脚的输出电平为0
                                s3c2410_gpio_setpin(gpio_table[arg-1], cmd);
                                printk("cmd=%d\n",cmd);
                                 if(cmd==1)
                                  printk("LED1  off\n");
                                else
                                  printk("LED1  on\n");
              return 0;
      }
                case 2:
                  {
                                // 设置指定引脚的输出电平为1
                                s3c2410_gpio_setpin(gpio_table[arg-1], cmd);
                                printk("cmd=%d\n",cmd);
                                 if(cmd==1)
                                  printk("LED2  off\n");
                                else
                                  printk("LED2  on\n");                       
                                 
                                return 0;
     }
                case 3:
                        {
                                // 设置指定引脚的输出电平为1
                                s3c2410_gpio_setpin(gpio_table[arg-1], cmd);
                                if(cmd==1)
                                  printk("LED3  off\n");
                                else
                                  printk("LED3  on\n");
                                return 0;
                        }
                case 4:
                        {
                                // 设置指定引脚的输出电平为1
                                s3c2410_gpio_setpin(gpio_table[arg-1], cmd);
                                 if(cmd==1)
                                  printk("LED4  off\n");
                                else
                                  printk("LED4  on\n");
                                return 0;
                        }
                case 5:
                  for(i=0;i<4;i++)
                     s3c2410_gpio_setpin(gpio_table[i],1);
                     printk("LED1~LED4  off\n");
                     return 0;
                default:
                        return -EINVAL;
        }
}


/* 这个结构是字符设备驱动程序的核心
* 当应用程序操作设备文件时所调用的open、read、write等函数,
* 最终会调用这个结构中指定的对应函数
*/
static struct file_operations myfrist_dev_fops={
        .owner = THIS_MODULE,    /* 这是一个宏,推向编译模块时自动创建的__this_module变量 */
       
        .ioctl = LEDSgpio_ioctl
};

static int __init LEDS_init(void)
{
  int i;
   HELLO_MAJOR = register_chrdev(0,DEVICE_NAME,&myfrist_dev_fops );//注册程序
  //自动创建设备节点
         
        for (i = 0; i < 4; i++)
        {
                s3c2410_gpio_cfgpin(gpio_table[i], gpio_cfg_table[i]);
                s3c2410_gpio_setpin(gpio_table[i], 0);
        }

     myfrist_hello_class = class_create(THIS_MODULE,"myfrist_hello");
     
     myfrist_hello_class_devs = device_create(myfrist_hello_class,NULL,MKDEV(HELLO_MAJOR,0),NULL,"LEDS");
   

   if(HELLO_MAJOR < 0)
   {
     printk(DEVICE_NAME "canot register major number");
     return HELLO_MAJOR;
   }
   printk("1--LED on\n");
   printk("0--LED off\n");
   printk(DEVICE_NAME"init yes \n");
   return 0;
}

static void __exit LEDS_exit(void)
{
  unregister_chrdev(HELLO_MAJOR,DEVICE_NAME);  //注销程序
  //注销设备节点
  device_unregister(myfrist_hello_class_devs);
  class_destroy(myfrist_hello_class);
  printk(DEVICE_NAME"go back\n");

  
}


module_init(LEDS_init);
module_exit(LEDS_exit);

MODULE_LICENSE("GPL");



编译之后如下
make[1]: Leaving directory `/home/a123/lx/linux-2.6.30.4'
rm -rf modules.order
root@a123-virtual-machine:/mnt/hgfs/Ub/LEDS# make
make -C /home/a123/lx/linux-2.6.30.4 M=`pwd` modules
make[1]: Entering directory `/home/a123/lx/linux-2.6.30.4'
  CC [M]  /mnt/hgfs/Ub/LEDS/leds.o
/mnt/hgfs/Ub/LEDS/leds.c: In function 'LEDS_init':
/mnt/hgfs/Ub/LEDS/leds.c:144: warning: assignment from incompatible pointer type
/mnt/hgfs/Ub/LEDS/leds.c: In function 'LEDS_exit':
/mnt/hgfs/Ub/LEDS/leds.c:162: warning: passing argument 1 of 'device_unregister' from

incompatible pointer type
  Building modules, stage 2.
make[2]: Warning: File `/mnt/hgfs/Ub/LEDS/leds.o' has modification time 1.1 s in the future
  MODPOST 1 modules
  CC      /mnt/hgfs/Ub/LEDS/leds.mod.o
  LD [M]  /mnt/hgfs/Ub/LEDS/leds.ko
make[2]: warning:  Clock skew detected.  Your build may be incomplete.
make[1]: Leaving directory `/home/a123/lx/linux-2.6.30.4'
root@a123-virtual-machine:/mnt/hgfs/Ub/LEDS#


其中144行内容为
myfrist_hello_class_devs = device_create(myfrist_hello_class,NULL,MKDEV(HELLO_MAJOR,0),NULL,"LEDS");
162行内容为
device_unregister(myfrist_hello_class_devs);


虽然也能正常的运行实现想要的功能,但有警告心里总是不踏实,求助
embedsky_lhh 发表于 2012-9-12 09:42:34 | 显示全部楼层
这是说你传进去的指针类型与定义的类型不一样,你可以将NULL强制转换下就没警告了,原型是extern struct device *device_create(struct class *cls, struct device *parent,
                                    dev_t devt, void *drvdata,
                                    const char *fmt, ...)
 楼主| wang12zhedi 发表于 2012-9-12 10:18:24 | 显示全部楼层
怎么转换呀,我才学不久,请再次指点
 楼主| wang12zhedi 发表于 2012-9-15 13:28:03 | 显示全部楼层
embedsky_lhh 发表于 2012-9-12 09:42
这是说你传进去的指针类型与定义的类型不一样,你可以将NULL强制转换下就没警告了,原型是extern struct de ...

怎么转换呀,我才学不久,请再次指点
embedsky_lhh 发表于 2012-9-17 17:38:13 | 显示全部楼层
(struct device *)NULL,你那警告可以不与理会也行的,不影响现象,但影响代码的质量
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-7-1 18:32 , Processed in 1.062500 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表