-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtb.cpp
60 lines (46 loc) · 1.21 KB
/
tb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <verilated_vcd_c.h>
#include "VTestHarness.h"
#define MAX_TIME 10000000
// Simulation time:
vluint64_t t_sim;
// provide method to be called by $time in Verilog:
double sc_time_stamp() { return t_sim; }
int main(int argc, char *argv[])
{
// Initialize Verilator:
Verilated::commandArgs(argc, argv);
Verilated::traceEverOn(true);
// Instantiate DUT:
VTestHarness *dut = new VTestHarness;
// Initialize tracing:
VerilatedVcdC *m_trace = new VerilatedVcdC;
dut->trace(m_trace, 99);
m_trace->open("tb.vcd");
// Initial input signals:
dut->clock = 0;
dut->reset = 1;
dut->uart_rx = 0;
// keep track of LED output value
int led = 0;
// Tick the clock for a few cycles (or until done):
for (t_sim = 0; !Verilated::gotFinish() && t_sim < MAX_TIME; t_sim++) {
if (t_sim > 100) dut->reset = 0;
if ((t_sim % 10) == 1) dut->clock = 1;
if ((t_sim % 10) == 6) dut->clock = 0;
dut->eval();
m_trace->dump(t_sim);
if ((t_sim % 100000) == 0)
std::cout << "### +10k cycles" << std::endl;
if (led != dut->led) {
led = dut->led;
std::cout << "### LED: " << led << std::endl;
}
}
// Clean up:
m_trace->close();
m_trace = NULL;
dut->final();
delete dut;
return 0;
}