picorv32/testbench.v

136 lines
3.3 KiB
Coq
Raw Normal View History

2015-06-28 06:20:23 -04:00
// This is free and unencumbered software released into the public domain.
2015-07-02 04:49:35 -04:00
//
2015-06-28 06:20:23 -04:00
// 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.
2015-06-06 08:01:37 -04:00
`timescale 1 ns / 1 ps
// `define VERBOSE
module testbench #(
parameter AXI_TEST = 0,
parameter VERBOSE = 0
);
2015-06-06 08:01:37 -04:00
reg clk = 1;
reg resetn = 0;
2015-06-26 04:03:37 -04:00
reg [31:0] irq;
2015-06-06 08:01:37 -04:00
wire trap;
2015-06-26 04:03:37 -04:00
always @* begin
irq = 0;
irq[4] = &uut.picorv32_core.count_cycle[12:0];
irq[5] = &uut.picorv32_core.count_cycle[15:0];
end
2015-06-06 08:01:37 -04:00
always #5 clk = ~clk;
initial begin
repeat (100) @(posedge clk);
resetn <= 1;
end
wire mem_axi_awvalid;
wire mem_axi_awready;
2015-06-06 08:01:37 -04:00
wire [31:0] mem_axi_awaddr;
wire [ 2:0] mem_axi_awprot;
wire mem_axi_wvalid;
wire mem_axi_wready;
2015-06-06 08:01:37 -04:00
wire [31:0] mem_axi_wdata;
wire [ 3:0] mem_axi_wstrb;
wire mem_axi_bvalid;
wire mem_axi_bready;
2015-06-06 08:01:37 -04:00
wire mem_axi_arvalid;
wire mem_axi_arready;
2015-06-06 08:01:37 -04:00
wire [31:0] mem_axi_araddr;
wire [ 2:0] mem_axi_arprot;
wire mem_axi_rvalid;
2015-06-06 08:01:37 -04:00
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_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 )
);
2015-06-06 08:01:37 -04:00
2015-06-25 08:08:39 -04:00
picorv32_axi #(
2015-06-26 17:54:12 -04:00
`ifdef SP_TEST
.ENABLE_REGS_DUALPORT(0),
`endif
.ENABLE_MUL(1),
2015-06-26 04:03:37 -04:00
.ENABLE_IRQ(1)
2015-06-25 08:08:39 -04:00
) uut (
2015-06-06 08:01:37 -04:00
.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 ),
2015-06-26 04:03:37 -04:00
.mem_axi_rdata (mem_axi_rdata ),
.irq (irq )
2015-06-06 08:01:37 -04:00
);
initial $readmemh("firmware/firmware.hex", mem.memory);
2015-06-06 08:01:37 -04:00
initial begin
if ($test$plusargs("vcd")) begin
$dumpfile("testbench.vcd");
$dumpvars(0, testbench);
end
2015-06-06 08:01:37 -04:00
repeat (1000000) @(posedge clk);
$display("TIMEOUT");
$finish;
end
2015-06-28 07:07:50 -04:00
integer cycle_counter;
2015-06-06 08:01:37 -04:00
always @(posedge clk) begin
2015-06-28 07:07:50 -04:00
cycle_counter <= resetn ? cycle_counter + 1 : 0;
2015-06-06 08:01:37 -04:00
if (resetn && trap) begin
repeat (10) @(posedge clk);
2015-06-28 07:07:50 -04:00
$display("TRAP after %1d clock cycles", cycle_counter);
2015-06-06 08:01:37 -04:00
$finish;
end
end
endmodule