Testbencch RISC32
Testbencch RISC32
Testbencch RISC32
//
//
//
//
//
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
`timescale 1 ns / 1 ps
`ifndef VERILATOR
module testbench #(
parameter AXI_TEST = 0,
parameter VERBOSE = 0
);
reg clk = 1;
reg resetn = 0;
always #5 clk = ~clk;
initial begin
repeat (100) @(posedge clk);
resetn <= 1;
end
initial begin
if ($test$plusargs("vcd")) begin
$dumpfile("testbench.vcd");
$dumpvars(0, testbench);
end
repeat (1000000) @(posedge clk);
$display("TIMEOUT");
$finish;
end
picorv32_wrapper #(
.AXI_TEST (AXI_TEST),
.VERBOSE (VERBOSE)
) top (
.clk
(clk ),
.resetn (resetn)
);
endmodule
`endif
module picorv32_wrapper #(
parameter AXI_TEST = 0,
parameter VERBOSE = 0
) (
input clk,
input resetn
);
wire
trap;
reg [31:0] irq;
always @* begin
irq = 0;
irq[4] = &uut.picorv32_core.count_cycle[12:0];
irq[5] = &uut.picorv32_core.count_cycle[15:0];
end
wire
mem_axi_awvalid;
wire
mem_axi_awready;
wire [31:0] mem_axi_awaddr;
wire [ 2:0] mem_axi_awprot;
wire
mem_axi_wvalid;
wire
mem_axi_wready;
wire [31:0] mem_axi_wdata;
wire [ 3:0] mem_axi_wstrb;
wire
wire
mem_axi_bvalid;
mem_axi_bready;
wire
mem_axi_arvalid;
wire
mem_axi_arready;
wire [31:0] mem_axi_araddr;
wire [ 2:0] mem_axi_arprot;
wire
mem_axi_rvalid;
wire
mem_axi_rready;
wire [31:0] mem_axi_rdata;
axi4_memory #(
.AXI_TEST (AXI_TEST),
.VERBOSE (VERBOSE)
) mem (
.clk
(clk
.mem_axi_awvalid (mem_axi_awvalid
.mem_axi_awready (mem_axi_awready
.mem_axi_awaddr (mem_axi_awaddr
.mem_axi_awprot (mem_axi_awprot
.mem_axi_wvalid
.mem_axi_wready
.mem_axi_wdata
.mem_axi_wstrb
(mem_axi_wvalid
(mem_axi_wready
(mem_axi_wdata
(mem_axi_wstrb
),
),
),
),
),
),
),
),
),
.mem_axi_bvalid (mem_axi_bvalid ),
.mem_axi_bready (mem_axi_bready ),
.mem_axi_arvalid
.mem_axi_arready
.mem_axi_araddr
.mem_axi_arprot
(mem_axi_arvalid
(mem_axi_arready
(mem_axi_araddr
(mem_axi_arprot
),
),
),
),
.mem_axi_rvalid (mem_axi_rvalid ),
.mem_axi_rready (mem_axi_rready ),
.mem_axi_rdata (mem_axi_rdata )
);
picorv32_axi #(
`ifdef SP_TEST
.ENABLE_REGS_DUALPORT(0),
`endif
`ifdef COMPRESSED_ISA
.COMPRESSED_ISA(1),
`endif
.ENABLE_MUL(1),
.ENABLE_DIV(1),
.ENABLE_IRQ(1)
) uut (
.clk
(clk
),
.resetn
(resetn
),
.trap
(trap
),
.mem_axi_awvalid(mem_axi_awvalid),
.mem_axi_awready(mem_axi_awready),
.mem_axi_awaddr (mem_axi_awaddr ),
.mem_axi_awprot (mem_axi_awprot ),
.mem_axi_wvalid (mem_axi_wvalid ),
.mem_axi_wready (mem_axi_wready ),
.mem_axi_wdata (mem_axi_wdata ),
.mem_axi_wstrb (mem_axi_wstrb ),
.mem_axi_bvalid (mem_axi_bvalid ),
.mem_axi_bready (mem_axi_bready ),
.mem_axi_arvalid(mem_axi_arvalid),
.mem_axi_arready(mem_axi_arready),
.mem_axi_araddr (mem_axi_araddr ),
.mem_axi_arprot (mem_axi_arprot ),
.mem_axi_rvalid (mem_axi_rvalid ),
.mem_axi_rready (mem_axi_rready ),
.mem_axi_rdata (mem_axi_rdata ),
.irq
(irq
)
);
reg [1023:0] firmware_file;
initial begin
if(!$value$plusargs("firmware=%s", firmware_file))
firmware_file = "firmware/firmware.hex";
$readmemh(firmware_file, mem.memory);
end
integer cycle_counter;
always @(posedge clk) begin
cycle_counter <= resetn ? cycle_counter + 1 : 0;
if (resetn && trap) begin
`ifndef VERILATOR
repeat (10) @(posedge clk);
`endif
$display("TRAP after %1d clock cycles", cycle_counter);
$finish;
end
end
endmodule
module axi4_memory #(
parameter AXI_TEST = 0,
parameter VERBOSE = 0
) (
input
clk,
input
mem_axi_awvalid,
output reg
mem_axi_awready = 0,
input [31:0]
mem_axi_awaddr,
input [ 2:0]
mem_axi_awprot,
input
output reg
input [31:0]
input [ 3:0]
mem_axi_wvalid,
mem_axi_wready = 0,
mem_axi_wdata,
mem_axi_wstrb,
output reg
input
mem_axi_bvalid = 0,
mem_axi_bready,
input
output reg
input [31:0]
input [ 2:0]
mem_axi_arvalid,
mem_axi_arready = 0,
mem_axi_araddr,
mem_axi_arprot,
output
mem_axi_rvalid = 0,
input
mem_axi_rready,
output reg [31:0] mem_axi_rdata
);
reg [31:0] memory [0:64*1024/4-1] /* verilator public */;
reg verbose;
initial verbose = $test$plusargs("verbose") || VERBOSE;
reg axi_test;
initial axi_test = $test$plusargs("axi_test") || AXI_TEST;
reg [63:0] xorshift64_state = 64'd88172645463325252;
task xorshift64_next;
begin
// see page 4 of
t RNGs". Journal of Statistical Software
xorshift64_state
<< 13);
xorshift64_state
>> 7);
xorshift64_state
<< 17);
end
endtask
[31:0]
[31:0]
[31:0]
[ 3:0]
latched_raddr;
latched_waddr;
latched_wdata;
latched_wstrb;
reg
latched_rinsn;
latched_wstrb = mem_axi_wstrb;
latched_wdata_en = 1;
end
if (mem_axi_arvalid && !(latched_raddr_en || fast_raddr) && !del
ay_axi_transaction[0]) handle_axi_arvalid;
if (mem_axi_awvalid && !(latched_waddr_en || fast_waddr) && !del
ay_axi_transaction[1]) handle_axi_awvalid;
if (mem_axi_wvalid && !(latched_wdata_en || fast_wdata) && !del
ay_axi_transaction[2]) handle_axi_wvalid;
if (!mem_axi_rvalid && latched_raddr_en && !delay_axi_transactio
n[3]) handle_axi_rvalid;
if (!mem_axi_bvalid && latched_waddr_en && latched_wdata_en && !
delay_axi_transaction[4]) handle_axi_bvalid;
end
endmodule