开发者分享 | 如何在 IP 的 kernel module 里设置并使用 IP interrupt

本文转载自:XILINX开发者社区微信公众号

本文来自 XILINX 产品应用工程师 Davis Zhang

有时我们需要为官方 IP 或者自己创建的 IP 生成 kernel module,然后在 linux kernel space 里使用 kernel module 来控制这个 IP。如果要使用 IP 中断,我们需要在 kernel module 代码里获取设备中断并建立中断服务程序。

在老版本 petalinux,我们可以在 kernelmodule 里直接指定 IP 中断的实际物理中断号,但是新版本内核里我们需要在 kernel module 里获取 IP 的虚拟中断号。可以在 kernelmodule 代码里使用 request_irq 函数来获取中断并指定中断服务程序。

附件是为 axigpio IP 写的一个 kernel module,可以作为参考例子:

点击:https://pan.baidu.com/share/init?surl=RvMAiHWdIx1d3qo_1RjpCA 输入0511 即可获得本文附件

首先需要生成一个基于 MPSoC 芯片的 vivado 工程,

在 block design 里加入 MPSoC processing core 和 axi gpiocore,

连接 axi gpio 的中断信号到 MPSoC processing core 的 PL->PS 中断端口

最后生成 bitstream 导出 hdf 或者 xsa,生成 petalinux 工程,

在 petalinux 工程里用下面命令生成并使能名字叫做 gpioirq 的 kernel module,

Petalinux-create-t modules --name gpioirq --enable

然后在petalinux工程目录里会生成这样一个路径 project-spec/meta-user/recipes-modules/gpioirq/files,把里面的 gpioirq.c 用附件里的同名文件覆盖掉。

用附件里的 system-user.dtsi 把 project-spec/meta-user/recipes-bsp/device-tree/files 里的同名文件覆盖掉,这是因为默认生成的 device tree 里 axigpio core 的 driver 是 xilinx driver,我们需要把它替换为我们生成的 kernel module 的 drivername,需要注意 system-user.dtsi 里面的 axigpio core 的名字需要和 petalinux 工程生成的 devicetree 里的 axi gpio core 的名字一样。然后就可以运行 petalinux-build 和 petalinux-package 命令来生成 boot image,然后上板启动。Linux boot 之后可以通过 cat/proc/interrupts 命令看到 qgioirq 中断已经建立起来了,按一下对应 axigpio 的板上 IO 按钮可以看到中断服务程序的打印信息。

最新文章

最新文章