HAL
v4.5.0-124-g47ab54673
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
testbench.h
Go to the documentation of this file.
1
//
3
// Filename: testb.h
4
//
5
// Project: dbgbus, a collection of 8b channel to WB bus debugging protocols
6
//
7
// Purpose: A wrapper for a common interface to a clocked FPGA core
8
// begin exercised in Verilator.
9
//
10
// Creator: Dan Gisselquist, Ph.D.
11
// Gisselquist Technology, LLC
12
//
14
//
15
// Copyright (C) 2015,2017-2020, Gisselquist Technology, LLC
16
//
17
// This file is part of the debugging interface demonstration.
18
//
19
// The debugging interface demonstration is free software (firmware): you can
20
// redistribute it and/or modify it under the terms of the GNU Lesser General
21
// Public License as published by the Free Software Foundation, either version
22
// 3 of the License, or (at your option) any later version.
23
//
24
// This debugging interface demonstration is distributed in the hope that it
25
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26
// of MERCHANTIBILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
27
// General Public License for more details.
28
//
29
// You should have received a copy of the GNU Lesser General Public License
30
// along with this program. (It's in the $(ROOT)/doc directory. Run make
31
// with no target there if the PDF file isn't present.) If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License: LGPL, v3, as defined and found on www.gnu.org,
35
// http://www.gnu.org/licenses/lgpl.html
36
//
37
//
39
//
40
//
41
#ifndef TESTB_H
42
#define TESTB_H
43
44
45
#include <stdint.h>
46
#include <stdio.h>
47
#include <verilated_vcd_c.h>
48
49
#include <fstream>
50
#include <iostream>
51
#include <string>
52
53
#define TBASSERT(TB, A) \
54
do { \
55
if (!(A)) { \
56
(TB).closetrace(); \
57
} \
58
assert(A); \
59
} while (0);
60
61
template
<
class
VA>
62
class
TESTB
{
63
public
:
64
VA*
m_core
;
65
VerilatedVcdC*
m_trace
;
66
unsigned
long
m_tickcount
;
67
68
TESTB
(
void
)
69
:
m_trace
(NULL)
70
,
m_tickcount
(0l)
71
{
72
m_core
=
new
VA;
73
Verilated::traceEverOn(
true
);
74
m_core
->Clock = 0;
75
eval
();
// Get our initial values set properly.
76
}
77
virtual
~TESTB
(
void
)
78
{
79
if
(
m_trace
)
80
m_trace
->close();
81
delete
m_core
;
82
m_core
= NULL;
83
}
84
85
virtual
unsigned
long
tb_sc_time_stamp
(
void
)
86
{
87
return
m_tickcount
;
88
}
89
90
virtual
void
opentrace
(
const
char
* vcdname)
91
{
92
if
(!
m_trace
) {
93
m_trace
=
new
VerilatedVcdC;
94
m_core
->trace(
m_trace
, 99);
95
m_trace
->open(vcdname);
96
}
97
}
98
99
virtual
void
closetrace
(
void
)
100
{
101
if
(
m_trace
) {
102
m_trace
->close();
103
m_trace
= NULL;
104
}
105
}
106
107
virtual
void
eval
(
void
) {
m_core
->eval(); }
108
109
virtual
void
tick
(
void
)
110
{
111
m_tickcount
++;
112
113
// Make sure we have our evaluations straight before the top
114
// of the clock. This is necessary since some of the
115
// connection modules may have made changes, for which some
116
// logic depends. This forces that logic to be recalculated
117
// before the top of the clock.
118
eval
();
119
if
(
m_trace
)
120
m_trace
->dump((vluint64_t)(10 *
m_tickcount
- 2));
121
m_core
->Clock = 1;
122
eval
();
123
if
(
m_trace
)
124
m_trace
->dump((vluint64_t)(10 *
m_tickcount
));
125
m_core
->Clock = 0;
126
eval
();
127
if
(
m_trace
) {
128
m_trace
->dump((vluint64_t)(10 *
m_tickcount
+ 5));
129
m_trace
->flush();
130
}
131
}
132
133
virtual
void
wait_for_n_clocks
(
int
ticks)
134
{
135
int
counter = 0;
136
137
while
(counter < ticks) {
138
tick
();
139
counter++;
140
}
141
}
142
};
143
144
#endif
TESTB
Definition:
testbench.h:62
TESTB::eval
virtual void eval(void)
Definition:
testbench.h:107
TESTB::~TESTB
virtual ~TESTB(void)
Definition:
testbench.h:77
TESTB::m_trace
VerilatedVcdC * m_trace
Definition:
testbench.h:65
TESTB::m_tickcount
unsigned long m_tickcount
Definition:
testbench.h:66
TESTB::opentrace
virtual void opentrace(const char *vcdname)
Definition:
testbench.h:90
TESTB::wait_for_n_clocks
virtual void wait_for_n_clocks(int ticks)
Definition:
testbench.h:133
TESTB::m_core
VA * m_core
Definition:
testbench.h:64
TESTB::tb_sc_time_stamp
virtual unsigned long tb_sc_time_stamp(void)
Definition:
testbench.h:85
TESTB::TESTB
TESTB(void)
Definition:
testbench.h:68
TESTB::closetrace
virtual void closetrace(void)
Definition:
testbench.h:99
TESTB::tick
virtual void tick(void)
Definition:
testbench.h:109
plugins
simulator
verilator
test_files
netlists
counter
testbench.h
Generated by
1.9.1