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

Subversion Repositories wbscope

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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