-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb.cpp
85 lines (69 loc) · 1.5 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "Vseq_top.h"
#include "verilated.h"
#include "verilated_vcd_c.h"
#define CLOCK_POS \
top->clk_i = !top->clk_i; \
top->eval()
#define CLOCK_NEG \
top->eval(); \
tfp->dump(local_time++); \
top->clk_i = !top->clk_i; \
top->eval(); \
tfp->dump(local_time++)
#define CLOCK_DELAY(x) \
for (int xx=0; xx < x; xx++) { \
top->clk_i = !top->clk_i; \
CLOCK_NEG; \
}
#define WAIT(x, y) \
while (1) { \
if (x == y) break; \
CLOCK_DELAY(1); \
}
int main(int argc, char **argv) {
int i, local_time = 0;
Verilated::commandArgs(argc, argv);
Vseq_top* top = new Vseq_top;
Verilated::traceEverOn(true);
VerilatedVcdC* tfp = new VerilatedVcdC;
top->trace(tfp, 99);
tfp->open("seq_top.vcd");
CLOCK_POS;
top->rst_ni = 0;
top->a = 0;
top->b = 0;
top->start = 0;
CLOCK_NEG;
CLOCK_DELAY(5);
CLOCK_POS;
top->rst_ni = 1;
CLOCK_NEG;
CLOCK_DELAY(10);
printf("Test case 1 start\n");
CLOCK_POS;
top->a = 15;
top->b = 13;
top->start = 1;
CLOCK_NEG;
CLOCK_POS;
top->start = 0;
CLOCK_NEG;
WAIT(top->finish, 1);
CLOCK_DELAY(10);
printf("Test case 2 start\n");
CLOCK_POS;
top->a = 0xfedcba98;
top->b = 0x76543210;
top->start = 1;
CLOCK_NEG;
CLOCK_POS;
top->start = 0;
CLOCK_NEG;
WAIT(top->finish, 1);
CLOCK_DELAY(10);
printf("Test finished\n");
tfp->close();
delete top;
delete tfp;
return 0;
}