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

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

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

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

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

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

S3C2440按键驱动的设计(内核2.6.30.4) 下图为S3C2440的按键连接电路图: 在开始设计程序之前介绍一下与Linux设备中断处理程序相关的知识。首先是申请与释放IRQ的APIrequest_irq()和free_irq(),request_irq()的原型为: intrequest_irq(unsignedintirq, void(*handler)(intirq,void*dev_id,structpt_regs*regs), unsignedlongirqflags, constchar*devname, void*dev_id); irq是要申请的硬件中断号; handler是向系统登记的中断处理函数,是一个回调函数,中断发生时,系统调用这个函数,dev_id参数将被传递; irqflags是中断处理的属性,若设置SA_INTERRUPT,表明中断处理程序是快速处理程序,快速处理程序被调用时屏蔽所有中断,而慢速处理程序不屏蔽;若设置SA_SHIRQ,则多个设备共享中断; dev_id在中断共享时会用到,一般设置为这个设备的device结构本身或者NULL。 free_irq()的原型为: voidfree_irq(unsignedintirq,void*dev_id); 下面我就开始写驱动程序,源码如下(详解在源码后面说明): #include<linux/module.h> #include<linux/kernel.h> #include<linux/fs.h> #include<linux/init.h> #include<linux/delay.h> #include<linux/poll.h> #include<linux/irq.h> #include<asm/irq.h> #include<linux/interrupt.h> #include<asm/uaccess.h> #include<mach/regs-gpio.h> #include<mach/hardware.h> #include<linux/platform_device.h> #include<linux/cdev.h> #include<linux/miscdevice.h> #defineDEVICE_NAME"IRQ-Test" structbutton_irq_desc{ intirq; intpin; intpin_setting; intnumber; char*name; }; staticstructbutton_irq_descbutton_irqs[]={ {IRQ_EINT1, S3C2410_GPF1, S3C2410_GPF1_EINT1, 0,"KEY1"},/*K1*/ {IRQ_EINT4, S3C2410_GPF4, S3C2410_GPF4_EINT4, 1,"KEY2"},/*K2*/ {IRQ_EINT2, S3C2410_GPF2, S3C2410_GPF2_EINT2, 2,"KEY3"},/*K3*/ {IRQ_EINT0, S3C2410_GPF0, S3C2410_GPF0_EINT0, 3,"KEY4"},/*K4*/ }; staticvolatilecharkey_values[]={'0','0','0','0'}; staticDECLARE_WAIT_QUEUE_HEAD(button_waitq); staticvolatileintev_press=0; staticirqreturn_tirq_interrupt(intirq,void*dev_id) { structbutton_irq_desc*button_irqs=(structbutton_irq_desc*)dev_id; intdown; down=!s3c2410_gpio_getpin(button_irqs->pin); if(down!=(key_values[button_irqs->number]&1)) { key_values[button_irqs->number]='0'+down; ev_press=1; wake_up_interruptible(&button_waitq); } returnIRQ_RETVAL(IRQ_HANDLED); } staticinttq2440_irq_open(structinode*inode,structfile*file) { inti; interr=0; for(i=0;i<sizeof(button_irqs)/sizeof(button_irq