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

Subversion Repositories dblclockfft

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

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
        int             rnd = 0;
75
 
76
        reset(qstage);
77
 
78 6 dgisselq
        for(int k=0; k<1060; k++) {
79 3 dgisselq
                int32_t or0, oi0, or1, oi1;
80
 
81
                qstage->i_ce = 1;
82
                qstage->i_sync = ((k&0x0ff)==0);
83
                // Let's pick some random values, ...
84
                ir0 = rand(); if (ir0&4) ir0 = -ir0;
85
                ii0 = rand(); if (ii0&2) ii0 = -ii0;
86
 
87
                qstage->i_data  = ((ir0&0x0ffff) << 16) | (ii0 & 0x0ffff);
88
                tick(qstage);
89
 
90 6 dgisselq
                printf("k=%4d: ISYNC=%d, IN = %08x, OUT =%09lx, SYNC=%d\n",
91 3 dgisselq
                        k, qstage->i_sync, qstage->i_data,
92
                        qstage->o_data, qstage->o_sync);
93
 
94
                or0 = (qstage->o_data  >> 17) & 0x01ffff;
95
                oi0 =  qstage->o_data         & 0x01ffff;
96
                if (or0 & 0x010000)     or0 |= (-1<<16);
97
                if (oi0 & 0x010000)     oi0 |= (-1<<16);
98
 
99
                if (k>3) {
100
                        /*
101
                        printf("\tOR0 = %6x, OI0 = %6x, SUM = %6x + %6x, DIF = %6x + %6x\n",
102
                                or0, oi0, sumr, sumi, difr, difi);
103
                        */
104
                        if (0==(k&1)) {
105
                                if (or0 != sumr)        {fprintf(stderr, "FAIL 1\n"); exit(-1);}
106
                                if (oi0 != sumi)        {fprintf(stderr, "FAIL 2\n"); exit(-1);}
107
                        } else if (1==(k&1)) {
108
                                if (or0 != difr)        {fprintf(stderr, "FAIL 3\n"); exit(-1);}
109
                                if (oi0 != difi)        {fprintf(stderr, "FAIL 4\n"); exit(-1);}
110
                        }
111
                }
112
 
113 6 dgisselq
                if (((4==(k&0x07f))?1:0) != qstage->o_sync) { fprintf(stderr, "BAD O-SYNC\n"); exit(-1); }
114 3 dgisselq
 
115
                if (1 == (k&1)) {
116
                        sumr = smr; sumi = smi; difr=dfr, difi= dfi;
117
 
118
                        smr = lstr + ir0 + rnd;
119
                        smi = lsti + ii0 + rnd;
120
 
121
                        dfr = lstr - ir0 + rnd;
122
                        dfi = lsti - ii0 + rnd;
123
                }
124
 
125
                lstr = ir0;
126
                lsti = ii0;
127
        }
128
 
129
        delete  qstage;
130
 
131 4 dgisselq
        printf("SUCCESS!\n");
132 3 dgisselq
        exit(0);
133
}

powered by: WebSVN 2.1.0

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