预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共13页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

中断方式按键驱动 实验器材:ok6410开发板 RedHat5.0 实验目的:利用中断方式来测试按键驱动 实验原理: 从上图可以得出: <1>当按键没有按下时,为高电平;当按下时,为低电平 <2>S[2-7]按键分别对应的是外部中断XEINT[0-5] 驱动程序: #include<plat/regs-gpio.h> #include<plat/gpio-bank-n.h> #include<linux/device.h> #include<linux/kernel.h> #include<linux/module.h> #include<linux/init.h> #include<linux/fs.h> #include<linux/errno.h> #include<linux/poll.h> #include<linux/interrupt.h> #include<linux/irq.h> #include<asm/irq.h> #include<asm/io.h> #include<mach/hardware.h> #include<linux/miscdevice.h> #defineGPNCON0x7F008830 #defineGPNDAT0x7F008834 volatileunsignedlong*s3c6410_GPNCON; volatileunsignedlong*s3c6410_GPNDAT; staticstructclass*mysecond_key_class; staticstructdevice*mysecond_key_class_dev; staticDECLARE_WAIT_QUEUE_HEAD(key_waitq);//定义一个等待队列头 /*中断事件标志,中断服务程序将它置1,read函数将它置0 */ staticvolatileintev_press=0; /*键值:按下时,0x01,0x02,0x03,0x04,0x05,0x06*/ /*键值:松开时,0x81,0x82,0x83,0x84,0x85,0x86*/ staticunsignedintkeyvals; structmysecond_key { unsignedintirq_no;//中断号 unsignedintkey_val;//键值 unsignedintnum;//按键数 char*name;//按键名字 }; staticstructmysecond_keysecond_keys[6]= { {IRQ_EINT(0),0x01,0,"KEY1"}, {IRQ_EINT(1),0x02,1,"KEY2"}, {IRQ_EINT(2),0x03,2,"KEY3"}, {IRQ_EINT(3),0x04,3,"KEY4"}, {IRQ_EINT(4),0x05,4,"KEY5"}, {IRQ_EINT(5),0x06,5,"KEY6"}, }; staticirqreturn_tmykey_handle(intirq,void*dev_id) { intnum; unsignedinttmp; unsignedintpinval; structmysecond_key*pindesc=(structmysecond_key*)dev_id; num=pindesc->num; tmp=readl(S3C64XX_GPNDAT);//读出GPNDAT的值 pinval=(tmp&(1<<num)); if(pinval)//松开 { keyvals=pindesc->key_val|0x80; } else//按下 { keyvals=pindesc->key_val; } ev_press=1;//将按键标识符置1 wake_up_interruptible(&key_waitq);//唤醒睡眠 returnIRQ_RETVAL(IRQ_HANDLED); } staticintmysecond_key_open(structinode*inode,structfile*file) { /*配置GPN[0-5]为中断引脚*/ inti=0; interr; for(i=0;i<sizeof(second_keys)/sizeof(second_keys[0]);i++) { err=request_irq(second_keys[i].irq_no,mykey_handle,IRQ_TYPE_EDGE_BOTH, second_k