#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
static int irq;
static char *interface;
module_param(interface,charp,0644); //2.6内核中的宏,表示这个参数要在插入模块时给出值
module_param(irq,int,0644);
int dev_id = 127;//设备id
static irqreturn_t myinterrupt(int irq, void *dev_id)//中断服务程序,自己所写
{
static int count = 0;
if (count < 10) {
printk("Interrupt %d, %d\n", irq, *(int *)dev_id);
count++;
}
return IRQ_NONE;
}
static int __init myirqtest_init(void)
{
printk ("My module worked!\n");
if (request_irq(irq, &myinterrupt, IRQF_SHARED,interface, &dev_id)) {//注册中断,参数意义前面有讲
printk(KERN_ERR "myirqtest: cannot register IRQ %d\n", irq);
return -EIO;
}
printk("%s Request on IRQ %d succeede dev_id is:%d\n",interface, irq, dev_id);
return 0;
}
static void __exit myirqtest_exit(void)
{
printk ("Unloading my module.\n");
free_irq(irq, &irq);
printk("Freeing IRQ %d\n", irq);
}
module_init(myirqtest_init);
module_exit(myirqtest_exit);
MODULE_LICENSE("GPL");
|