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

Subversion Repositories wbscope

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

Go to most recent revision | 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
#include "testb.h"
43
#include "Vwbscope_tb.h"
44
 
45
#define MMUFLAG_RONW    8 // Read only (not writeable)
46
#define MMUFLAG_ACCS    4 // Accessed
47
#define MMUFLAG_CCHE    2 // Cachable
48
#define MMUFLAG_THSP    1 // Page has this context
49
 
50
const int       BOMBCOUNT = 32,
51
                LGMEMSIZE = 15;
52
 
53
class   WBSCOPE_TB : public TESTB<Vwbscope_tb> {
54
        bool            m_bomb, m_miss, m_err, m_debug;
55
        int             m_last_tlb_index;
56
public:
57
 
58
        WBSCOPE_TB(void) {
59
                m_debug = true;
60
                m_last_tlb_index = 0;
61
        }
62
 
63
        void    tick(void) {
64
 
65
                TESTB<Vwbscope_tb>::tick();
66
 
67
                bool    writeout = true;
68
                if ((m_debug)&&(writeout)) {}
69
        }
70
 
71
        void reset(void) {
72
                m_core->i_rst    = 1;
73
                m_core->i_wb_cyc = 0;
74
                m_core->i_wb_stb = 0;
75
                tick();
76
                m_core->i_rst  = 0;
77
        }
78
 
79
        void wb_tick(void) {
80
                m_core->i_wb_cyc  = 0;
81
                m_core->i_wb_stb  = 0;
82
                tick();
83
                assert(!m_core->o_wb_ack);
84
        }
85
 
86
        unsigned wb_read(unsigned a) {
87
                unsigned        result;
88
 
89
                printf("WB-READM(%08x)\n", a);
90
 
91
                m_core->i_wb_cyc = 1;
92
                m_core->i_wb_stb = 1;
93
                m_core->i_wb_we  = 0;
94
                m_core->i_wb_addr= (a>>2)&1;
95
 
96
                // Dont need to check for stalls, since the wbscope never stalls
97
                tick();
98
 
99
                m_core->i_wb_stb = 0;
100
 
101
                while(!m_core->o_wb_ack)
102
                        tick();
103
 
104
                result = m_core->o_wb_data;
105
 
106
                // Release the bus?
107
                m_core->i_wb_cyc = 0;
108
                m_core->i_wb_stb = 0;
109
 
110
                // Let the bus idle for one cycle
111
                tick();
112
 
113
                return result;
114
        }
115
 
116
        void    wb_read(unsigned a, int len, unsigned *buf) {
117
                int             cnt, rdidx;
118
 
119
                printf("WB-READM(%08x, %d)\n", a, len);
120
 
121
                m_core->i_wb_cyc = 1;
122
                m_core->i_wb_stb = 1;
123
                m_core->i_wb_we   = 0;
124
                m_core->i_wb_addr = (a>>2)&1;
125
 
126
                rdidx =0; cnt = 0;
127
 
128
                do {
129
                        tick();
130
                        // Normally, we'd increment the address here.  For the
131
                        // scope, multiple reads only make sense if they are 
132
                        // from the same address, hence we don't increment the
133
                        // address here
134
                        // m_core->i_wb_addr += inc;
135
                        cnt += 1;
136
                        if (m_core->o_wb_ack)
137
                                buf[rdidx++] = m_core->o_wb_data;
138
                } while(cnt < len);
139
 
140
                m_core->i_wb_stb = 0;
141
 
142
                while(rdidx < len) {
143
                        tick();
144
                        if (m_core->o_wb_ack)
145
                                buf[rdidx++] = m_core->o_wb_data;
146
                }
147
 
148
                // Release the bus?
149
                m_core->i_wb_cyc = 0;
150
 
151
                tick();
152
                assert(!m_core->o_wb_ack);
153
        }
154
 
155
        void    wb_write(unsigned a, unsigned v) {
156
                int errcount = 0;
157
 
158
                printf("WB-WRITEM(%08x) <= %08x\n", a, v);
159
                m_core->i_wb_cyc = 1;
160
                m_core->i_wb_stb = 1;
161
                m_core->i_wb_we  = 1;
162
                m_core->i_wb_addr= (a>>2)&1;
163
                m_core->i_wb_data= v;
164
 
165
                tick();
166
                m_core->i_wb_stb = 0;
167
 
168
                while(!m_core->o_wb_ack) {
169
                        tick();
170
                }
171
 
172
                tick();
173
 
174
                // Release the bus?
175
                m_core->i_wb_cyc = 0;
176
                m_core->i_wb_stb = 0;
177
 
178
                assert(!m_core->o_wb_ack);
179
        }
180
 
181
        unsigned        trigger(void) {
182
                m_core->i_trigger = 1;
183
                wb_tick();
184
                m_core->i_trigger = 0;
185
                printf("TRIGGERED AT %08x\n", m_core->o_data);
186
                return m_core->o_data;
187
        }
188
 
189
        bool    debug(void) const { return m_debug; }
190
        bool    debug(bool nxtv) { return m_debug = nxtv; }
191
};
192
 
