转自:https://blog.csdn.net/h244259402/article/details/83993524

PC:Windows 10

虚拟机:ubuntu 16.04

vivado:2017.04

的的PetaLinux:2017.04

开发板:黑金AX7010

根文件系统:debian8

-------------------------------------------------- --------------------传说中的分割线------------------------- -------------------------------------------------- ----

将  zynq linux驱动之传统开发  里的vivado工程另存为interrupt7010

接下来配置一下中断

这里会出现中断的接口

接下来添加一个引脚

连起来

重新生成一下顶层文件

打开顶层文件,加一个非门(因为PS这边貌似只支持上升沿中断和高电平中断)

在约束文件里面添加触发IRQ的引脚(这里用的是KEY4,HDMI座子旁边的那个按键)

执行生成位文件

结束之后将原来的SDK目录删掉

重新导入硬件和位文件之后打开SDK

将该文件夹拷贝到Ubuntu的里

使用的PetaLinux编译fsbl,u-boot的,内核,设备树文件:

过程略.....

用的PetaLinux制作BOOT.BIN文件,将BOOT.BIN,image.ub,system.dtb文件拷贝到SD卡的胖分区里(这里没有用的PetaLinux生成的根文件系统,用的是debian8)

接下来打开数据表

找到中断号是61

然后先到开板上看一下

cat /proc/interrupts

再看看数据表上

没有问题中断号都对得上

然后再来看看设备树

vim components/plnx_workspace/device-tree/device-tree-generation/zynq-7000.dtsi

发现这里的中断号跟数据表和/ PROC /中断里面的对不上

仔细观察发现设备树里面的中断号是数据表上的中断号减去32得到的值

接下来仿照这个写一个自己的

vim project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi
/include/ "system-conf.dtsi"
/ {
amba_pl: amba_pl{
#address-cells = <1>;
#size-cells = <1>;
compatible = "simple-bus";
ranges;
irq: irq@0{
compatible = "hello,irq";
interrupt-parent = <&intc>;
interrupts = <0 29 2>;
};
};
};

执行的PetaLinux建造编译

编译完成之后

到开发板上,挂接NFS文件系统,然后把编译好的设备树文件(system.dts)拷贝到开发板SD卡的脂肪分区里,重启开发板

ls /proc/device-tree/amba_pl/
可以看到设备树节点增加了IRQ @ 0

编写驱动:

#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/types.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/device.h>
#include <linux/cdev.h>
#include <linux/of.h>
#include <linux/delay.h>

#include <linux/dma-mapping.h>

#include <linux/pm.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/gfp.h>
#include <linux/mm.h>
#include <linux/dma-buf.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/dmaengine.h>
#include <linux/completion.h>
#include <linux/wait.h>
#include <linux/init.h>

#include <linux/sched.h>
#include <linux/pagemap.h>
#include <linux/errno.h> /* error codes */
#include <linux/clk.h>
#include <linux/interrupt.h>
#include <linux/vmalloc.h>

#include <linux/moduleparam.h>
#include <linux/miscdevice.h>
#include <linux/ioport.h>
#include <linux/notifier.h>
#include <linux/init.h>
#include <linux/pci.h>

#include <linux/time.h>
#include <linux/timer.h>

//
static char devname[16];
static int major;
static int mijor;
static struct class* cls;
static void __iomem* base_address;
static resource_size_t remap_size;
static int irq;
static struct device* dev;

//

#define DEVICE_NAME "irq_drv"

static volatile int irq_is_open = 0;

static struct fasync_struct *irq_async;

static int irq_drv_open(struct inode *Inode, struct file *File)
{
irq_is_open = 1;
return 0;
}

int irq_drv_release (struct inode *inode, struct file *file)
{
irq_is_open = 0;
return 0;
}

static ssize_t irq_drv_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
return 0;
}

static ssize_t irq_drv_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
{
return 0;
}

static int irq_drv_fasync (int fd, struct file *filp, int on)
{
return fasync_helper (fd, filp, on, &irq_async);
}

static struct file_operations irq_fops = {
.owner = THIS_MODULE,
.open = irq_drv_open,
.read = irq_drv_read,
.write = irq_drv_write,
.fasync = irq_drv_fasync,
.release = irq_drv_release,
};

static irqreturn_t irq_interrupt(int irq, void *dev_id)
{
printk("irq = %d\n", irq);
if(irq_is_open)
{
kill_fasync (&irq_async, SIGIO, POLL_IN);
}
return IRQ_HANDLED;
}

