gpt4 book ai didi

c - 如何手动引起中断?

转载 作者:太空狗 更新时间:2023-10-29 11:22:37 26 4
gpt4 key购买 nike

我正在为 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。

我很感激任何提示。谢谢。

最佳答案

我的问题到此结束。没有办法手动发出中断。如果使用 android 的虚拟机,则可以使用控制台命令虚拟调用一组有限的中断和信号。此控制台可以通过 telnet localhost 5554 打开到虚拟机。

关于c - 如何手动引起中断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15890897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com