一个好老好老的老程序员了。
全部博文(915)
分类: LINUX
2011-06-06 12:18:07
在调试该程序的时候请保证调试了内的程序,并且对中断有了一定的学习。
/*myirq.c*/
#include
#include
#include
static int irq;
static char *interface;
module_param(interface,charp,0644);
module_param(irq,int,0644);
//static irq_handler_t myinterrupt(int irq, void *dev_id, struct pt_regs *regs)
static irqreturn_t myinterrupt(int irq, void *dev_id)
{
static int mycount = 0;
static long mytime = 0;
struct net_device *dev=(struct net_device *)dev_id;
if(mycount==0){
mytime=jiffies;
}
//count the interval between two irqs
if (mycount < 10) {
mytime=jiffies-mytime;
printk(“Interrupt number %d — intterval(jiffies) %ld — jiffies:%ld \n”, irq,mytime, jiffies);
mytime=jiffies;
//printk(“Interrupt on %s —–%d \n”,dev->name,dev->irq);
}
mycount++;
return IRQ_NONE;
}
static int __init myirqtest_init(void)
{
printk (“My module worked!\n”);
//regist irq
//if (request_irq(irq,&myinterrupt,SA_SHIRQ,interface,&irq)) { //early than 2.6.23
if (request_irq(irq,&myinterrupt,IRQF_SHARED,interface,&irq)) { //later than 2.6.23
printk(KERN_ERR “myirqtest: cannot register IRQ %d\n”, irq);
return -EIO;
}
printk(“%s Request on IRQ %d succeeded\n”,interface,irq);
return 0;
}
static void __exit myirqtest_exit(void)
{
printk (“Unloading my module.\n”);
free_irq(irq, &irq); //release irq
printk(“Freeing IRQ %d\n”, irq);
return;
}
module_init(myirqtest_init);
module_exit(myirqtest_exit);
MODULE_AUTHOR(“Helight.Xu”);
MODULE_LICENSE(“GPL”);
编译使用该模块:
使用Makefile文件的内容如下
obj-m := myirq.o
KERNELDIR := /usr/src/kernels/linux-2.6.24/
all:
make -C $(KERNELDIR) M=$(PWD) modules
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
在查看 /proc/interrupts文件后,确定要共享的中断号(应为该程序是共享中断号的),使用下面的命令插入模块。
insmod myirq.ko irq=2 interface=myirq