-
Notifications
You must be signed in to change notification settings - Fork 0
/
MIPS_tb.v
87 lines (71 loc) · 2.07 KB
/
MIPS_tb.v
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
86
87
module mips_tb;
timeunit 1ns / 10ps;
parameter RAM_INIT_FILE = "test/binary/basics.hex.txt";
parameter DATA_INIT_FILE = "test/binary/data.hex.txt";
parameter TIMEOUT_CYCLES = 10000;
logic clk;
logic rst;
logic active;
logic[31:0] address;
logic write;
logic read;
logic[31:0] writedata;
logic[31:0] readdata;
logic[31:0] register_v0;
logic[3:0] byte_en;
logic waterequest;
mips_memory #(RAM_INIT_FILE) ramInst(clk, active, address, write, read, byte_en, writedata, readdata);
mips_cpu_bus cpuInst(clk, rst, active, register_v0, address, write, read, waitrequest, writedata, byte_en, readdata);
//Generate clock
initial begin
integer i;
i=0;
clk=0;
$display("CPU reset");
repeat (TIMEOUT_CYCLES) begin
#10;
clk = !clk;
#10;
clk = !clk;
i=i+1;
$display("%d cycle",i);
$display("active: %b",active);
end
$fatal(2, "Simulation did not finish within %d cycles.", TIMEOUT_CYCLES);
end
initial begin
rst <= 0;
@(posedge clk);
rst <= 1;
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
@(posedge clk);
rst <= 0;
$display("CPU reset");
@(posedge clk);
assert(active==1)
else $display("TB : CPU did not set active=1 after reset.");
while (active) begin
@(posedge clk);
$display( "v0 : %h",register_v0);
end
$display( "v0 : %h",register_v0);
// $dumpfile("cpu_all_waves.vcd");
// $dumpvars(0,mips_tb);
$display("active: %b",active);
$dumpfile("cpu_toplvl_waves.vcd");
$dumpvars(0,cpuInst);
$display("TB : finished; running=0");
$finish;
end
endmodule