+ -
当前位置:首页 → 问答吧 → 写了个简单的设备驱动,调试出了问题,请高手指正!!!

写了个简单的设备驱动,调试出了问题,请高手指正!!!

时间:2007-08-12

来源:互联网

调试出现如下问题:

test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `ssize_t (*)(file*, char*, unsigned int,
   loff_t*)' to `loff_t (*)(file*, long long int, int)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `ssize_t (*)(file*, const char*, unsigned
   int, loff_t*)' to `ssize_t (*)(file*, char*, unsigned int, loff_t*)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `int (*)(inode*, file*)' to `ssize_t
   (*)(file*, const char*, unsigned int, loff_t*)'
test1.C:47: sorry, not implemented: non-trivial labeled initializers
test1.C:47: invalid conversion from `int (*)(inode*, file*)' to `int (*)(file*,
   void*, int (*)(void*, const char*, int, long long int, long unsigned int,
   unsigned int))'


请各位给点解决意见,谢谢!

$ gcc -D_KERNEL_ -DMODULE -DLINUX -I/usr/src/linux-2.4.20-8/include  -c  test1.C

源代码如下:

#ifndef __KERNEL__
  #define __KERNEL__
#endif

#ifndef MODULE
  #define MODULE
#endif

#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>     // printk()
#include <linux/types.h>   // size_t
#include <asm/delay.h>
#include <asm/uaccess.h>

MODULE_LICENSE("GPL");

#define MAJOR_NUM 0 //主设备号

static int test_var = 66;

static ssize_t test_read(struct file *filp, char *buf, size_t len, loff_t *f_pos);
static ssize_t test_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos);
static int test_open(struct inode *inode, struct file *file);
static int test_release(struct inode *inode, struct file *file);
static int test_init(void);
static void  test_exit(void);

static struct file_operations test_fops ={

  owner:    THIS_MODULE,       

  read:     test_read,

  write:    test_write,

  open:     test_open,

  release:  test_release,
};


static int test_init(void)
{
  int ret=register_chrdev(MAJOR_NUM, "test", &test_fops);

if(ret)
  {
   printk("test register failure");

  }
else
  {
   printk("test register success!");
  }
return ret;
}


static void  test_exit(void)
{
  int ret=unregister_chrdev(MAJOR_NUM, "test");

if(ret)
  {
   printk("test unregister failure");
  }

else
  {
   printk("test unregister success");
  }

}


static ssize_t  test_read(struct file *filp, char *buf, size_t len, loff_t *f_pos)
{

if(copy_to_user(buf, &test_var, sizeof(int)))
  {
   return - EFAULT;
  }

return sizeof(int);

}


static ssize_t test_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos)
{

if(copy_from_user(&test_var, buf, sizeof(int)))
  {
    return - EFAULT;
  }

return sizeof(int);

}


static int test_open(struct inode *inode,struct file *file)
{
          MOD_INC_USE_COUNT;
          return 0;
}


static int test_release(struct inode *inode,struct file *file)
{
          MOD_DEC_USE_COUNT;
          return (0);
}
module_init(test_init);
module_exit(test_exit);      

作者: robin_lu   发布时间: 2007-08-12

驱动正确

编译命令或许路径有问题      

作者: AIKO_sex   发布时间: 2007-08-13

既然已经帮忙回答了   那么能给出具体详细的操作吗?谢谢!      

作者: robin_lu   发布时间: 2007-08-13

比如说2。4。20-8

看起来是redhat8

你的如果不是路径就有问题编译器如果也不是也可能有问题      

作者: AIKO_sex   发布时间: 2007-08-13

我的就是redhat9的   

我知道问题了  

把 test1.C  改为 test1.c  就OK了     

其他 没有问题  正常编译通过!!       

作者: robin_lu   发布时间: 2007-08-13

我把你的例子在我的饿REDHAT9。0上便宜出很多错误, 说delay.h 。。都找不到, 是不是我哪里没弄好啊, 请帮忙咯, 还没在LINUX上成功便宜过一个设备驱动, 郁闷中。。      

作者: yuzheng110   发布时间: 2007-08-22

在regist_chardev中,主设备好为零时表示自动获取设备号,返回值RET才是你所申请到的主设备号,你应该及时更改MAJOR的值,并且你没有使用设备文件系统来建立文件节点,设备文件节点的建立函数为devfs_register,参数有很多,其中有一个是次设备号。      

作者: tengqian   发布时间: 2007-08-22

最近在学驱动,但是苦于无处下手,希望高手能提供个GPIO的驱动共学习,谢谢,我的邮箱是[email protected]      

作者: luotuo2761   发布时间: 2007-09-17