-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbench.sv
More file actions
84 lines (72 loc) · 2.05 KB
/
testbench.sv
File metadata and controls
84 lines (72 loc) · 2.05 KB
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
`include "cache.sv"
`include "cpu.sv"
`include "mem.sv"
module testbench ();
parameter BUS_SIZE = 16;
parameter MEM_ADDR_SIZE = 10 + 9; // log2(MEM_SIZE)
parameter CACHE_OFFSET_SIZE = $clog2(CACHE_LINE_SIZE);
parameter CACHE_LINE_SIZE = 16;
wire [MEM_ADDR_SIZE-CACHE_OFFSET_SIZE-1:0] cpu_address;
wire [BUS_SIZE-1:0] cpu_data;
wire [3-1:0] cpu_command;
wire [MEM_ADDR_SIZE-CACHE_OFFSET_SIZE-1:0] mem_address;
wire [BUS_SIZE-1:0] mem_data;
wire [2-1:0] mem_command;
wire cache_dump;
wire mem_dump;
reg clk;
reg reset;
cpu #(MEM_ADDR_SIZE, BUS_SIZE, CACHE_OFFSET_SIZE)
cpu (
.clk(clk),
.cache_dump(cache_dump),
.mem_dump(mem_dump),
.address(cpu_address),
.data(cpu_data),
.command(cpu_command)
);
cache #(BUS_SIZE, MEM_ADDR_SIZE, CACHE_OFFSET_SIZE, CACHE_LINE_SIZE)
cache (
.clk(clk),
.reset(reset),
.dump(cache_dump),
.cpu_address(cpu_address),
.cpu_data(cpu_data),
.cpu_command(cpu_command),
.mem_address(mem_address),
.mem_data(mem_data),
.mem_command(mem_command)
);
mem #(MEM_ADDR_SIZE, BUS_SIZE, CACHE_OFFSET_SIZE, CACHE_LINE_SIZE)
mem(
.clk(clk),
.reset(reset),
.dump(mem_dump),
.address(mem_address),
.data(mem_data),
.command(mem_command)
);
int cyclesCount = 1;
initial begin
#2 forever begin
#1 if (clk) begin
++cyclesCount;
end
if (mem_dump) begin
$display("Total clock cycles: %0d", cyclesCount);
repeat(2) begin
@(posedge clk);
end
end
end
end
initial begin
reset = 0;
#1 reset = 1;
#1 reset = 0;
clk = 1'd0;
forever begin
#1 clk = ~clk;
end
end
endmodule