2)此时可以查看源文件(fir.c)和testbench(fir_test.c)文件,还可以看到out.gold.dat文件,此文件为标准的输出结果,用于对比验证。
注意,fir.c中的函数名fir即为将要生成的IP的名称,必须相同
3)选择run c Simulation进行逻辑验证。此步骤可以验证程序的语法、功能等问题。但是调试功能不强,因此建议最好先在外面验证好代码的正确性,再在HLS中进行操作。
验证后,出现下图,说明验证成功。
2. fir原理介绍和源程序分析
4)fir原理介绍
5)fir.c程序分析
[cpp] view plaincopy
#include "fir.h"
void fir (
data_t *y,
coef_t c[N],
data_t x
) {
#pragma HLS INTERFACE ap_vld port=y
#pragma HLS INTERFACE ap_vld port=x
#pragma HLS RESOURCE variable=c core=RAM_1P_BRAM //for array,generally BRAM
static data_t shift_reg[N];
#pragma HLS ARRAY_PARTITION variable=shift_reg complete dim=1
// Creates an additional valid port (
_vld) to operate in conjunction with this data port
// For input ports, a read stalls the function until its associated input valid port is asserted.
// An output port has its output valid signal asserted when it writes data
acc_t acc;
data_t data;
int i;acc=0;
Shift_Accum_Loop:
for (i=N-1;i>=0;i--)
{
#pragma HLS UNROLL
if (i==0)
{
shift_reg[0]=x;
data = x;
} else
{
shift_reg=shift_reg[i-1];
data = shift_reg;
}
acc+=data*c;;
}
*y=acc;
}
这里给出了fir数据存储的图,最新的数据将把最老的数据挤出,然后缓冲区的数据和系数矩阵相乘加和得到一个输出结果。
如果上图不是很清晰,博主给出了开始自己的分析图,很傻却能说明问题:
6)fir_test.c程序分析
testbench用于测试fir模块的正确性。本例选取的600个采样点进行测试,数据为:从0到+75,再到-75,再到+75,再到-75,以此类推,间隔为1.把fir的结果和一个标准结果文件out.gold.dat进行比较,如果相同,说明程序正确。
[cpp] view plaincopy
#include
#include
#include "fir.h"
int main () {
const int SAMPLES=600; //number of samples
FILE *fp;
data_t signal, output;
coef_t taps[N] = {0,-10,-9,23,56,63,56,23,-9,-10,0,}; //
int i, ramp_up;
signal = 0;
ramp_up = 1;
fp=fopen("out.dat","w");
for (i=0;i<=SAMPLES;i++) //signal is: 0-(+75)-(-75)-(+75)-(-75)-...step=1
{
if (ramp_up == 1)
signal = signal + 1;
else
signal = signal - 1;
// Execute the function with latest input
fir(&output,taps,signal);
if ((ramp_up == 1) && (signal >= 75))
ramp_up = 0;
else if ((ramp_up == 0) && (signal <= -75))
ramp_up = 1;
// Save the results.
fprintf(fp,"%i %d %d\n",i,signal,output);
}
fclose(fp);
printf ("Comparing against output data \n"); //compare the standard output and the result
if (system("diff -w out.dat out.gold.dat")) {
fprintf(stdout, "*******************************************\n");
fprintf(stdout, "FAIL: Output DOES NOT match the golden output\n");
fprintf(stdout, "*******************************************\n");
return 1;
} else {
fprintf(stdout, "*******************************************\n");
fprintf(stdout, "PASS: The output matches the golden output!\n");
fprintf(stdout, "*******************************************\n");
return 0;
}
}
3. 导出IP
选择export RTL,导出格式选择IP Catalog。