zynq linux驱动之PL-PS中断

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卡的fat分区里(这里没有用的PetaLinux生成的根文件系统,用的是debian8)

接下来打开datasheet

找到中断号是61

然后先到开板上看一下

cat /proc/interrupts

再看看datasheet上

没有问题,中断号都对得上

然后再回到ubuntu里看看设备树

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

发现这里的中断号跟datasheet 和 /proc/interrupt 里面的对不上

仔细观察发现设备树里面的中断号是datasheet的中断号减去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-build编译

编译完成之后

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

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平台上进行PL-PS协同设计时,需要考虑如何将PL中的网口与PS中的网口进行连接。一种常用的方式是使用AXI Ethernet IP核,将PL中的网口接到AXI总线上,然后通过AXI总线与PS中的网口进行连接。 在Linux中使用PL中的网口时,需要进行如下调试步骤: 1. 确认AXI Ethernet IP核已经正确配置,并且在硬件中已经成功实现了网口的功能。 2. 在Linux内核中,需要加载相应的驱动程序。以常见的AXI Ethernet驱动程序axienet为例,可以使用以下命令加载驱动程序: ``` modprobe axienet ``` 3. 确认网口的设备节点已经正确创建。可以使用以下命令查看网口设备节点: ``` ls /sys/class/net ``` 如果成功创建了网口设备节点,应该能够看到类似于eth0、eth1等设备节点。 4. 使用ifconfig命令配置网口IP地址等参数。例如,可以使用以下命令将eth0网口的IP地址设置为192.168.1.100: ``` ifconfig eth0 192.168.1.100 ``` 5. 确认网口是否能够正常工作。可以使用ping命令测试与其他主机的连通性: ``` ping <目标IP地址> ``` 如果能够ping通目标主机,则说明网口已经正确工作。 6. 如果出现网络连接问题,可以使用tcpdump命令进行网络抓包分析,以便确定问题的原因: ``` tcpdump -i eth0 ``` 这将在eth0网口上抓取所有的网络数据包,并将它们输出到屏幕上。可以使用Ctrl+C停止抓包,并分析输出的数据包内容以确定问题的原因。 以上就是在ZYNQ平台上使用PL中的网口进行Linux开发时常见的调试步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值