3107|0

9

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

button(中断)驱动程序中 错误原因! [复制链接]

/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");
此帖出自ARM技术论坛
点赞 关注
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表