新聞中心

        EEPW首頁 > 模擬技術 > 設計應用 > 讓 Linux 接收來自 PL 的自定義中斷信號

        讓 Linux 接收來自 PL 的自定義中斷信號

        作者: 時間:2018-07-25 來源:網絡 收藏

        硬件連接

        本文引用地址:http://www.104case.com/article/201807/383831.htm

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

        對應的硬件中斷號分別是

        PL PS Group 0: 121-128

        PL PS Group 1: 136-143

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

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

        軟硬件的橋梁: device tree

        硬件信息怎樣傳送給軟件系統?

        Linux 的答案是 Device Tree。

        以下是 Device Tree Generator 為上圖中的 AXI UARTLite 自動創建的 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>;

        };

        創建 Device Tree

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

        一種方法是使用 PetaLinux,其實這也是 petalinux-build 中的一個步驟。當在一個 PetaLinux 工程中導入 HDF 后,運行 petalinux-build它會自動調用 Device Tree Generator (DTG),為你的工程產生 device tree。用戶可以在自動生成的文件的基礎上進一步修改,修改的時候注意文件都上會寫哪些文件重新生成時會被覆蓋,哪些不會。

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

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

        Interrupt 屬性的定義

        Device tree 中和中斷相關的屬性有兩條,interrupts和interrupt-parents。

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

        interrupts 后的參數指定了中斷號和中斷屬性。

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

        ARM GIC 使用的是 3 個 Cell:

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

        第二個 Cell 表示中斷號

        第三個 Cell 表示中斷觸發方式。

        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

        中斷號的確定

        Device tree 中 interrupts 的中斷號請填寫硬件硬件中斷號 - 32

        中斷的驅動程序

        PetaLinux 中自帶了中斷服務程序的例子。

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

        其中與注冊 IRQ 中斷號相關的語句為:

        /* 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 獲取中斷的信息,然后讓操作系統分配一個虛擬中斷號。以前注冊中斷號是通過手工在 C 代碼中填入中斷號,現在這種方法不可行了,請使用虛擬中斷號的方法。



        關鍵詞:

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 盘山县| 灵川县| 华亭县| 博湖县| 阳信县| 图片| 潍坊市| 布尔津县| 界首市| 阳新县| 申扎县| 吐鲁番市| 崇仁县| 安义县| 沂源县| 南通市| 山阴县| 游戏| 丹凤县| 崇阳县| 阿鲁科尔沁旗| 保康县| 尚志市| 台东县| 永川市| 霍邱县| 都兰县| 望江县| 麻栗坡县| 老河口市| 扎赉特旗| 宁南县| 偏关县| 吴川市| 囊谦县| 巴林左旗| 定日县| 河东区| 崇义县| 岳阳县| 西林县|