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

Subversion Repositories wbscope

[/] [wbscope/] [trunk/] [bench/] [cpp/] [wbscope_tb.cpp] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    wbscope_tb.cpp
4
//
5
// Project:     WBScope, a wishbone hosted scope
6
//
7
// Purpose:     A quick test bench to determine if the wbscope module works.
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
#include <stdio.h>
39
 
40
#include <verilated.h>
41
#include <verilated_vcd_c.h>
42 13 dgisselq
#include "Vwbscope_tb.h"
43 12 dgisselq
#include "testb.h"
44 13 dgisselq
#define INTERRUPTWIRE   o_interrupt
45
#include "wb_tb.h"
46 12 dgisselq
 
47 13 dgisselq
const int       LGMEMSIZE = 15;
48 12 dgisselq
 
49 13 dgisselq
class   WBSCOPE_TB : public WB_TB<Vwbscope_tb> {
50
        bool            m_bomb, m_debug;
51 12 dgisselq
public:
52
 
53
        WBSCOPE_TB(void) {
54
                m_debug = true;
55
        }
56
 
57
        void    tick(void) {
58
 
59 13 dgisselq
                WB_TB<Vwbscope_tb>::tick();
60 12 dgisselq
 
61
                bool    writeout = true;
62
                if ((m_debug)&&(writeout)) {}
63
        }
64
 
65
        void reset(void) {
66
                m_core->i_rst    = 1;
67
                m_core->i_wb_cyc = 0;
68
                m_core->i_wb_stb = 0;
69
                tick();
70
                m_core->i_rst  = 0;
71
        }
72
 
73
        unsigned        trigger(void) {
74
                m_core->i_trigger = 1;
75 13 dgisselq
                idle();
76 12 dgisselq
                m_core->i_trigger = 0;
77
                return m_core->o_data;
78
        }
79
 
80
        bool    debug(void) const { return m_debug; }
81
        bool    debug(bool nxtv) { return m_debug = nxtv; }
82
};
83
 
84
int main(int  argc, char **argv) {
85
        Verilated::commandArgs(argc, argv);
86
        WBSCOPE_TB      *tb = new WBSCOPE_TB;
87
        unsigned        v;
88
        unsigned *buf;
89
        int     trigpt;
90 13 dgisselq
        unsigned        trigger_time, expected_first_value;
91 12 dgisselq
 
92
        tb->opentrace("wbscope_tb.vcd");
93
        printf("Giving the core 2 cycles to start up\n");
94
        // Before testing, let's give the unit time enough to warm up
95
        tb->reset();
96 13 dgisselq
        tb->idle(2);
97 12 dgisselq
 
98
#define WBSCOPE_STATUS  0
99
#define WBSCOPE_DATA    4
100
#define WBSCOPE_NORESET 0x80000000
101
#define WBSCOPE_TRIGGER (WBSCOPE_NO_RESET|0x08000000)
102
#define WBSCOPE_MANUAL  (WBSCOPE_TRIGGER)
103
#define WBSCOPE_PRIMED  0x10000000
104
#define WBSCOPE_TRIGGERED 0x20000000
105
#define WBSCOPE_STOPPED 0x40000000
106
#define WBSCOPE_DISABLED  0x04000000
107
#define WBSCOPE_LGLEN(A)        ((A>>20)&0x01f)
108
#define WBSCOPE_LENGTH(A)       (1<<(LGLEN(A)))
109
 
110
        // First test ... read the status register
111 13 dgisselq
        v = tb->readio(WBSCOPE_STATUS);
112 12 dgisselq
        int ln = WBSCOPE_LGLEN(v);
113
        printf("V   = %08x\n", v);
114
        printf("LN  = %d, or %d entries\n", ln, (1<<ln));
115
        printf("DLY = %d\n", (v&0xfffff));
116
        if (((1<<ln) < tb->m_tickcount)&&(v&0x10000000)) {
117
                printf("SCOPE is already triggered! ??\n");
118
                goto test_failure;
119
        }
120
        buf = new unsigned[(1<<ln)];
121
 
122 13 dgisselq
        tb->idle(1<<ln);
123 12 dgisselq
 
124 13 dgisselq
        v = tb->readio(WBSCOPE_STATUS);
125 12 dgisselq
        if ((v&WBSCOPE_PRIMED)==0) {
126
                printf("v = %08x\n", v);
127
                printf("SCOPE hasn\'t primed! ??\n");
128
                goto test_failure;
129
        }
130
 
131 13 dgisselq
        trigger_time = tb->trigger() & 0x7fffffff;
132
        printf("TRIGGERED AT %08x\n", trigger_time);
133
 
134
        v = tb->readio(WBSCOPE_STATUS);
135 12 dgisselq
        if ((v&WBSCOPE_TRIGGERED)==0) {
136
                printf("v = %08x\n", v);
137
                printf("SCOPE hasn\'t triggered! ??\n");
138
                goto test_failure;
139
        }
140
 
141
        while((v & WBSCOPE_STOPPED)==0)
142 13 dgisselq
                v = tb->readio(WBSCOPE_STATUS);
143 12 dgisselq
        printf("SCOPE has stopped, reading data\n");
144
 
145 13 dgisselq
        tb->readz(WBSCOPE_DATA, (1<<ln), buf);
146 12 dgisselq
        for(int i=0; i<(1<<ln); i++) {
147 13 dgisselq
                printf("%4d: %08x%s\n", i, buf[i],
148
                        (i== (1<<ln)-1-(v&0x0fffff)) ? " <<--- TRIGGER!":"");
149
                if ((i>0)&&(((buf[i]&0x7fffffff)-(buf[i-1]&0x7fffffff))!=1)) {
150
                        printf("ERR: Scope data doesn't increment!\n");
151
                        printf("\tIn other words--its not matching the test signal\n");
152 12 dgisselq
                        goto test_failure;
153 13 dgisselq
                }
154 12 dgisselq
        }
155
 
156 13 dgisselq
        trigpt = (1<<ln)-v&(0x0fffff)-1;
157 12 dgisselq
        if ((trigpt >= 0)&&(trigpt < (1<<ln))) {
158
                printf("Trigger value = %08x\n", buf[trigpt]);
159
                if (((0x80000000 & buf[trigpt])==0)&&(trigpt>0)) {
160
                        printf("Pre-Trigger value = %08x\n", buf[trigpt-1]);
161
                        if ((buf[trigpt-1]&0x80000000)==0) {
162
                                printf("TRIGGER NOT FOUND\n");
163
                                goto test_failure;
164
                        }
165
                }
166
        }
167
 
168 13 dgisselq
        expected_first_value = trigger_time + (v&0x0fffff) - (1<<ln);
169
        if (buf[0] != expected_first_value) {
170
                printf("Initial value = %08x\n", buf[0]);
171
                printf("Expected:     %08x\n", expected_first_value);
172
                printf("ERR: WRONG STARTING-VALUE\n");
173
                goto test_failure;
174
        }
175
 
176 12 dgisselq
        printf("SUCCESS!!\n");
177
        delete tb;
178
        exit(0);
179
test_failure:
180
        printf("FAIL-HERE\n");
181
        for(int i=0; i<4; i++)
182
                tb->tick();
183
        printf("TEST FAILED\n");
184
        delete tb;
185
        exit(-1);
186
}

powered by: WebSVN 2.1.0

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