我正在为 x86 linux 开发设备驱动程序。该设备有一个引脚连接到 PCH 上的 GPIO 以产生中断。如何请求与该 GPIO 引脚关联的 IRQ 并安装中断处理程序?
问问题
5958 次
1 回答
5
您要查找的头文件是
#include <linux/gpio.h>
您需要做的第一件事是分配特定的 GPIO。你可以使用这个调用来做到这一点:
#define GPIO //gpio number
...
if(gpio_request(GPIO, "Description"))
//fail
...
在你自己得到 GPIO 引脚后,你可以为它获取一个 IRQ
int irq = 0;
if((irq = gpio_to_irq(GPIO)) < 0 /*irq number can't be less than zero*/)
//fail
...
现在您使用通常的内核例程注册一个 IRQ 处理程序。
#include <linux/interrupt.h>
...
int result = request_irq(irq, handler_function,
IRQF_TRIGGER_LOW, /*here is where you set up on what event should the irq occur*/
"Description", "Device description");
if(result)
//fail
...
记得在做模块清理free_irq
的时候。gpio_free
如果您不这样做,您将无法再次分配该 GPIO 引脚。
于 2013-09-07T14:06:31.103 回答