[讨论] button(中断)驱动程序中 错误原因!

huyixin11100   2012-12-28 14:33 楼主
/home/wq/linux_drv/int_key/int_key_drv.c:69: warning: initialization from incompatible pointer type
/home/wq/linux_drv/int_key/int_key_drv.c:72:25: error: macro "key_init" passed 1 arguments, but takes just 0
/home/wq/linux_drv/int_key/int_key_drv.c:73: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
/home/wq/linux_drv/int_key/int_key_drv.c: In function 'key_exit':
/home/wq/linux_drv/int_key/int_key_drv.c:84: warning: passing argument 1 of 'device_destroy' from incompatible pointer type
/home/wq/linux_drv/int_key/int_key_drv.c: In function '__inittest':
/home/wq/linux_drv/int_key/int_key_drv.c:88: error: 'key_init' undeclared (first use in this function)
/home/wq/linux_drv/int_key/int_key_drv.c:88: error: (Each undeclared identifier is reported only once
/home/wq/linux_drv/int_key/int_key_drv.c:88: error: for each function it appears in.)
make[2]: *** [/home/wq/linux_drv/int_key/int_key_drv.o] Error 1
make[1]: *** [_module_/home/wq/linux_drv/int_key] Error 2
make[1]: Leaving directory `/home/wq/linux-2.6.31'
make: *** [all] Error 2

内核2.6.31
交叉编译工具4.1.2
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#include
#include
#include
int major;
static unsigned long *GPFCON = NULL;
static unsigned long *GPFDAT = NULL;
static struct class *key_class;
static struct class_device *key_class_dev;
static irqreturn_t Button_irq(int irq, void *dev_i)
{
printk("<4> KEY=%d\n",irq);
return 0;
}
static int key_open(struct inode *inode,struct file *file)
{
/*将GPF0123设置为输出引脚;GPF4567设置为输入引脚*/
//*GPFCON &=~((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7));
//*GPFCON |=((1<<0)|(1<<1)|(1<<2)|(1<<3));

//将引脚设置为中断引脚;
request_irq(IRQ_EINT4,Button_irq,IRQ_TYPE_EDGE_BOTH,"s1",1);
request_irq(IRQ_EINT5,Button_irq,IRQ_TYPE_EDGE_BOTH,"s2",1);
request_irq(IRQ_EINT6,Button_irq,IRQ_TYPE_EDGE_BOTH,"s3",1);
request_irq(IRQ_EINT7,Button_irq,IRQ_TYPE_EDGE_BOTH,"s4",1);

return 0;
}
static int key_read(struct file * file,char __user *buff,size_t count,loff_t *offp)
{
//返回4个电平
unsigned char keyval[4];
int retval;
if(count!=sizeof(keyval))
  return -EINVAL;
//读GPF4567
retval  = *GPFDAT;
keyval[0] = (retval&(1<<4))?1:0;
keyval[1] = (retval&(1<<5))?1:0;
keyval[2] = (retval&(1<<6))?1:0;
keyval[3] = (retval&(1<<7))?1:0;

copy_to_user(buff,keyval,sizeof(keyval));
return (sizeof(keyval));
}
static ssize_t key_write(struct file *file,char __user *buff,size_t count,loff_t *ppos)
{
return 0;
}
static struct file_operations key_fops={
.owner = THIS_MODULE,
.open = key_open,
.read = key_read,
.write = key_write,
};
static int key_init(void)
{
major = register_chrdev(0,"key_drv",&key_fops);
key_class = class_create(THIS_MODULE,"key_drv");
key_class_dev = device_create(key_class,NULL,MKDEV(major,0),NULL,"key");
GPFCON = ioremap(0x56000050,4);
GPFDAT = GPFCON +1;
return 0;
}
static void key_exit(void)
{
unregister_chrdev(major,"key_drv");
device_destroy(key_class_dev,MKDEV(major,0));
class_destroy(key_class);
iounmap(GPFCON);
}
module_init(key_init);
module_exit(key_exit);
MODULE_LICENSE("GPL");

回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复