-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb.h
56 lines (49 loc) · 1.23 KB
/
tb.h
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
#include "verilated.h"
#include "verilated_vcd_c.h"
template<typename UUT>
class Sim {
public:
UUT* mod {};
protected:
VerilatedVcdC* trace {};
unsigned int sim_time = 0;
unsigned int time_limit {};
public:
Sim(std::string trace_name, unsigned int time_limit) {
this->time_limit = time_limit;
trace = new VerilatedVcdC();
mod = new UUT();
mod->trace(trace, 10 /* trace depth */);
trace->open((trace_name + ".vcd").c_str());
}
~Sim() {
mod->final();
trace->close();
}
unsigned int time() const {
return sim_time;
}
template<typename F, typename G>
void tickt(F&& posedge, G&& negedge) {
for (int i=0; i<10; i++) {
mod->eval();
trace->dump(sim_time);
sim_time++;
if (i % 10 == 4) {
negedge();
mod->eval();
} else if (i % 10 == 9) {
posedge();
mod->eval();
} else {
mod->eval();
}
trace->dump(sim_time);
}
trace->flush();
if (sim_time > time_limit) {
trace->flush();
throw "hit time limit";
}
}
};