注册中断服务函数
中断注册是使用了<linux/interrupt.h>的"requset_irq"函数:
extern int __must_check
request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
            const char *name, void *dev);

 

变量 作用
irq 申请的硬件中断号
handler 向系统注册的中断处理函数,是一个回调函数,中断发生时,系统调用这个函数,dev_id参数将被传递给它
*name 中断名称,在/proc/interrupts中可以看到此名称
*dev 在中断共享时会用到,让handler知道是处理哪个中断,也可以用来指定中断服务函数需要参考的数据地址,一般设置为这个设备的设备结构体或者NULL
flags 中断处理的属性,详细参数在中说明.详细看代码1

/*
/*
 * These flags used only by the kernel as part of the
 * irq handling routines.
 *
 * IRQF_DISABLED - keep irqs disabled when calling the action handler.
 *                 DEPRECATED. This flag is a NOOP and scheduled to be removed
 * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator
 * IRQF_SHARED - allow sharing the irq among several devices
 * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
 * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
 * IRQF_PERCPU - Interrupt is per cpu
 * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
 * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
 *                registered first in an shared interrupt is considered for
 *                performance reasons)
 * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished.
 *                Used by threaded interrupts which need to keep the
 *                irq line disabled until the threaded handler has been run.
 * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend
 * IRQF_FORCE_RESUME - Force enable it on resume even if IRQF_NO_SUSPEND is set
 * IRQF_NO_THREAD - Interrupt cannot be threaded
 */
#define IRQF_DISABLED        0x00000020
#define IRQF_SAMPLE_RANDOM    0x00000040
#define IRQF_SHARED        0x00000080
#define IRQF_PROBE_SHARED    0x00000100
#define __IRQF_TIMER        0x00000200
#define IRQF_PERCPU        0x00000400
#define IRQF_NOBALANCING    0x00000800
#define IRQF_IRQPOLL        0x00001000
#define IRQF_ONESHOT        0x00002000
#define IRQF_NO_SUSPEND        0x00004000
#define IRQF_FORCE_RESUME    0x00008000
#define IRQF_NO_THREAD        0x00010000

#define IRQF_TIMER        (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)



关闭中断服务函数
extern void disable_irq(unsigned int irq);

 

变量 作用
irq 需要屏蔽的硬件中断号



使能中断服务函数
extern void enable_irq(unsigned int irq);

 

变量 作用
irq 需要使能硬件中断号



释放中断服务函数
void free_irq (unsigned int irq, void *dev_id);

 

变量 作用
irq 将要注销掉的中断服务函数的中断号;
dev_id 值指定与"request_irq()"函数中使用的"dev_id"值相同的值



中断处理例程的返回值说明

中断处理例程应当返回一个值指示是否真正处理了一个中断.如果处理例程发现设备确实需要处理,应当返回"IRQ_HANDLED"; 否则返回值"IRQ_NONE".
下面是<linux/irqreturn.h>文件的内容,更为详细的说明.
#ifndef _LINUX_IRQRETURN_H
#define _LINUX_IRQRETURN_H

/**
 * enum irqreturn
 * @IRQ_NONE        interrupt was not from this device
 * @IRQ_HANDLED        interrupt was handled by this device
 * @IRQ_WAKE_THREAD    handler requests to wake the handler thread
 */
enum irqreturn {
    IRQ_NONE,
    IRQ_HANDLED,
    IRQ_WAKE_THREAD,
};

typedef enum irqreturn irqreturn_t;
#define IRQ_RETVAL(x)    ((x) != IRQ_NONE)

#endif