资源描述:
《poll机制按键驱动》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、Poll机制按键驱动实验器材:ok6410开发板RedHat5.0实验目的:利用poll机制来测试按键驱动实验原理:从上图可以得出:<1>当按键没有按下时,为高电平;当按下时,为低电平<2>S[2-7]按键分别对应的是外部中断XEINT[0-5]驱动程序:#include#include#include#include#include#include#include#in
2、clude#include#include#include#include#include#include#include#defineGPNCON0x7F008830#defineGPNDAT0x7F008834volatileunsignedlong*s3c6410_GPNCON;volatileunsignedlong*s3c6410_GPNDAT;s
3、taticstructclass*mythird_key_class;staticstructdevice*mythird_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;stru
4、ctmythird_key{unsignedintirq_no;unsignedintkey_val;unsignedintnum;char*name;};staticstructmythird_keythird_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"},};staticirqretu
5、rn_tmykey_handle(intirq,void*dev_id){intnum;unsignedinttmp;unsignedintpinval;structmythird_key*pindesc=(structmythird_key*)dev_id;num=pindesc->num;tmp=readl(S3C64XX_GPNDAT);pinval=(tmp&(1<key_val
6、0x80;}else//按下{keyvals=pindesc->key_val;}ev_press=1;wake_up_inte
7、rruptible(&key_waitq);returnIRQ_RETVAL(IRQ_HANDLED);}staticintmythird_key_open(structinode*inode,structfile*file){/*配置GPN[0-5]为中断引脚*/inti=0;interr;for(i=0;i8、third_keys[i]);}return0;}staticintmythird_key_close(structinode*inode,structfile*file){inti=0;for(i=0;i