当前位置:   article > 正文

zynq linux系统上通过寄存器读写直接调用HLS IP_zynq vdma寄存器

zynq vdma寄存器

以一个向量加法的HLS IP为例:
linux应用程序代码如下

/*
 * Copyright (c) 2012 Xilinx, Inc.  All rights reserved.
 *
 * Xilinx, Inc.
 * XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
 * COURTESY TO YOU.  BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
 * ONE POSSIBLE   IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
 * STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
 * IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
 * FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
 * XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
 * THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
 * ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
 * FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 */
#include<stdio.h>
#include<unistd.h>
#include<sys/mman.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include"xadder_hw.h"
#define CTRL_BASE_ADDR 0x43c00000
#define A_BASE_ADDR 0x05000000
#define B_BASE_ADDR 0x06000000
#define C_BASE_ADDR 0X07000000
#define SIZE 4096
int main()
{
    int i;
    int devmem;
    int *a_addr;
    int *b_addr;
    int *c_addr;
    int *ctrl_addr;
    devmem = open("/dev/mem", O_RDWR | O_SYNC);
    if(devmem==-1)
    	printf("open /dev/mem failed\n");
    a_addr=(int*)mmap(0,SIZE*sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,devmem,A_BASE_ADDR);
    if(a_addr == MAP_FAILED)
    	printf("a_addr map failed\n");
    b_addr=(int*)mmap(0,SIZE*sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,devmem,B_BASE_ADDR);
    if(b_addr == MAP_FAILED)
        	printf("b_addr map failed\n");
    c_addr=(int*)mmap(0,SIZE*sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,devmem,C_BASE_ADDR);
    if(c_addr == MAP_FAILED)
        	printf("c_addr map failed\n");
    ctrl_addr=(int*)mmap(0,SIZE*sizeof(int),PROT_READ|PROT_WRITE,MAP_SHARED,devmem,CTRL_BASE_ADDR);
    if(ctrl_addr==MAP_FAILED)
    	    printf("ctrl_addr map failed\n");
    for(i=0;i<100;i++)
    {
    	*(a_addr+i)=2*i;
    	*(b_addr+i)=100-i;
    	*(c_addr+i)=0;
    }

    printf("test start\n");
    *(volatile int*)((int)ctrl_addr+XADDER_CTRL_ADDR_A_R_DATA)=A_BASE_ADDR;
    *(volatile int*)((int)ctrl_addr+XADDER_CTRL_ADDR_B_R_DATA)=B_BASE_ADDR;
    *(volatile int*)((int)ctrl_addr+XADDER_CTRL_ADDR_C_R_DATA)=C_BASE_ADDR;
    *(volatile int*)((int)ctrl_addr+XADDER_CTRL_ADDR_AP_CTRL)=0x1;               //start
    while(1){
    	int data=*(volatile int*)((int)ctrl_addr+XADDER_CTRL_ADDR_AP_CTRL);
    	if(((data>>1)&0x01)==1)
    		break;
    }
    printf("PL compute finished\n");
    for(i=0;i<100;i++)
    	printf("%d+%d=%d\n",*(a_addr+i),*(b_addr+i),*(c_addr+i));
    printf("end\n");
    return 0;
}


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77

头文件xadder_hw.h中定义了HLS IP各个寄存器的偏移:

// ==============================================================
// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC
// Version: 2017.3
// Copyright (C) 1986-2017 Xilinx, Inc. All Rights Reserved.
// 
// ==============================================================

// CTRL
// 0x00 : Control signals
//        bit 0  - ap_start (Read/Write/COH)
//        bit 1  - ap_done (Read/COR)
//        bit 2  - ap_idle (Read)
//        bit 3  - ap_ready (Read)
//        bit 7  - auto_restart (Read/Write)
//        others - reserved
// 0x04 : Global Interrupt Enable Register
//        bit 0  - Global Interrupt Enable (Read/Write)
//        others - reserved
// 0x08 : IP Interrupt Enable Register (Read/Write)
//        bit 0  - Channel 0 (ap_done)
//        bit 1  - Channel 1 (ap_ready)
//        others - reserved
// 0x0c : IP Interrupt Status Register (Read/TOW)
//        bit 0  - Channel 0 (ap_done)
//        bit 1  - Channel 1 (ap_ready)
//        others - reserved
// 0x10 : Data signal of a_r
//        bit 31~0 - a_r[31:0] (Read/Write)
// 0x14 : reserved
// 0x18 : Data signal of b_r
//        bit 31~0 - b_r[31:0] (Read/Write)
// 0x1c : reserved
// 0x20 : Data signal of c_r
//        bit 31~0 - c_r[31:0] (Read/Write)
// 0x24 : reserved
// (SC = Self Clear, COR = Clear on Read, TOW = Toggle on Write, COH = Clear on Handshake)

#define XADDER_CTRL_ADDR_AP_CTRL  0x00
#define XADDER_CTRL_ADDR_GIE      0x04
#define XADDER_CTRL_ADDR_IER      0x08
#define XADDER_CTRL_ADDR_ISR      0x0c
#define XADDER_CTRL_ADDR_A_R_DATA 0x10
#define XADDER_CTRL_BITS_A_R_DATA 32
#define XADDER_CTRL_ADDR_B_R_DATA 0x18
#define XADDER_CTRL_BITS_B_R_DATA 32
#define XADDER_CTRL_ADDR_C_R_DATA 0x20
#define XADDER_CTRL_BITS_C_R_DATA 32


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

而首地址为0x43c00000,可从system.hdf中查找到
在这里插入图片描述
最终上板运行结果正确无误:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/寸_铁/article/detail/744680
推荐阅读
相关标签
  

闽ICP备14008679号