设备树知识小全(八):中断连接

简介: 设备树知识小全(八):中断连接

参考资料:《Linux设备驱动开发详解》

1、中断连接

这我还有是有点惊讶

设备树竟然还可以保存中断信息。对于中断与硬件的关系,硬件怎么去触发中断,实现中断。有机会看看研究一下,中断。回到正题。

对于中断控制器而言,它提供如下属性:**interrupt-controller–这个属性为空,**中断控制器应该加上此属性表明自己的身份;

#interrupt-cells–与#address-cells和#size-cells相似,它表明连接此中断控制器的设备的中断属性的cell大小。

在整个设备树中,与中断相关的属性还包括:

interrupt-parent–设备节点通过它来指定它所依附的中断控制器的phandle,当节点没有指定interrupt-parent时,则从父级节点继承。对于本例(代码清单18.2)而言,根节点指定了interrupt-parent=<&intc>;,其对应于intc:interrupt-controller@10140000,而根节点的子节点并未指定interrupt-parent,因此它们都继承了intc,即位于0x10140000的中断控制器中。

interrupts–用到了中断的设备节点,通过它指定中断号、触发方法等,这个属性具体含有多少个cell,由它依附的中断控制器节点的#interrupt-cells属性决定。

而每个cell具体又是什么含义,一般由驱动的实现决定,而且也会在设备树的绑定文档中说明。譬如,对于ARM GIC中断控制器而言,#interrupt-cells为3,3个cell的具体含义在Documentation/devicetree/bindings/arm/gic.txt中就有如下文字说明:

The 1st cell is the interrupt type; 0 for SPI interrupts, 1 for PPI
interrupts.
The 2nd cell contains the interrupt number for the interrupt type.
SPI interrupts are in the range [0-987].  PPI interrupts are in the
range [0-15].
The 3rd cell is the flags, encoded as follows:
bits[3:0] trigger type and level flags.
              1 = low-to-high edge triggered
              2 = high-to-low edge triggered
              4 = active high level-sensitive
              8 = active low level-sensitive
bits[15:8] PPI interrupt cpu mask.  Each bit corresponds to each of
the 8 possible cpus attached to the GIC.  A bit set to '1' indicated
the interrupt is wired to that CPU.  Only valid for PPI interrupts.

另外,值得注意的是,一个设备还可能用到多个中断号。对于ARM GIC而言,若某设备使用了SPI的168号、169号两个中断,而且都是高电平触发,则该设备节点的中断属性可定义为interrupts=<01684>,<01694>;。

对于平台设备而言,简单的通过如下API就可以指定想取哪一个中断,其中的参数num就是中断的index

int platform_get_irq(struct platform_device *dev, unsigned int num);

当然在.dts文件中可以对中断进行命名,而后在驱动中通过platform_get_irq_byname()来获取对应的中断号

譬如代码清单18.14演示了在drivers/dma/fsl-edma.c中通过platform_get_irq_byname()获取IRQ,以及arch/arm/boot/dts/vf610.dtsi与fsl-edma驱动对应节点的中断描述。

1 static int
 2 fsl_edma_irq_init(struct platform_device *pdev,struct fsl_edma_engine *fsl_edma)
 3 {
 4     fsl_edma->txirq = platform_get_irq_byname(pdev, "edma-tx");
 5     fsl_edma->errirq = platform_get_irq_byname(pdev, "edma-err");
 6 }
 7
 8 edma0: dma-controller@40018000 {
 9           #dma-cells = <2>;
10           compatible = "fsl,vf610-edma";
11           reg = <0x40018000 0x2000>,
12                   <0x40024000 0x1000>,
13                   <0x40025000 0x1000>;
14           interrupts = <0 8 IRQ_TYPE_LEVEL_HIGH>,
15                           <0 9 IRQ_TYPE_LEVEL_HIGH>;
16           interrupt-names = "edma-tx", "edma-err";
17           dma-channels = <32>;
18           clock-names = "dmamux0", "dmamux1";
19           clocks = <&clks VF610_CLK_DMAMUX0>,
20                   <&clks VF610_CLK_DMAMUX1>;
21 };

第4行、第5行的platform_get_irq_byname()的第2个参数与.dts中的interrupt-names是一致的。

目录
相关文章
|
Ubuntu Linux 编译器
字符驱动设备原理及其相关函数(一)
字符驱动设备原理及其相关函数(一)
114 0
|
2月前
GIGE 协议摘录 —— 引导寄存器(四)(中)
GIGE 协议摘录 —— 引导寄存器(四)
36 1
|
2月前
|
存储 XML 前端开发
GIGE 协议摘录 —— 引导寄存器(四)(上)
GIGE 协议摘录 —— 引导寄存器(四)
34 1
|
2月前
GIGE 协议摘录 —— 引导寄存器(四)(下)
GIGE 协议摘录 —— 引导寄存器(四)
31 1
|
5月前
|
Linux API 开发者
设备树知识小全(九):GPIO、时钟、pinmux连接
设备树知识小全(九):GPIO、时钟、pinmux连接
231 0
|
Linux
字符驱动设备原理及其相关函数(二)
字符驱动设备原理及其相关函数(二)
56 0
|
Ubuntu Linux 开发者
韦东山Linux驱动入门实验班(2)hello驱动---驱动层与应用层通讯,以及自动产生设备节点
韦东山Linux驱动入门实验班(2)hello驱动---驱动层与应用层通讯,以及自动产生设备节点
158 0
|
存储 安全 存储控制器
ZYNQ裸板:中断篇
中断对于单片机过来的我们来说,相对也算比较熟悉了,还是严谨一点从头开始说吧。中断是什么?是一种当满足要求的突发事件发生时通知处理器进行处理的信号。中断可以由硬件处理单元和外部设备产生,也可以由软件本身产生。对硬件来说,中断信号是一个由某个处理单元产生的异步信号,用来引起处理器的注意。对软件来说,中断还是一种异步事件,用来通知处理器需要改变代码的执行,当然,轮询所产生的中断的过程是同步的。
789 0
ZYNQ裸板:中断篇
|
Linux
Linux驱动开发——(次设备号使用及混杂设备驱动开发)gpio(5)
Linux驱动开发——(次设备号使用及混杂设备驱动开发)gpio(5)
237 0
Linux驱动开发——(次设备号使用及混杂设备驱动开发)gpio(5)
|
编解码
什么是中断?西门子S7-200 SMART如何编写中断程序
中断就是中止当前正在运行的程序,去执行为立刻响应的信号而编写的中断服务程序,执行完毕后再返回原来中止的程序并继续执行。
什么是中断?西门子S7-200 SMART如何编写中断程序