static int irq_probe(struct platform_device *pdev)
{
int err;
struct device *tmp_dev;
memset(devname,0,16);
strcpy(devname, DEVICE_NAME);

major = register_chrdev(0, devname, &irq_fops);

cls = class_create(THIS_MODULE, devname);
mijor = 1;
tmp_dev = device_create(cls, &pdev->dev, MKDEV(major, mijor), NULL, devname);
if (IS_ERR(tmp_dev)) {
class_destroy(cls);
unregister_chrdev(major, devname);
return 0;
}

irq = platform_get_irq(pdev,0);
if (irq <= 0)
return -ENXIO;

dev = &pdev->dev;

err = request_threaded_irq(irq, NULL,
irq_interrupt,
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
devname, NULL);
if (err) {
printk(KERN_ALERT "irq_probe irq error=%d\n", err);

goto fail;
}
else
{
printk("irq = %d\n", irq);
printk("devname = %s\n", devname);
}

//保存dev
//platform_set_drvdata(pdev, &xxx);

return 0;

fail:

free_irq(irq, NULL);

device_destroy(cls, MKDEV(major, mijor));
class_destroy(cls);
unregister_chrdev(major, devname);

return -ENOMEM;

}

static int irq_remove(struct platform_device *pdev)
{
device_destroy(cls, MKDEV(major, mijor));
class_destroy(cls);
unregister_chrdev(major, devname);

free_irq(irq, NULL);
printk("irq = %d\n", irq);

return 0;
}

static int irq_suspend(struct device *dev)
{

return 0;
}

static int irq_resume(struct device *dev)
{

return 0;
}

static const struct dev_pm_ops irq_pm_ops = {
.suspend = irq_suspend,
.resume = irq_resume,
};

//MODULE_DEVICE_TABLE(platform, irq_driver_ids);

static const struct of_device_id irq_of_match[] = {
{.compatible = "hello,irq" },
{ }
};
MODULE_DEVICE_TABLE(of, irq_of_match);

static struct platform_driver irq_driver = {
.probe = irq_probe,
.remove = irq_remove,
.driver = {
.owner = THIS_MODULE,
.name = "irq@0",
.pm = &irq_pm_ops,
.of_match_table = irq_of_match,
},
};

module_platform_driver(irq_driver);

MODULE_LICENSE("GPL v2");

Makefile文件:

export ARCH=arm

KERN_DIR = /home/zynq/work/kernel/linux-4.9

all:
make -C $(KERN_DIR) M=`pwd` modules

clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order

obj-m += irq_drv.o

编译驱动

开发板挂接NFS文件系统,加载驱动

然后按一下按键,内核就能打印出IRQ

编写测试程序:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <poll.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int fd;

void my_signal_fun(int signum)
{
printf("irq app printf!\n");
}

int main(int argc, char **argv)
{
unsigned char key_val;
int ret;
int Oflags;

signal(SIGIO, my_signal_fun);

fd = open("/dev/irq_drv", O_RDWR);
if (fd < 0)
{
printf("can't open!\n");
}

fcntl(fd, F_SETOWN, getpid());

Oflags = fcntl(fd, F_GETFL);

fcntl(fd, F_SETFL, Oflags | FASYNC);

while (1)
{
sleep(1000);
}

return 0;
}
编译

arm-linux-gnueabihf-gcc -o irq irq.c
回到开发板运行测试程序

按下按键之后能够看到内核和测试程序的打印信息
---------------------
作者:h244259402
来源:CSDN
原文:https://blog.csdn.net/h244259402/article/details/83993524
版权声明:本文为博主原创文章,转载请附上博文链接!

