<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 模擬技術(shù) > 設(shè)計(jì)應(yīng)用 > 讓 Linux 接收來自 PL 的自定義中斷信號(hào)

          讓 Linux 接收來自 PL 的自定義中斷信號(hào)

          作者: 時(shí)間:2018-07-25 來源:網(wǎng)絡(luò) 收藏

          硬件連接

          本文引用地址:http://www.ex-cimer.com/article/201807/383831.htm

          MPSoC 可以接收兩組來自 PL 的中斷信號(hào)。在 Vivado 中,可以通過 PS-PL Configuration -> General -> Interrupts -> PL to PS -> IRQ0/IRQ1 打開。

          對(duì)應(yīng)的硬件中斷號(hào)分別是

          PL PS Group 0: 121-128

          PL PS Group 1: 136-143

          這兩組中斷信號(hào)既可以與 IPI 中的 IP 的中斷信號(hào)相連接,也可以和 Verilog 中的邏輯相連接。如果有多個(gè)中斷源要連接到一組信號(hào)中,可以使用concat將多個(gè)信號(hào)組合成一組信號(hào),然后連接到 IRQ。

          如果要從 Verilog 引入中斷信號(hào),需要在 IPI 中按右鍵選擇 Create Port。Port Type 選擇為 Interrupt。

          軟硬件的橋梁: device tree

          硬件信息怎樣傳送給軟件系統(tǒng)?

          Linux 的答案是 Device Tree。

          以下是 Device Tree Generator 為上圖中的 AXI UARTLite 自動(dòng)創(chuàng)建的 device tree。

          axi_uartlite_0: serial@a0000000 {

          clocks = misc_clk_0>;

          compatible = xlnx,xps-uartlite-1.00.a;

          current-speed = 115200>;

          device_type = serial;

          interrupt-parent = gic>;

          interrupts = 0 89 1>;

          port-number = 1>;

          reg = 0x0 0xa0000000 0x0 0x10000>;

          xlnx,baudrate = 0x2580>;

          xlnx,data-bits = 0x8>;

          xlnx,odd-parity = 0x0>;

          xlnx,s-axi-aclk-freq-hz-d = 99.999;

          xlnx,use-parity = 0x0>;

          };

          創(chuàng)建 Device Tree

          Device tree 是純文本文件,后綴是 .dts 或 .dtsi。當(dāng)然可以手工從頭開始寫(似乎沒人這么做),Xilinx 也提供了工具來幫助自動(dòng)生成。

          一種方法是使用 PetaLinux,其實(shí)這也是 petalinux-build 中的一個(gè)步驟。當(dāng)在一個(gè) PetaLinux 工程中導(dǎo)入 HDF 后,運(yùn)行 petalinux-build它會(huì)自動(dòng)調(diào)用 Device Tree Generator (DTG),為你的工程產(chǎn)生 device tree。用戶可以在自動(dòng)生成的文件的基礎(chǔ)上進(jìn)一步修改,修改的時(shí)候注意文件都上會(huì)寫哪些文件重新生成時(shí)會(huì)被覆蓋,哪些不會(huì)。

          另一種生成 device tree 的方法是使用 SDK。SDK 可以把 DTG 加載為 BSP Generator,用來生成 device tree. DTG 的下載地址是 [ https://github.com/Xilinx/device-tree-xlnx ]。下載到本地后,在 SDK 的 Xilinx Tools -> Repositories 中添加解壓后的目錄。在 SDK 中新建一個(gè) BSP, BSP 類型選擇 device_tree

          Note: 如果是SDx工具,加載DTG的方法是 Window -> Preference -> Xilinx SDK -> Repositories

          Interrupt 屬性的定義

          Device tree 中和中斷相關(guān)的屬性有兩條,interrupts和interrupt-parents。

          interrupt-parents指向了中斷控制器。在 MPSoC 中有多個(gè)外設(shè)都有中斷控制器屬性,分別是 GIC, GPIO, PCIe。

          interrupts 后的參數(shù)指定了中斷號(hào)和中斷屬性。

          Device tree bindings interrupts.txt 中定義了 interrupts 后參數(shù)的意義。需要注意的是,在中斷控制器的屬性中有#interrupt-cells的定義,表示interrupts參數(shù)需要幾個(gè)32位的字符。常見的情況是1到3。1個(gè)Cell的情況只填寫中斷號(hào)。2個(gè)Cell的情況填寫中斷號(hào)和觸發(fā)條件,GPIO Controller就是這種情況。

          ARM GIC 使用的是 3 個(gè) Cell:

          第一個(gè) cell 是 0 的話表示中斷類型:0 for SPI interrupts, 1 for PPI interrupts。PL 到 PS 的中斷屬于 SPI,所以填寫 0。

          第二個(gè) Cell 表示中斷號(hào)

          第三個(gè) Cell 表示中斷觸發(fā)方式。

          ARM GIC v3 中斷 Cell 說明,來自 arm,gic-v3.txt

          The 1st cell is the interrupt type; 0 for SPI interrupts, 1 for PPI

          interrupts. Other values are reserved for future use.

          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 = edge triggered

          4 = level triggered

          中斷號(hào)的確定

          Device tree 中 interrupts 的中斷號(hào)請(qǐng)?zhí)顚懹布布袛嗵?hào) - 32

          中斷的驅(qū)動(dòng)程序

          PetaLinux 中自帶了中斷服務(wù)程序的例子。

          用命令 petalinux-create -t modules -n mymodule就可以創(chuàng)建出例子程序。

          其中與注冊(cè) IRQ 中斷號(hào)相關(guān)的語句為:

          /* Get IRQ for the device */

          r_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);

          if (!r_irq) {

          dev_info(dev, no IRQ foundn);

          dev_info(dev, mymodule at 0x%08x mapped to 0x%08xn,

          (unsigned int __force)lp->mem_start,

          (unsigned int __force)lp->base_addr);

          return 0;

          }

          lp->irq = r_irq->start;

          rc = request_irq(lp->irq, mymodule_irq, 0, DRIVER_NAME, lp);

          if (rc) {

          dev_err(dev, testmodule: Could not allocate interrupt %d.n,

          lp->irq);

          goto error3;

          }

          注意上面的程序是通過讀取 dts 獲取中斷的信息,然后讓操作系統(tǒng)分配一個(gè)虛擬中斷號(hào)。以前注冊(cè)中斷號(hào)是通過手工在 C 代碼中填入中斷號(hào),現(xiàn)在這種方法不可行了,請(qǐng)使用虛擬中斷號(hào)的方法。



          關(guān)鍵詞:

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();