我正在为 Linux 内核中的虚拟设备编写设备驱动程序。因为它是虚拟的,请问是否有任何命令或技术可以手动触发中断只是为了测试我的中断处理程序?
目前我的中断处理程序就像这样简单:
static irqreturn_t interrupt_handler(int irq, void *dev_id){
printk(KERN_ALERT "Interrupt handler executed!\n");
return IRQ_HANDLED;
}
它由探针函数调用:
static int probe (struct platform_device *pdev) {
printk("-----------------------------------------PROBE CALLED \n");
ret = misc_register(&mydevice);
printk("-----------------------------------------GOT MINOR:%i\n",mydevice.minor);
struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if(r == NULL) {
printk("platform_get_resource failed\n");
return -ENODEV;
}
irq = platform_get_irq(pdev,0);
if (irq < 0) {
printk("platform_get_irq failed\n");
return -ENODEV;
}
printk("Got irq =%d\n",irq);
ret = request_irq(irq, interrupt_handler, IRQF_DISABLED, pdev->name, NULL);
printk("Got irq, function returns %d\n.", ret);
return ret;
}
虚拟设备在板中定义为:
static struct resource mydevice_resources[] ={
[0] = {
.start = 20,
.end = 20,
.flags = IORESOURCE_IRQ
},
[2] = {
.start = 0xC0100000,
.end = 0xC0200000,
.flags = IORESOURCE_MEM
}
};
static struct platform_device mydevice = {
.name = "mydevice",
.id = 0,
.num_resources = ARRAY_SIZE(mydevice_resources),
.resource = mydevice_resources
};
而且,不知何故,预定义的中断mydevice
是 20,但探测函数总是说它接收到中断 17。
我很感激任何提示。谢谢你。