Line 1... |
Line 1... |
|
////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Filename: qtrstage_tb.cpp
|
|
//
|
|
// Project: A Doubletime Pipelined FFT
|
|
//
|
|
// Purpose: A test-bench for the qtrstage.v subfile of the double
|
|
// clocked FFT. This file may be run autonomously. If so,
|
|
// the last line output will either read "SUCCESS" on success,
|
|
// or some other failure message otherwise.
|
|
//
|
|
// This file depends upon verilator to both compile, run, and
|
|
// therefore test qtrstage.v
|
|
//
|
|
// Creator: Dan Gisselquist, Ph.D.
|
|
// Gisselquist Tecnology, LLC
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2015, Gisselquist Technology, LLC
|
|
//
|
|
// This program is free software (firmware): you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License as published
|
|
// by the Free Software Foundation, either version 3 of the License, or (at
|
|
// your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
// for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along
|
|
// with this program. (It's in the $(ROOT)/doc directory, run make with no
|
|
// target there if the PDF file isn't present.) If not, see
|
|
// <http://www.gnu.org/licenses/> for a copy.
|
|
//
|
|
// License: GPL, v3, as defined and found on www.gnu.org,
|
|
// http://www.gnu.org/licenses/gpl.html
|
|
//
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdint.h>
|
#include <stdint.h>
|
|
|
#include "Vqtrstage.h"
|
#include "Vqtrstage.h"
|
#include "verilated.h"
|
#include "verilated.h"
|
|
|
|
#define IWIDTH 16
|
|
#define OWIDTH (IWIDTH+1)
|
|
#define LGWIDTH 8
|
|
|
void tick(Vqtrstage *qstage) {
|
void tick(Vqtrstage *qstage) {
|
qstage->i_clk = 0;
|
qstage->i_clk = 0;
|
qstage->eval();
|
qstage->eval();
|
qstage->i_clk = 1;
|
qstage->i_clk = 1;
|
qstage->eval();
|
qstage->eval();
|
Line 28... |
Line 73... |
int32_t smr, smi, dfr, dfi;
|
int32_t smr, smi, dfr, dfi;
|
int rnd = 0;
|
int rnd = 0;
|
|
|
reset(qstage);
|
reset(qstage);
|
|
|
for(int k=0; k<270; k++) {
|
for(int k=0; k<1060; k++) {
|
int32_t or0, oi0, or1, oi1;
|
int32_t or0, oi0, or1, oi1;
|
|
|
qstage->i_ce = 1;
|
qstage->i_ce = 1;
|
qstage->i_sync = ((k&0x0ff)==0);
|
qstage->i_sync = ((k&0x0ff)==0);
|
// Let's pick some random values, ...
|
// Let's pick some random values, ...
|
Line 40... |
Line 85... |
ii0 = rand(); if (ii0&2) ii0 = -ii0;
|
ii0 = rand(); if (ii0&2) ii0 = -ii0;
|
|
|
qstage->i_data = ((ir0&0x0ffff) << 16) | (ii0 & 0x0ffff);
|
qstage->i_data = ((ir0&0x0ffff) << 16) | (ii0 & 0x0ffff);
|
tick(qstage);
|
tick(qstage);
|
|
|
printf("k=%3d: ISYNC=%d, IN = %08x, OUT =%09lx, SYNC=%d\n",
|
printf("k=%4d: ISYNC=%d, IN = %08x, OUT =%09lx, SYNC=%d\n",
|
k, qstage->i_sync, qstage->i_data,
|
k, qstage->i_sync, qstage->i_data,
|
qstage->o_data, qstage->o_sync);
|
qstage->o_data, qstage->o_sync);
|
|
|
or0 = (qstage->o_data >> 17) & 0x01ffff;
|
or0 = (qstage->o_data >> 17) & 0x01ffff;
|
oi0 = qstage->o_data & 0x01ffff;
|
oi0 = qstage->o_data & 0x01ffff;
|
Line 63... |
Line 108... |
if (or0 != difr) {fprintf(stderr, "FAIL 3\n"); exit(-1);}
|
if (or0 != difr) {fprintf(stderr, "FAIL 3\n"); exit(-1);}
|
if (oi0 != difi) {fprintf(stderr, "FAIL 4\n"); exit(-1);}
|
if (oi0 != difi) {fprintf(stderr, "FAIL 4\n"); exit(-1);}
|
}
|
}
|
}
|
}
|
|
|
if (((4==(k&0x0ff))?1:0) != qstage->o_sync) { fprintf(stderr, "BAD O-SYNC\n"); exit(-1); }
|
if (((4==(k&0x07f))?1:0) != qstage->o_sync) { fprintf(stderr, "BAD O-SYNC\n"); exit(-1); }
|
|
|
if (1 == (k&1)) {
|
if (1 == (k&1)) {
|
sumr = smr; sumi = smi; difr=dfr, difi= dfi;
|
sumr = smr; sumi = smi; difr=dfr, difi= dfi;
|
|
|
smr = lstr + ir0 + rnd;
|
smr = lstr + ir0 + rnd;
|