赞
踩
以一个向量加法的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; }
头文件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
而首地址为0x43c00000,可从system.hdf中查找到
最终上板运行结果正确无误:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。