OpenCores
URL https://opencores.org/ocsvn/dblclockfft/dblclockfft/trunk

Subversion Repositories dblclockfft

[/] [dblclockfft/] [trunk/] [bench/] [cpp/] [qtrstage_tb.cpp] - Blame information for rev 19

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 dgisselq
////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    qtrstage_tb.cpp
4
//
5
// Project:     A Doubletime Pipelined FFT
6
//
7
// Purpose:     A test-bench for the qtrstage.v subfile of the double
8
//              clocked FFT.  This file may be run autonomously.  If so,
9
//              the last line output will either read "SUCCESS" on success,
10
//              or some other failure message otherwise.
11
//
12
//              This file depends upon verilator to both compile, run, and
13
//              therefore test qtrstage.v
14
//
15
// Creator:     Dan Gisselquist, Ph.D.
16
//              Gisselquist Tecnology, LLC
17
//
18
///////////////////////////////////////////////////////////////////////////
19
//
20
// Copyright (C) 2015, Gisselquist Technology, LLC
21
//
22
// This program is free software (firmware): you can redistribute it and/or
23
// modify it under the terms of  the GNU General Public License as published
24
// by the Free Software Foundation, either version 3 of the License, or (at
25
// your option) any later version.
26
//
27
// This program is distributed in the hope that it will be useful, but WITHOUT
28
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
29
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
30
// for more details.
31
//
32
// You should have received a copy of the GNU General Public License along
33
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
34
// target there if the PDF file isn't present.)  If not, see
35
// <http://www.gnu.org/licenses/> for a copy.
36
//
37
// License:     GPL, v3, as defined and found on www.gnu.org,
38
//              http://www.gnu.org/licenses/gpl.html
39
//
40
//
41
///////////////////////////////////////////////////////////////////////////
42 3 dgisselq
#include <stdio.h>
43
#include <stdint.h>
44
 
45
#include "Vqtrstage.h"
46
#include "verilated.h"
47
 
48 6 dgisselq
#define IWIDTH  16
49
#define OWIDTH  (IWIDTH+1)
50
#define LGWIDTH 8
51
 
52 3 dgisselq
void    tick(Vqtrstage *qstage) {
53
        qstage->i_clk = 0;
54
        qstage->eval();
55
        qstage->i_clk = 1;
56
        qstage->eval();
57
}
58
 
59
void    reset(Vqtrstage *qstage) {
60
        qstage->i_ce  = 0;
61
        qstage->i_rst = 1;
62
        tick(qstage);
63
        qstage->i_ce  = 0;
64
        qstage->i_rst = 0;
65
        tick(qstage);
66
}
67
 
68
int     main(int argc, char **argv, char **envp) {
69
        Verilated::commandArgs(argc, argv);
70
        Vqtrstage       *qstage = new Vqtrstage;
71
        int16_t         ir0, ii0, lstr, lsti;
72
        int32_t         sumr, sumi, difr, difi;
73
        int32_t         smr, smi, dfr, dfi;
74 15 dgisselq
        int             rnd = 0; // Can only be set to true if OWIDTH=IWIDTH
75 3 dgisselq
 
76 15 dgisselq
        if ((OWIDTH<IWIDTH+1)&&(rnd!=0)) {
77
                fprintf(stderr, "ERR: Rounding can only be applied when\n");
78
                fprintf(stderr, "\tthe output width is less than or equal\n");
79
                fprintf(stderr, "\tto the input width.  Turn rounding off\n");
80
                fprintf(stderr, "\trebuild, and try again.\n");
81
                assert(0 == rnd);
82
        }
83
 
84 3 dgisselq
        reset(qstage);
85
 
86 6 dgisselq
        for(int k=0; k<1060; k++) {
87 3 dgisselq
                int32_t or0, oi0, or1, oi1;
88
 
89
                qstage->i_ce = 1;
90
                qstage->i_sync = ((k&0x0ff)==0);
91
                // Let's pick some random values, ...
92
                ir0 = rand(); if (ir0&4) ir0 = -ir0;
93
                ii0 = rand(); if (ii0&2) ii0 = -ii0;
94
 
95
                qstage->i_data  = ((ir0&0x0ffff) << 16) | (ii0 & 0x0ffff);
96
                tick(qstage);
97
 
98 6 dgisselq
                printf("k=%4d: ISYNC=%d, IN = %08x, OUT =%09lx, SYNC=%d\n",
99 3 dgisselq
                        k, qstage->i_sync, qstage->i_data,
100
                        qstage->o_data, qstage->o_sync);
101
 
102
                or0 = (qstage->o_data  >> 17) & 0x01ffff;
103
                oi0 =  qstage->o_data         & 0x01ffff;
104
                if (or0 & 0x010000)     or0 |= (-1<<16);
105
                if (oi0 & 0x010000)     oi0 |= (-1<<16);
106
 
107
                if (k>3) {
108
                        /*
109
                        printf("\tOR0 = %6x, OI0 = %6x, SUM = %6x + %6x, DIF = %6x + %6x\n",
110
                                or0, oi0, sumr, sumi, difr, difi);
111
                        */
112
                        if (0==(k&1)) {
113
                                if (or0 != sumr)        {fprintf(stderr, "FAIL 1\n"); exit(-1);}
114
                                if (oi0 != sumi)        {fprintf(stderr, "FAIL 2\n"); exit(-1);}
115
                        } else if (1==(k&1)) {
116
                                if (or0 != difr)        {fprintf(stderr, "FAIL 3\n"); exit(-1);}
117
                                if (oi0 != difi)        {fprintf(stderr, "FAIL 4\n"); exit(-1);}
118
                        }
119
                }
120
 
121 6 dgisselq
                if (((4==(k&0x07f))?1:0) != qstage->o_sync) { fprintf(stderr, "BAD O-SYNC\n"); exit(-1); }
122 3 dgisselq
 
123
                if (1 == (k&1)) {
124
                        sumr = smr; sumi = smi; difr=dfr, difi= dfi;
125
 
126
                        smr = lstr + ir0 + rnd;
127
                        smi = lsti + ii0 + rnd;
128
 
129
                        dfr = lstr - ir0 + rnd;
130
                        dfi = lsti - ii0 + rnd;
131
                }
132
 
133
                lstr = ir0;
134
                lsti = ii0;
135
        }
136
 
137
        delete  qstage;
138
 
139 4 dgisselq
        printf("SUCCESS!\n");
140 3 dgisselq
        exit(0);
141
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.