-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpicotest_sim.cpp
82 lines (67 loc) · 1.49 KB
/
picotest_sim.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdlib.h>
#include "Vpicotest_sim.h"
#include "verilated.h"
#include "verilated_vcd_c.h"
template <class MODULE> class TESTBENCH {
public:
VerilatedVcdC *m_trace;
unsigned long m_tickcount;
MODULE *m_core;
TESTBENCH(void) {
m_core = new MODULE;
m_tickcount = 0;
}
virtual ~TESTBENCH(void) {
delete m_core;
m_core = NULL;
}
virtual void opentrace(const char *vcdname) {
if (!m_trace) {
m_trace = new VerilatedVcdC;
m_core->trace(m_trace, 99);
m_trace->open(vcdname);
}
}
virtual void close(void) {
if (m_trace) {
m_trace->close();
m_trace = NULL;
}
}
virtual void reset(void) {
m_core->rst = 1;
this->tick();
m_core->rst = 0;
}
virtual void tick(void) {
m_tickcount++;
// Allow combinatorial logic to settle before ticking the clock.
m_core->clk = 0;
m_core->eval();
if (m_trace) m_trace->dump(10*m_tickcount-2);
// Simulate the rising edge.
m_core->clk = 1;
m_core->eval();
if (m_trace) m_trace->dump(10*m_tickcount);
// Simulate the falling edge.
m_core->clk = 0;
m_core->eval();
if (m_trace) {
m_trace->dump(10*m_tickcount+5);
m_trace->flush();
}
}
virtual bool done(void) {
return Verilated::gotFinish();
}
};
int main(int argc, char **argv) {
// Initialize Verilators variables
Verilated::commandArgs(argc, argv);
TESTBENCH<Vpicotest_sim> *tb = new TESTBENCH<Vpicotest_sim>();
Verilated::traceEverOn(true);
tb->opentrace("picotest_sim.vcd");
while (!tb->done()) {
tb->tick();
} exit(EXIT_SUCCESS);
}