193
int main(int  argc, char **argv) {
194
        Verilated::commandArgs(argc, argv);
195
        WBSCOPE_TB      *tb = new WBSCOPE_TB;
196
        unsigned        v;
197
        unsigned *buf;
198
        int     trigpt;
199
 
200
        tb->opentrace("wbscope_tb.vcd");
201
        printf("Giving the core 2 cycles to start up\n");
202
        // Before testing, let's give the unit time enough to warm up
203
        tb->reset();
204
        for(int i=0; i<2; i++)
205
                tb->wb_tick();
206
 
207
#define WBSCOPE_STATUS  0
208
#define WBSCOPE_DATA    4
209
#define WBSCOPE_NORESET 0x80000000
210
#define WBSCOPE_TRIGGER (WBSCOPE_NO_RESET|0x08000000)
211
#define WBSCOPE_MANUAL  (WBSCOPE_TRIGGER)
212
#define WBSCOPE_PRIMED  0x10000000
213
#define WBSCOPE_TRIGGERED 0x20000000
214
#define WBSCOPE_STOPPED 0x40000000
215
#define WBSCOPE_DISABLED  0x04000000
216
#define WBSCOPE_LGLEN(A)        ((A>>20)&0x01f)
217
#define WBSCOPE_LENGTH(A)       (1<<(LGLEN(A)))
218
 
219
        // First test ... read the status register
220
        v = tb->wb_read(WBSCOPE_STATUS);
221
        int ln = WBSCOPE_LGLEN(v);
222
        printf("V   = %08x\n", v);
223
        printf("LN  = %d, or %d entries\n", ln, (1<<ln));
224
        printf("DLY = %d\n", (v&0xfffff));
225
        if (((1<<ln) < tb->m_tickcount)&&(v&0x10000000)) {
226
                printf("SCOPE is already triggered! ??\n");
227
                goto test_failure;
228
        }
229
        buf = new unsigned[(1<<ln)];
230
 
231
        for(int i=0; i<(1<<ln); i++)
232
                tb->wb_tick();
233
 
234
        v = tb->wb_read(WBSCOPE_STATUS);
235
        if ((v&WBSCOPE_PRIMED)==0) {
236
                printf("v = %08x\n", v);
237
                printf("SCOPE hasn\'t primed! ??\n");
238
                goto test_failure;
239
        }
240
 
241
        tb->trigger();
242
        v = tb->wb_read(WBSCOPE_STATUS);
243
        if ((v&WBSCOPE_TRIGGERED)==0) {
244
                printf("v = %08x\n", v);
245
                printf("SCOPE hasn\'t triggered! ??\n");
246
                goto test_failure;
247
        }
248
 
249
        while((v & WBSCOPE_STOPPED)==0)
250
                v = tb->wb_read(WBSCOPE_STATUS);
251
        printf("SCOPE has stopped, reading data\n");
252
 
253
        tb->wb_read(WBSCOPE_DATA, (1<<ln), buf);
254
        for(int i=0; i<(1<<ln); i++) {
255
                printf("%4d: %08x\n", i, buf[i]);
256
                if ((i>0)&&(((buf[i]&0x7fffffff)-(buf[i-1]&0x7fffffff))!=1))
257
                        goto test_failure;
258
        }
259
 
260
        trigpt = (1<<ln)-v&(0x0fffff);
261
        if ((trigpt >= 0)&&(trigpt < (1<<ln))) {
262
                printf("Trigger value = %08x\n", buf[trigpt]);
263
                if (((0x80000000 & buf[trigpt])==0)&&(trigpt>0)) {
264
                        printf("Pre-Trigger value = %08x\n", buf[trigpt-1]);
265
                        if ((buf[trigpt-1]&0x80000000)==0) {
266
                                printf("TRIGGER NOT FOUND\n");
267
                                goto test_failure;
268
                        }
269
                }
270
        }
271
 
272
        printf("SUCCESS!!\n");
273
        delete tb;
274
        exit(0);
275
test_failure:
276
        printf("FAIL-HERE\n");
277
        for(int i=0; i<4; i++)
278
                tb->tick();
279
        printf("TEST FAILED\n");
280
        delete tb;
281
        exit(-1);
282
}

powered by: WebSVN 2.1.0

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