当前位置: 技术问答>linux和unix
Linux驱动中注册的中断号与实际的硬件中断号的关系
来源: 互联网 发布时间:2016-11-24
本文导语: 最近在学习怎么写Linux的驱动,看到中断的注册时有点困惑,主要是不明白request_irq时,这个irq是要从哪来呢?如果一个引脚可以做普通io口也可以用来接收外部中断,那我现在要注册这个中断时应该去哪里找这个中断...
最近在学习怎么写Linux的驱动,看到中断的注册时有点困惑,主要是不明白request_irq时,这个irq是要从哪来呢?如果一个引脚可以做普通io口也可以用来接收外部中断,那我现在要注册这个中断时应该去哪里找这个中断号呢?
是不是linux的源代码包中都已经将各种cpu下的中断号都定好了,我们要用时直接去找就行??
以前看过wince的中断实现,就是在一个中断响应函数里面读取寄存器,判断是那一个外设引发的中断,然后返回与预设的逻辑中断号,驱动就可以接收到信号了。linux的暂时还看不大懂,高手们指点下。谢谢。
是不是linux的源代码包中都已经将各种cpu下的中断号都定好了,我们要用时直接去找就行??
以前看过wince的中断实现,就是在一个中断响应函数里面读取寄存器,判断是那一个外设引发的中断,然后返回与预设的逻辑中断号,驱动就可以接收到信号了。linux的暂时还看不大懂,高手们指点下。谢谢。
|
是这样的,一般的板子BSP包已经做好了,各个IRQ的号已经编好了,一般在xxx-irqs.h或者irqs.h里面,其实这个号也是可以随便编的,只是在系统查询中断号的地方(entry-macro.S)里面把这个号和实际的中断对应上就OK了。关于gpio中断注册上是不是立马就能用,取决于你的BSP的配置了,比如有些上来默认是GPIO输出,那你还需要把它配置成输入并使能中断,这个把那些控制寄存器的值打出来看看就知道了
|
以前见过一段如下描述:
There are three ways to select a line for an IRQ-configurable device:
• By setting hardware jumpers (only on very old device cards).
• By a utility program shipped with the device and executed when installing it. Such a program may either ask the user to select an available IRQ number or probe the system to determine an available number by itself.
• By a hardware protocol executed at system startup. Peripheral devices declare which interrupt lines they are ready to use; the final values are then negotiated to reduce conflicts as much as possible. Once this is done, each interrupt handler can read the assigned IRQ by using a function that accesses some I/O ports of the device. For instance, drivers for devices that comply with the Peripheral Component Interconnect (PCI) standard use a group of functions such as pci_read_config_byte( ) to access the device configuration space.
There are three ways to select a line for an IRQ-configurable device:
• By setting hardware jumpers (only on very old device cards).
• By a utility program shipped with the device and executed when installing it. Such a program may either ask the user to select an available IRQ number or probe the system to determine an available number by itself.
• By a hardware protocol executed at system startup. Peripheral devices declare which interrupt lines they are ready to use; the final values are then negotiated to reduce conflicts as much as possible. Once this is done, each interrupt handler can read the assigned IRQ by using a function that accesses some I/O ports of the device. For instance, drivers for devices that comply with the Peripheral Component Interconnect (PCI) standard use a group of functions such as pci_read_config_byte( ) to access the device configuration space.
|
omap下的代码,gpio的号加上一个base就是irq号
data->irq = OMAP_GPIO_IRQ(COMPASS_SENSOR_INT_GPIO);
if(request_irq(data->irq,AMI304_int_handler,IRQF_TRIGGER_RISING,"ami304", data)
data->irq = OMAP_GPIO_IRQ(COMPASS_SENSOR_INT_GPIO);
if(request_irq(data->irq,AMI304_int_handler,IRQF_TRIGGER_RISING,"ami304", data)