forked from mhyousefi/MIPS-pipeline-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestbench.v
More file actions
104 lines (86 loc) · 1.85 KB
/
testbench.v
File metadata and controls
104 lines (86 loc) · 1.85 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
`timescale 1ms/1ms
`include "top.v"
`include "sources/memory/dataMem.v"
`include "sources/memory/instrMem.v"
module testbench();
reg clk;
reg reset;
wire [31:0] imem_addr;
wire [31:0] imem_data;
wire [31:0] dmem_addr;
wire dmem_write_en;
wire [31:0] dmem_val_out;
wire [31:0] dmem_val_in;
`ifdef FOR_TEST
reg [31:0] buffer[0:255];
wire [31:0] test_imem_addr;
wire [31:0] test_imem_data_in;
wire [31:0] test_imem_data_out;
reg [31:0] test_imem_addr_reg;
reg [31:0] test_imem_data_in_reg;
integer i = 0;
`endif
PikaRISC _PikaRISC(
.clk(clk),
.reset(reset),
.imem_addr(imem_addr),
.imem_data(imem_data),
.dmem_addr(dmem_addr),
.dmem_write_en(dmem_write_en),
.dmem_val_out(dmem_val_out),
.dmem_val_in(dmem_val_in)
);
instrMem _instrMem(
.reset(reset),
.addr(imem_addr),
.data_out(imem_data)
`ifdef FOR_TEST
,
.test_addr(test_imem_addr),
.test_data_in(test_imem_data_in),
.test_data_out(test_imem_data_out)
`endif
);
dataMem _dataMem(
.reset(reset),
.addr(dmem_addr),
.write_en(dmem_write_en),
.data_in(dmem_val_out),
.data_out(dmem_val_in)
);
`ifdef FOR_TEST
assign test_imem_addr = test_imem_addr_reg;
assign test_imem_data_in = test_imem_data_in_reg;
`endif
initial begin
// for simulation
$dumpfile("test.vcd");
$dumpvars(-1, _PikaRISC);
$dumpvars(-1, _instrMem);
$dumpvars(-1, _dataMem);
// initialize
clk = 1;
reset = 1;
// reset
#1 reset = 0;
#1 reset = 1;
`ifdef FOR_TEST
// test probe
// $dumpvars(-1, test_imem_addr);
// $dumpvars(-1, test_imem_data_in);
// $dumpvars(-1, test_imem_data_out);
// code injection
$readmemh("test.hex", buffer);
for (i = 0; i < 44; i = i + 1) begin
#1 test_imem_addr_reg = i;
test_imem_data_in_reg = buffer[i];
end
`endif
// start clock trigger
repeat (44) begin
#1 clk = ~clk;
#1 clk = ~clk;
end
#1 $finish;
end
endmodule