-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_tb.cpp
64 lines (45 loc) · 1.62 KB
/
example_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
61
62
63
64
#include <stdio.h>
#include "Vthe_top_module.h"
#include "verilated_vcd_c.h"
int main(int argc, char** argv, char** env) {
Verilated::commandArgs(argc, argv);
Vthe_top_module* dut = new Vthe_top_module;
Verilated::traceEverOn(true);
VerilatedVcdC* trace = new VerilatedVcdC;
dut->trace(trace, 99);
trace->open("waves.vcd");
int timestamp = 0;
printf("time\tclk\trst\td\tnload\tq\n");
dut->clk = 1;
dut->rst = 1;
dut->en_counter = 0;
dut->en_lfsr = 0;
dut->eval();
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", timestamp, dut->clk, dut->rst, dut->en_counter, dut->en_lfsr, dut->counter, dut->lfsr);
trace->dump(timestamp++);
dut->clk = 0;
dut->eval();
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", timestamp, dut->clk, dut->rst, dut->en_counter, dut->en_lfsr, dut->counter, dut->lfsr);
trace->dump(timestamp++);
dut->clk = 1;
dut->eval();
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", timestamp, dut->clk, dut->rst, dut->en_counter, dut->en_lfsr, dut->counter, dut->lfsr);
trace->dump(timestamp++);
dut->rst = 0;
for(int i = 0; i < 50; i++) {
dut->en_counter = (rand() & 3) != 0? 1 : 0;
dut->en_lfsr = (rand() & 3) != 0? 1 : 0;
dut->clk = 0;
dut->eval();
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", timestamp, dut->clk, dut->rst, dut->en_counter, dut->en_lfsr, dut->counter, dut->lfsr);
trace->dump(timestamp++);
dut->clk = 1;
dut->eval();
printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\n", timestamp, dut->clk, dut->rst, dut->en_counter, dut->en_lfsr, dut->counter, dut->lfsr);
trace->dump(timestamp++);
}
dut->final();
trace->close();
delete dut;
return 0;
}