欢迎来到天天文库
浏览记录
ID:41032804
大小:133.00 KB
页数:20页
时间:2019-08-14
《S3C2440按键中断驱动程序的设计》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、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是要申请的硬件中断号;h
2、andler是向系统登记的中断处理函数,是一个回调函数,中断发生时,系统调用这个函数,dev_id参数将被传递;irqflags是中断处理的属性,若设置SA_INTERRUPT,表明中断处理程序是快速处理程序,快速处理程序被调用时屏蔽所有中断,而慢速处理程序不屏蔽;若设置SA_SHIRQ,则多个设备共享中断;dev_id在中断共享时会用到,一般设置为这个设备的device结构本身或者NULL。free_irq()的原型为:voidfree_irq(unsignedintirq,void*dev_id);下面我就开始写驱动程序,源码如下(详解在源码后面说明):#incl
3、ude#include#include#include#include#include#include#include#include#include#include#include#include4、latform_device.h>#include#include#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,S3C24105、_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;stati6、cirqreturn_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(&but7、ton_waitq);}returnIRQ_RETVAL(IRQ_HANDLED);}staticinttq2440_irq_open(structinode*inode,structfile*file){inti;interr=0;for(i=0;i
4、latform_device.h>#include#include#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
5、_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;stati
6、cirqreturn_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(&but
7、ton_waitq);}returnIRQ_RETVAL(IRQ_HANDLED);}staticinttq2440_irq_open(structinode*inode,structfile*file){inti;interr=0;for(i=0;i
此文档下载收益归作者所有