03day01irq

 1 #include <linux/module.h>
 2 #include <linux/init.h>
 3 #include <linux/kernel.h>
 4 
 5 #include <linux/interrupt.h> //request_irq   注册中断
 6 #include <mach/irqs.h> 
 7 /*
 8 对于中断号,它是和芯片相关,  头文件是在linux-3.5/arch/arm/mach-exynos/include/mach   中
 9 该头文件又包含了  plat/irqs.h   该文件中有IRQ_EINT()   可以算出外部中断号
10 */
11 
12 /*
13 按键产生中断
14 /sysfs  /proc   这两个目录都是虚拟文件系统,这种文件系统存在内存中
15 在/proc/interrupts  文件可以查看   中断的注册信息 
16 */
17 //中断处理函数  irqno  中断号,   data
18 irqreturn_t key_hankler(int  irqno, void * data)
19 {
20     printk("hello world
");
21     printk("data = %d
", (int)data);
22 
23     return  IRQ_HANDLED;
24 }
25 
26 
27 static int test_init(void)
28 {
29     int  ret = 0;
30     printk("%s:%d
", __FILE__, __LINE__);
31 
32     //注册  按键中断
33     //XEINT26  ~29 
34 /*
35 static inline int __must_check
36 request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
37         const char *name, void *dev)
38 
39 irq   中断号   4412 平台   
40 #define IRQ_EINT(x)   
41 IRQ_EINT(26)
42 
43 typedef irqreturn_t (*irq_handler_t)(int, void *);
44 中断 服务函数
45 
46 flags  中断的标志  中断触发的形式  IRQF_TRIGGER_FALLING
47 
48 name  名称  注册成功之后,可以在/proc/interrupts  看到
49 
50 dev   向中断服务函数,传递的参数,如果不需要传递,可以赋值为NULL
51 
52 */
53     ret = request_irq(IRQ_EINT(26), key_hankler, IRQF_TRIGGER_FALLING, 
54         "candle_test",   (void *)123);
55     if(ret < 0) {
56         printk("request_irq  failed
");
57         goto  err_request_irq;
58     }
59 
60 
61     return 0;
62 err_request_irq:
63     return -1;
64 }
65 
66 
67 static void test_exit(void)
68 {
69     printk("%s:%d
", __FILE__, __LINE__);
70     //释放中断号
71     free_irq(IRQ_EINT(26), (void *)123);
72 }
73 
74 
75 module_init(test_init);
76 module_exit(test_exit);
77 
78 MODULE_LICENSE("GPL");
原文地址:https://www.cnblogs.com/baoshulin/p/6416176.html