zynq linux驱动之PL-PS中断【转】的更多相关文章

  1. linux驱动学习笔记---实现中断下半部以及驱动编写规范(七)【转】

    转自:https://blog.csdn.net/weixin_42471952/article/details/81609141 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协 ...

  2. ZYNQ笔记(4):PL触发中断

    一.ZYNQ中断框图 PL到PS部分的中断经过ICD控制器分发器后同时进入CPU1 和CPU0.从下面的表格中可以看到中断向量的具体值.PL到PS部分一共有20个中断可以使用.其中4个是快速中断.剩余 ...

  3. Linux驱动设计—— 中断与时钟

    中断和时钟技术可以提升驱动程序的效率 中断 中断在Linux中的实现 通常情况下,一个驱动程序只需要申请中断,并添加中断处理函数就可以了,中断的到达和中断函数的调用都是内核实现框架完成的.所以程序员只 ...

  4. Linux驱动之按键驱动编写(中断方式)

    在Linux驱动之按键驱动编写(查询方式)已经写了一个查询方式的按键驱动,但是查询方式太占用CPU,接下来利用中断方式编写一个驱动程序,使得CPU占有率降低,在按键空闲时调用read系统调用的进程可以 ...

  5. linux驱动之中断方式获取键值

    linux驱动之中断方式获取键值 ----------------------------------------------------------------------------------- ...

  6. Linux 驱动框架---驱动中的中断

    在单片机开发中中断就是执行过程中发生了一些事件需要及时处理,所以需要停止当前正在运行的处理的事情转而去执行中断服务函数,已完成必要的事件的处理.在Linux中断一样是如此使用但是基于常见的中断控制器的 ...

  7. Linux驱动实践:一起来梳理中断的前世今生(附代码)

    作 者:道哥,10+年嵌入式开发老兵,专注于:C/C++.嵌入式.Linux. 关注下方公众号,回复[书籍],获取 Linux.嵌入式领域经典书籍:回复[PDF],获取所有原创文章( PDF 格式). ...

  8. Linux驱动技术(六) _内核中断

    在硬件上,中断源可以通过中断控制器向CPU提交中断,进而引发中断处理程序的执行,不过这种硬件中断体系每一种CPU都不一样,而Linux作为操作系统,需要同时支持这些中断体系,如此一来,Linux中就提 ...

  9. Linux 驱动开发

    linux驱动开发总结(一) 基础性总结 1, linux驱动一般分为3大类: * 字符设备 * 块设备 * 网络设备 2, 开发环境构建: * 交叉工具链构建 * NFS和tftp服务器安装 3, ...

随机推荐

  1. LSTM时间序列预测及网络层搭建

    一.LSTM预测未来一年某航空公司的客运流量 给你一个数据集,只有一列数据,这是一个关于时间序列的数据,从这个时间序列中预测未来一年某航空公司的客运流量.数据形式: 二.实战 1)数据下载 你可以go ...

  2. 设计模式_代理模式_在SqlSessionTemplate(Spring)中的应用

    1.SqlSessionTemplate的构造函数,根据传入的SqlSessionFactory和ExecutorType创建一个Spring管理的SqlSession,并生成SqlSession的动 ...

  3. JDK1.5以后的版本特性

    一.JDK1.5新特性 1.泛型:泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法.可以在编译的时候就能 ...

  4. Java Web之Http协议

    为什么会出现HTTP协议?有什么用? 浏览器和服务器之间进行数据的沟通的时候,需要标准,浏览器有Chrome浏览器,火狐浏览器,IE浏览器等.服务器有Tomcat服务器,IIS服务器等,由于各自标准不 ...

  5. "Error 0162 - Setup data integrity check failure" after updating BIOS via Thinkvantage

    Start the computer and start pressing F1 and get into set up. In setup press F9 for default settings ...

  6. sqlserver修改计算机名称。

    SELECT @@SERVERNAME As [@@SERVERNAME], CAST(SERVERPROPERTY('MACHINENAME') AS VARCHAR(128)) + COALESC ...

  7. Hadoop记录-技术网站

    Grafan监控:http://docs.grafana.org/ Tez:http://tez.apache.org/install.html 阿里巴巴镜像:https://opsx.alibaba ...

  8. 【1】【leetcode-77】 组合

    (典型,做过似曾相识但不熟悉,基本知道怎么做但调试了一个多小时各种错) 给定两个整数 n 和 k,返回 1 ... n 中所有可能的 k 个数的组合. 示例: 输入: n = 4, k = 2 输出: ...

  9. java基础之自定义异常类及throw和throws的区别

    一.异常的架构: Throwable类:所以异常类都是Throwable的子类,它派生两个子类 Error和Exception. Error类:表示仅靠程序本身无法恢复的的严重错误,比如内存溢出,虚拟 ...

  10. 二十一、Linux 进程与信号---进程查看和进程状态、进程调度和进程状态变化、进程标识

    21.1 进程查看和进程状态 21.1.1 ps 指令 ps 指令通常可以查看到进程的 ID.进程的用户 ID.进程状态和进程的 Command ps:查看当前用户启动的进程 ps -ef:详细查看后 ...