linuxÖеÄÖжÏ
1£ºlinuxÖÐÖжϵÄÌص㣺
LinuxÖеÄÖжϺͼĴæÆ÷Ò»Ñù¶¼ÊDz»ÔÊÐíÓû§Ö±½Ó·ÃÎʵģ¬ÔÚlinuxϵͳµ±ÖУ¬Öжϱ»ÏµÍ³ÅäÖúÃÖ®ºó£¬»áÌṩ¸øÓû§Ò»¸ö¶ÔÓÃÓÚÖжϵÄÊýÖµ£¬Õâ¸öÊýÖµ¶ÔÓ¦ÓÚÓ²¼þÖжϣ¬Óû§Ö»ÄÜͨ¹ýÕâ¸öÊýֵȥ·ÃÎÊÖжϣ¬¶ø²»ÔÊÐíÖ±½ÓÈ¥¶ÁдÆäÏ°¹ßµÄ¼Ä´æÆ÷¡£Õâ¸öÊýÖµ¾Í½Ð×öÖжϺţ¬ÊÇÒ»¸öunsigned int Ð͵ıäÁ¿¡£
LinuxÖжϵķÖÀࣺ
a. Ó²¼þÖжϣ¬ºÍM4Ò»Ñù£¬ÓÐÒì³£ÏòÁ¿±í£¬ÌṩӲ¼þÖжϡ£
b. ÈíÖжϣ¬ÈíÖжÏÊÇÄÚºËÖÐÀàËÆÓÚÏ̵߳ĽøÖÆʵÏֵġ£
ÎÒÃÇÒÔ°¸¼þÖжÏΪÀýÀ´Á˽âlinuxÖеÄÖжÏÏà¹Ø֪ʶµã
2£ºÖжϵÄÍ·Îļþ£¬º¯ÊýÏà¹Ø
1) Í·Îļþ #include <linux/interrupt.h>
2) Ïà¹Øº¯Êý
a. IRQ_EINT(x)
×÷Ó㺻ñµÃÖжϺŵĺ¯Êý,»ñµÃÍⲿÖжϱàºÅµÄºê
²ÎÊý£ºÔÚµç·ͼ»òÕßÊý¾ÝÊÖ²áPDFÖвéѯÏî¶ÔÓ¦µÄÍⲿÖжÏÓ²¼þ±àºÅ
·µ»ØÖµ£º·µ»Ø¶ÔÓ¦µÄϵͳÖжϱàºÅ(Ó²¼þÖжϺÅתϵͳÖжϺÅ)
¹ØÓÚÖжϺŵÄ֪ʶ£¬Çë²Î¿¼Êý¾ÝÊÖ²á9.2.2ÕµÄÖжÏÁбí
b. static inline int __must_check
request_irq(unsigned int irq, irq_handler_t handler,unsigned long flags,
constchar *name, void *dev)
×÷ÓãºÍ¨¹ýϵͳÖжϺŹØÁªÓû§×Ô¶¨ÒåµÄÖжϺ¯Êý²¢ÇÒ¼¤»îÖжϣ¬Ö´ÐÐÕâ¸öº¯ÊýÖ®ºó£¬ÖжϾͿÉÒÔʹÓÃÁË¡£
²ÎÊý1£ºÏµÍ³ÖжϺÅ
²ÎÊý2£ºÎÒÃÇ×Ô¼ºÊµÏÖµÄÖжϺ¯ÊýµÄº¯ÊýÃû(º¯ÊýÈë¿Ú)
²ÎÊý3£ºÖжϱêʶ£º¶¨ÒåÔÚinterrupt.hÍ·Îļþµ±ÖÐ
#define IRQF_TRIGGER_RISING 0x00000001//ÉÏÉýÑØÓÐЧ
#define IRQF_TRIGGER_FALLING 0x00000002//ϽµÑØÓÐЧ
#define IRQF_TRIGGER_HIGH 0x00000004//¸ßµçƽÓÐЧ
#define IRQF_TRIGGER_LOW 0x00000008//µÍµçƽÓÐЧ
²ÎÊý4£ºÖжϵÄ×¢²áÃû£¬Ò»°ãÌîNULL
²ÎÊý5£º´«µÝ¸øÖжϺ¯ÊýµÄ²ÎÊý£¬ÒòΪÊÇ¿ÕÖ¸Õ룬ËùÒÔ¿ÉÒÔ´«µÝÈÎÒⶫÎ÷
·µ»Ø³É¹¦£º0
·µ»Øʧ°Ü£ºÐ¡ÓÚ0
c. gpio_get_value(x) #include<linux/gpio.h>
×÷ÓãºÍ¨¹ýGPIOϵͳ±àºÅµÃµ½GPIOÒý½ÅµÄµçƽ
²ÎÊý£ºGPIOϵͳ±àºÅ
·µ»ØÖµ£ºµÍµçƽ·µ»Ø0 ¸ßµçƽ·µ»Ø1
d. EXYNOS4_GPX3(_nr) #include <linux/gpio.h>
×÷Ó㺻ñµÃGPIO¶Ë¿Úϵͳ±àºÅ
²ÎÊý£º¶ÔÓ¦µÄ¶Ë¿ÚºÅ
·µ»ØÖµ£ºGPIOϵͳ±àºÅ
e. ÖжϺ¯ÊýµÄ·µ»ØÖµ£º
˵Ã÷£º
1. ÖжϺ¯Êý·µ»ØÖµÀàÐÍÊÇirqreturn_t
2. Irqreturn_tÀàÐÍÊÇͨ¹ýö¾Ù½á¹¹enumirqreturn¶¨ÒåµÄ
3. Enum irqreturnö¾Ù½á¹¹ÓÐÈý¸ö³ÉÔ±£¬·Ö±ðÊÇ0,1, 2
4. ͨ¹ýirqreturn_t¶¨Òå·µ»ØÀàÐ͵ĺ¯Êý¿ÉÒÔĬÈÏ·µ»ØÈý¸ö½á¹û£¬·Ö±ðÊÇ0,1,2
ÕâÑù¶¨ÒåÊÇΪÁËʲô£¿
IRQ_NONE·µ»ØÖµÔÚÖжϵ±ÖÐûÓÐÖ´Ðж¯×÷µÄʱºò·µ»Ø
IRQ_HANDLED ·µ»ØÖµÔÚÖжϳɹ¦Ö´Ðж¯×÷Ö®ºó·µ»Ø
IRQ_WAKE_THREAD Èç¹ûÖжÏÊÇÔÚÏ̵߳±Öе÷Ó㬾ͷµ»ØÕâ¸ö
f. ÖжϺ¯ÊýµÄÀàÐͶ¨Òå
typedef irqreturn_t (*irq_handler_t)(int, void *)
˵Ã÷£º¶¨Ò庯ÊýÔÐÍʹÓõÄÒ»ÖÖ·½Ê½£¬ÕâÑù¶¨ÒåÁËÖ®ºó£¬¾Íʺ¯ÊýµÄÔÐÍÃûirq_handler_t±ä³ÉÁËÒ»¸öÀàÐÍ£¬ÓÃÕâ¸öÀàÐÍÈ¥¶¨ÒåÒ»¸ö±äÁ¿£¬Õâ¸ö±äÁ¿¾ÍÊÇÒ»¸öº¯Êý£¬¶øÇҺʹζ¨ÒåµÄº¯ÊýÔÐÍÒÆÖ²£¬±ÈÈ磺
Irq_handler_t KEYIRQ_Handler£¬ÄÇôÎÒÃǾ͵õ½ÁËÕâÑùµÄÒ»¸öº¯Êý£º
Irqreturn_tKEYIRQ_Hanlder(int arg, void *devID)
26-3£ºÖжϺ¯ÊýµÄ±àд
Çë²Î¿¼ÊÓƵÓë´úÂë
26-4£ºÖжϵĶ¥²¿Óëµ×²¿
ÔÚÖжϵÄÖ´Ðйý³ÌÖУ¬ÖжϺ¯Êý±¾Éí¾ÍÊÇÖж϶¥²¿£¬ÔÚÖж϶¥²¿¿ªÆôÖжϵײ¿µÄ¿ª¹Ø£¬Öжϵײ¿¾Í¿ÉÒÔÂíÉÏÖ´ÐУ¬ÒòΪÖжϺ¯ÊýÓ¦¸Ã¾¡Á¿¶Ì£¬²¢ÇÒ²»Äܹ»ÓÐÐÝÃߣ¬ËùÒÔ¿ÉÒÔ½«½Ï¸´ÔÓ£¬ÒªÓõ½ÐÝÃߣ¬ºÄʱ½Ï³¤µÄ¹¦ÄÜÈ«²¿Òƶ¯µ½Öն˵ײ¿È¥ÊµÏÖ¡£
Öжϵײ¿µÄʵÏÖÔÚLINUXÖÐÓÐÈýÖÖ·½Ê½£º
a. Äں˶¨Ê±Æ÷£ºÄں˶¨Ê±Æ÷±¾ÉíÒ²ÊÇͨ¹ýÈíÖжϵÄÐÎʽÀ´ÊµÏֵģ¬Ö»²»¹ýÔÚÈíÖжϵ±Öаó¶¨ÁËÒ»¸ö¼ÆʱµÄ»úÖÆ¡£±¾ÖÊÉÏÒ²ÊÇÈíÖжϣ¬ÒòΪҲÊÇÖжϣ¬ËùÒÔÔÚÄںͶ¨Ê±Æ÷µÄº¯Êýµ±Öв»Äܹ»Ê¹ÓÃÐÝÃß
b. ÈÎÎñ(ÈíÖжÏ)£ºÒòΪÊÇÈíÖжϣ¬¿ÉÒÔ×öºÜ¶àÊÂÇ鵫ÊDz»ÄÜÐÝÃß
c. ¹¤×÷¶ÓÁУººÍÄں˶¨Ê±Æ÷»¹ÓÐÈÎÎñ²»Í¬£¬²»ÊÇͨ¹ýÈíÖжϵÄÐÎʽʵÏֵģ¬Çø±ðÔÚÓÚ±ÈÆðÈíÖжϣ¬¿ÉÄܵ÷ÓõÄʱºò»¨µÄʱ¼ä¸ü³¤£¬µ«ÊÇ¿ÉÒÔÔÚÆäÄÚ²¿Ê¹ÓÃÐÝÃß