????????Vitis?HLS 2021.2
? ? ? ? Windows 10
? ? ? ? 什么是块级I/O协议和如何去使用它们。
# 重置和创建工程
open_project -reset adders_prj
# 添加源文件
add_files src/adders.cpp
add_files src/adders.hpp
# 添加测试文件
add_files -tb src/adders_test.cpp
# 设置顶层函数
set_top adders
# 创建解决方案
open_solution -reset solution1
# 设置使用芯片
set_part {xc7z020-clg400-2}
# 这是时钟频率
create_clock -period 10 -name default
# 源码仿真
csim_design
退出HLS
exit
/*******adders.hpp******/
#ifndef ADDERS_H_
#define ADDERS_H_
int adders(int in1, int in2, int in3);
#endif
/*******adders.cpp******/
#include "adders.hpp"
int adders(int in1, int in2, int in3) {
#pragma HLS INTERFACE ap_ctrl_none port=return
// Prevent IO protocols on all input ports
#pragma HLS INTERFACE ap_none port=in3
#pragma HLS INTERFACE ap_none port=in2
#pragma HLS INTERFACE ap_none port=in1
int sum;
sum = in1 + in2 + in3;
return sum;
}
/*******adders_test.cpp******/
#include <stdio.h>
#include "adders.hpp"
int main()
{
int inA, inB, inC;
int sum;
int refOut[5] = {60, 90, 120, 150, 180};
int pass;
int i;
inA = 10;
inB = 20;
inC = 30;
for (i=0; i<5; i++)
{
sum = adders(inA, inB, inC);
fprintf(stdout, " %d+%d+%d=%d \n", inA, inB, inC, sum);
if (sum == refOut[i])
pass = 1;
else
pass = 0;
inA=inA+10;
inB=inB+10;
inC=inC+10;
}
if (pass)
{
fprintf(stdout, "----------Pass!------------\n");
return 0;
}
else
{
fprintf(stderr, "----------Fail!------------\n");
return 1;
}
}