中断
申请中断
int request_irq(unsigned int irq, irq_handler_t handler,unsigned long irqflags, const char *devname, void *dev_id)
irq为中断号,在与board相关的头文件中定义,2440在Irqs.h include\asm-arm\arch-s3c2410\Irqs.h 中
handler为中断处理函数
irqflags为触发方式,在Irq.h里面定义
devname为名字
dev_id卸载时才用到,只要与free_irq中的dev_id相同即可,写为NULL也行
看一下irqflags
/*
* These correspond to the IORESOURCE_IRQ_* defines in
* linux/ioport.h to select the interrupt line behaviour. When
* requesting an interrupt without specifying a IRQF_TRIGGER, the
* setting should be assumed to be "as already configured", which
* may be as per machine or firmware initialisation.
*/
#define IRQF_TRIGGER_NONE 0x00000000<span style="white-space:pre"> /*无触发中断*/</span>
#define IRQF_TRIGGER_RISING 0x00000001<span style="white-space:pre"> /*指定中断触发类型:上升沿有效*/</span>
#define IRQF_TRIGGER_FALLING 0x00000002<span style="white-space:pre"> /*</span><span style="font-family: Arial, Helvetica, sans-serif;">指定</span><span style="white-space:pre">中断触发类型:下降沿有效*/</span>
#define IRQF_TRIGGER_HIGH 0x00000004<span style="white-space:pre"> /*指定中断触发类型:高电平有效*/</span>
#define IRQF_TRIGGER_LOW 0x00000008<span style="white-space:pre"> /*指定中断触发类型:低电平有效*/</span>
#define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
#define IRQF_TRIGGER_PROBE 0x00000010<span style="white-space:pre"> /*触发式检测中断*/</span>
/*
* These flags used only by the kernel as part of the
* irq handling routines.
*
* IRQF_DISABLED - keep irqs disabled when calling the action handler
* 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)
*/
#define IRQF_DISABLED 0x00000020<span style="white-space:pre"> /*中断禁止*/</span>
#define IRQF_SAMPLE_RANDOM 0x00000040<span style="white-space:pre"> /*供系统产生随机数使用*/</span>
#define IRQF_SHARED 0x00000080<span style="white-space:pre"> /*在设备之间可共享*/</span>
#define IRQF_PROBE_SHARED 0x00000100<span style="white-space:pre"> /*探测共享中断*/</span>
#define IRQF_TIMER 0x00000200<span style="white-space:pre"> /*专用于时钟中断*/</span>
#define IRQF_PERCPU 0x00000400<span style="white-space:pre"> /*每CPU周期执行中断*/</span>
#define IRQF_NOBALANCING 0x00000800<span style="white-space:pre"> /*复位中断*/</span>
#define IRQF_IRQPOLL 0x00001000<span style="white-space:pre"> /*共享中断中根据注册时间判断*/</span>
卸载中断
free_irq(unsigned int irq,void *dev_id)
定时器
设置定时器
分配一个定时器结构
static struct timer_list buttons_timer;
初始化定时器
init_timer(&buttons_timer);
设置处理函数
buttons_timer.function = buttons_timer_function;
将结构体加入链表
add_timer(&buttons_timer);
启动定时器
mod_timer(&buttons_timer, jiffies+HZ/100);
删除定时器
del_timer(&buttons_timer);