中断
static irqreturn_t irq_isr(int irq, void *dev_id)
{
printk(KERN_ALERT"HAVE COMT INTERRUPT ISR ->->->->->/n/n");
return 1;
}
/* request irq */
static int request_irqs(void)
{
int ret;
if((ret = request_irq(IRQ_EINT8, irq_isr,IRQ_TYPE_EDGE_RISING, "sharp-test-irq", name)) != 0) //??????
{
printk(KERN_ALERT"Register Error 1 /n/n ");
return -ret;
}
return 0;
}
static int __init sharp_style_init(void)
{
request_irqs();
return 0;
}
static void __exit sharp_style_exit(void)
{
free_irq(IRQ_EINT8, name);
}
module_init(sharp_style_init);
module_exit(sharp_style_exit);
MODULE_LICENSE("GPL");
申请中断与释放中断时的id一定要一致!
内核定时器
static struct timer_list my_timer; 开辟内存
static irqreturn_t irq_isr(int irq, void *dev_id)
{
printk(KERN_ALERT"HAVE COMT INTERRUPT ISR ->->->->->/n/n");
return 1;
}
/* request irq */
static int request_irqs(void)
{
int ret;
if((ret = request_irq(IRQ_EINT8, irq_isr,IRQ_TYPE_EDGE_RISING, "IRQ_TEST!", NULL)) != 0) //??????
{
printk(KERN_ALERT"Register Error 1 /n/n ");
return -ret;
}
return 0;
}
static void timer_isr(unsigned long data)
{
printk("This is timer_ISR, data_parameter = %d/n", data++);
/*
my_timer.expires = jiffies + 3*HZ;
my_timer.data = data;
add_timer(&my_timer);
*/
my_timer.data = data;
mod_timer(&my_timer, jiffies + 3*HZ);
两种方式一致
}
static int __init sharp_style_init(void)
{
request_irqs();
printk("jiffies = %d, HZ = %d /n", jiffies, HZ);
init_timer(&my_timer);
my_timer.expires = jiffies + 3*HZ;
my_timer.function = timer_isr;
my_timer.data = 1009909;
add_timer(&my_timer);
return 0;
}
static void __exit sharp_style_exit(void)
{
free_irq(IRQ_EINT8, NULL);
del_timer_sync(&my_timer);
}
module_init(sharp_style_init);
module_exit(sharp_style_exit);
MODULE_LICENSE("GPL");