2020-12-04 14:44:48 +00:00
|
|
|
module mips_cpu_harvard_tb;
|
|
|
|
|
2020-12-11 10:45:13 +00:00
|
|
|
parameter RAM_INIT_FILE = "inputs/addiu.txt";
|
|
|
|
parameter MEM_INIT_FILE = "inputs/addiu.data.txt";
|
2020-12-09 07:47:58 +00:00
|
|
|
parameter TIMEOUT_CYCLES = 100;
|
2020-12-04 14:44:48 +00:00
|
|
|
|
2020-12-09 07:47:58 +00:00
|
|
|
logic clk, clk_enable, reset, active, data_read, data_write;
|
|
|
|
logic[31:0] register_v0, instr_address, instr_readdata, data_readdata, data_writedata, data_address;
|
2020-12-04 14:44:48 +00:00
|
|
|
|
2020-12-11 10:45:13 +00:00
|
|
|
mips_cpu_memory #(RAM_INIT_FILE, MEM_INIT_FILE) ramInst(
|
2020-12-06 06:44:58 +00:00
|
|
|
.clk(clk),
|
|
|
|
.data_address(data_address),
|
|
|
|
.data_write(data_write),
|
|
|
|
.data_read(data_read),
|
|
|
|
.data_writedata(data_writedata),
|
|
|
|
.data_readdata(data_readdata),
|
|
|
|
.instr_address(instr_address),
|
|
|
|
.instr_readdata(instr_readdata)
|
|
|
|
);
|
|
|
|
mips_cpu_harvard cpuInst(
|
|
|
|
.clk(clk),
|
|
|
|
.reset(reset),
|
|
|
|
.active(active),
|
|
|
|
.register_v0(register_v0),
|
|
|
|
.clk_enable(clk_enable),
|
|
|
|
.instr_address(instr_address),
|
|
|
|
.instr_readdata(instr_readdata),
|
|
|
|
.data_address(data_address),
|
|
|
|
.data_write(data_write),
|
|
|
|
.data_read(data_read),
|
|
|
|
.data_writedata(data_writedata),
|
|
|
|
.data_readdata(data_readdata)
|
|
|
|
);
|
2020-12-04 14:44:48 +00:00
|
|
|
|
|
|
|
// Generate clock
|
|
|
|
initial begin
|
2020-12-11 10:45:13 +00:00
|
|
|
$dumpfile("mips_cpu_harvard.vcd");
|
|
|
|
$dumpvars(0,mips_cpu_harvard_tb);
|
2020-12-04 14:44:48 +00:00
|
|
|
clk=0;
|
|
|
|
|
|
|
|
repeat (TIMEOUT_CYCLES) begin
|
|
|
|
#10;
|
|
|
|
clk = !clk;
|
|
|
|
#10;
|
|
|
|
clk = !clk;
|
|
|
|
end
|
|
|
|
|
|
|
|
$fatal(2, "Simulation did not finish within %d cycles.", TIMEOUT_CYCLES);
|
|
|
|
end
|
|
|
|
|
|
|
|
initial begin
|
2020-12-09 07:47:58 +00:00
|
|
|
$display("Initial Reset 0");
|
2020-12-04 14:44:48 +00:00
|
|
|
reset <= 0;
|
2020-12-09 07:47:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
$display("Initial Reset 1");
|
2020-12-04 14:44:48 +00:00
|
|
|
@(posedge clk);
|
|
|
|
reset <= 1;
|
|
|
|
|
2020-12-09 07:47:58 +00:00
|
|
|
$display("Initial Reset 0: Start Program");
|
2020-12-04 14:44:48 +00:00
|
|
|
@(posedge clk);
|
|
|
|
reset <= 0;
|
|
|
|
|
|
|
|
@(posedge clk);
|
2020-12-09 07:47:58 +00:00
|
|
|
assert(active==1);
|
|
|
|
else $display("TB: CPU did not set active=1 after reset.");
|
2020-12-04 14:44:48 +00:00
|
|
|
|
2020-12-06 06:44:58 +00:00
|
|
|
while (active) begin
|
2020-12-11 10:45:13 +00:00
|
|
|
//$display("Clk: %d", clk);
|
2020-12-04 14:44:48 +00:00
|
|
|
@(posedge clk);
|
2020-12-11 10:45:13 +00:00
|
|
|
//$display("Register v0: %d", register_v0);
|
2020-12-13 05:40:16 +00:00
|
|
|
//$display("Reg File Write data: %d", cpuInst.in_writedata);
|
|
|
|
$display("Reg File Out Read data: %h", cpuInst.out_readdata1);
|
|
|
|
$display("Reg File opcode: %b", cpuInst.regfile.opcode);
|
|
|
|
//$display("ALU output: %h", cpuInst.out_ALURes);
|
|
|
|
//$display("ALU input B: %h", cpuInst.alu.B);
|
2020-12-04 14:44:48 +00:00
|
|
|
end
|
2020-12-11 10:45:13 +00:00
|
|
|
@(posedge clk);
|
|
|
|
$display("TB: CPU Halt; active=0");
|
|
|
|
$display("Output:");
|
|
|
|
$display("%d",register_v0);
|
2020-12-04 14:44:48 +00:00
|
|
|
$finish;
|
|
|
|
|
|
|
|
end
|
|
|
|
endmodule
|