usage: Compiling this file by make
and using the following command to insert the mode which the make generated just now
command: sudo insmod filename.ko irq=1 devname=myirq
This interrupt shared the one irq with keyboard
http://edsionte.com/techblog/archives/1547
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
static int irq;
static char* devname;
module_param(irq,int,0644);
module_param(devname,charp,0644);
struct myirq
{
int devid;
};
struct myirq mydev={1119};
static void mytasklet_handler(unsigned long data)
{
printk("tasklet is wroking..\n");
}
static irqreturn_t myirq_handler(int irq,void* dev);
#if 0
static struct tasklet_struct mytasklet;
#else
DECLARE_TASKLET(mytasklet,mytasklet_handler,0);
/*
equal to this
464#define DECLARE_TASKLET(name, func, data) \
2
465struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
3
466
4
467#define DECLARE_TASKLET_DISABLED(name, func, data) \
5
468struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
470void tasklet_init(struct tasklet_struct *t,
2
471 void (*func)(unsigned long), unsigned long data)
3
472{
4
473 t->next = NULL;
5
474 t->state = 0;
6
475 atomic_set(&t->count, 0);
7
476 t->func = func;
8
477 t->data = data;
9
478}
*/
#endif
#if 0
static irqreturn_t myirq_handler(int irq,void* dev)
{
struct myirq mydev;
static int count=0;
mydev=*(struct myirq*)dev;
printk("key:%d..\n",count+1);
printk("devid:%d ISR is working..\n",mydev.devid);
printk("Bottom half will be working..\n");
tasklet_init(&mytasklet,mytasklet_handler,0);
tasklet_schedule(&mytasklet);
printk("ISR is leaving..\n");
count++;
return IRQ_HANDLED;
}
#else
static irqreturn_t myirq_handler(int irq,void* dev)
{
static int count=0;
if(count<10)
{
printk("-----------%d start--------------------------\n",count+1);
printk("The interrupt handeler is working..\n");
printk("The most of interrupt work will be done by following tasklet..\n");
tasklet_init(&mytasklet,mytasklet_handler,0);
tasklet_schedule(&mytasklet);
printk("The top half has been done and bottom half will be processed..\n");
}
count++;
return IRQ_HANDLED;
}
#endif
static int __init myirq_init()
{
printk("Module is working..\n");
if(request_irq(irq,myirq_handler,IRQF_SHARED,devname,&mydev)!=0)
{
printk("%s request IRQ:%d failed..\n",devname,irq);
return -1;
}
printk("%s rquest IRQ:%d success..\n",devname,irq);
return 0;
}
static void __exit myirq_exit()
{
printk("Module is leaving..\n");
tasklet_kill(&mytasklet);
free_irq(irq,&mydev);
printk("%s request IRQ:%d success..\n",devname,irq);
}
module_init(myirq_init);
module_exit(myirq_exit);
MODULE_LICENSE("GPL");
[ 5746.224365] -----------7 start--------------------------
[ 5746.224371] The interrupt handeler is working..
[ 5746.224374] The most of interrupt work will be done by following tasklet..
[ 5746.224378] The top half has been done and bottom half will be processed..
[ 5746.224383] tasklet is wroking..
[ 5746.304318] -----------8 start--------------------------
[ 5746.304324] The interrupt handeler is working..
[ 5746.304327] The most of interrupt work will be done by following tasklet..
[ 5746.304331] The top half has been done and bottom half will be processed..
[ 5746.304336] tasklet is wroking..
[ 5746.928381] -----------9 start--------------------------
[ 5746.928388] The interrupt handeler is working..
[ 5746.928391] The most of interrupt work will be done by following tasklet..
[ 5746.928395] The top half has been done and bottom half will be processed..
[ 5746.928401] tasklet is wroking..
[ 5747.024316] -----------10 start--------------------------
[ 5747.024323] The interrupt handeler is working..
[ 5747.024326] The most of interrupt work will be done by following tasklet..
[ 5747.024330] The top half has been done and bottom half will be processed..
[ 5747.024336] tasklet is wroking..
[ 5843.123786] Module is leaving..
[ 5843.123794] myirq request IRQ:1 success..