你的第一个中断处理程序

 

//平台:ubuntu9.10  

 

#include "linux/init.h"

#include "linux/module.h"

#include "linux/kernel.h"

 

#include "linux/interrupt.h"

 

static int irq;

static char * interface;

 

module_param(interface,charp,0644);

module_param(irq,int,0644);

 

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("lin.tang");

MODULE_LICENSE("GPL");

 

 

对应Makefile文件:

 

 

 

obj-m += interrupt.o

#generate the path

CURRENT_PATH:=$(shell pwd)

 

#the current kernel version number

LINUX_KERNEL:=$(shell uname -r)

 

#the absolute path

LINUX_KERNEL_PATH:=/usr/src/linux-headers-$(LINUX_KERNEL)

 

#complie object

all:

make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules

#clean

clean:

make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean

rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

 

 

 

//参考文档:

 

http://www.kerneltravel.net/?p=133

http://edsionte.com/techblog/archives/1521

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值