-
Notifications
You must be signed in to change notification settings - Fork 51
/
tb.sv
77 lines (67 loc) · 1.69 KB
/
tb.sv
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
module toplevel;
// Signals for the main module.
logic go, done, clk, reset;
main #() main (
.go(go),
.clk(clk),
.reset(reset),
.done(done)
);
localparam RESET_CYCLES = 3;
// Cycle counter. Make this signed to catch errors with cycle simulation
// counts.
logic signed [63:0] cycle_count;
always_ff @(posedge clk) begin
cycle_count <= cycle_count + 1;
end
always_ff @(posedge clk) begin
// Reset the design for a few cycles
if (cycle_count < RESET_CYCLES) begin
reset <= 1;
go <= 0;
end else begin
reset <= 0;
go <= 1;
end
end
// Output location of the VCD file
string OUT;
// Disable VCD tracing
int NOTRACE;
// Maximum number of cycles to simulate
longint CYCLE_LIMIT;
// Dummy variable to track value returned by $value$plusargs
int CODE;
initial begin
CODE = $value$plusargs("OUT=%s", OUT);
CODE = $value$plusargs("CYCLE_LIMIT=%d", CYCLE_LIMIT);
if (CYCLE_LIMIT != 0) begin
$display("cycle limit set to %d", CYCLE_LIMIT);
end
CODE = $value$plusargs("NOTRACE=%d", NOTRACE);
if (NOTRACE == 0) begin
$display("VCD tracing enabled");
$dumpfile(OUT);
$dumpvars(0,main);
end else begin
$display("VCD tracing disabled");
end
// Initial values
go = 0;
clk = 0;
reset = 1;
cycle_count = 0;
forever begin
#10 clk = ~clk;
if (cycle_count > RESET_CYCLES && done == 1) begin
// Subtract 1 because the cycle counter is incremented at the end of the
// cycle.
$display("Simulated %d cycles", cycle_count - RESET_CYCLES - 1);
$finish;
end else if (cycle_count != 0 && cycle_count == CYCLE_LIMIT + RESET_CYCLES) begin
$display("reached limit of %d cycles", CYCLE_LIMIT);
$finish;
end
end
end
endmodule