2015-08-10 06:11:33 -04:00
|
|
|
`timescale 1 ns / 1 ps
|
|
|
|
|
2015-08-09 08:23:02 -04:00
|
|
|
module main (input clk, resetn, domem, output trap);
|
2015-08-10 06:11:33 -04:00
|
|
|
parameter integer MEMORY_WORDS = 2**30;
|
2015-08-15 05:28:35 -04:00
|
|
|
|
|
|
|
// timing parameters (vary for async test)
|
2015-08-09 08:23:02 -04:00
|
|
|
parameter [0:0] ENABLE_REGS_DUALPORT = 1;
|
|
|
|
parameter [0:0] TWO_STAGE_SHIFT = 1;
|
|
|
|
parameter [0:0] TWO_CYCLE_COMPARE = 0;
|
|
|
|
parameter [0:0] TWO_CYCLE_ALU = 0;
|
|
|
|
|
2015-08-15 05:28:35 -04:00
|
|
|
// isa parameters (vary for sync test)
|
|
|
|
parameter [0:0] ENABLE_COUNTERS = 0;
|
|
|
|
parameter [0:0] CATCH_MISALIGN = 1;
|
|
|
|
parameter [0:0] CATCH_ILLINSN = 1;
|
|
|
|
parameter [0:0] ENABLE_MUL = 0;
|
|
|
|
parameter [0:0] ENABLE_IRQ = 0;
|
|
|
|
|
2015-08-09 08:23:02 -04:00
|
|
|
(* keep *) wire mem_valid;
|
|
|
|
(* keep *) wire mem_ready;
|
|
|
|
(* keep *) wire [31:0] mem_addr;
|
|
|
|
(* keep *) wire [31:0] mem_wdata;
|
|
|
|
(* keep *) wire [ 3:0] mem_wstrb;
|
|
|
|
(* keep *) wire [31:0] mem_rdata;
|
|
|
|
|
|
|
|
picorv32 #(
|
2015-08-15 05:28:35 -04:00
|
|
|
// timing parameters
|
2015-08-09 08:23:02 -04:00
|
|
|
.ENABLE_REGS_DUALPORT(ENABLE_REGS_DUALPORT),
|
|
|
|
.TWO_STAGE_SHIFT (TWO_STAGE_SHIFT ),
|
|
|
|
.TWO_CYCLE_COMPARE (TWO_CYCLE_COMPARE ),
|
2015-08-15 05:28:35 -04:00
|
|
|
.TWO_CYCLE_ALU (TWO_CYCLE_ALU ),
|
|
|
|
|
|
|
|
// isa parameters
|
|
|
|
.ENABLE_COUNTERS(ENABLE_COUNTERS),
|
|
|
|
.CATCH_MISALIGN (CATCH_MISALIGN ),
|
|
|
|
.CATCH_ILLINSN (CATCH_ILLINSN ),
|
|
|
|
.ENABLE_MUL (ENABLE_MUL ),
|
|
|
|
.ENABLE_IRQ (ENABLE_IRQ )
|
2015-08-09 08:23:02 -04:00
|
|
|
) cpu (
|
|
|
|
.clk (clk ),
|
|
|
|
.resetn (resetn ),
|
|
|
|
.trap (trap ),
|
|
|
|
.mem_valid(mem_valid),
|
|
|
|
.mem_ready(mem_ready),
|
|
|
|
.mem_addr (mem_addr ),
|
|
|
|
.mem_wdata(mem_wdata),
|
|
|
|
.mem_wstrb(mem_wstrb),
|
|
|
|
.mem_rdata(mem_rdata)
|
|
|
|
);
|
|
|
|
|
2015-08-10 06:11:33 -04:00
|
|
|
reg [31:0] memory [0:MEMORY_WORDS-1];
|
2015-08-09 08:23:02 -04:00
|
|
|
|
|
|
|
assign mem_ready = domem && resetn && mem_valid;
|
|
|
|
assign mem_rdata = memory[mem_addr >> 2];
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (mem_ready && mem_valid) begin
|
|
|
|
if (mem_wstrb[0]) memory[mem_addr >> 2][ 7: 0] <= mem_wdata[ 7: 0];
|
|
|
|
if (mem_wstrb[1]) memory[mem_addr >> 2][15: 8] <= mem_wdata[15: 8];
|
|
|
|
if (mem_wstrb[2]) memory[mem_addr >> 2][23:16] <= mem_wdata[23:16];
|
|
|
|
if (mem_wstrb[3]) memory[mem_addr >> 2][31:24] <= mem_wdata[31:24];
|
|
|
|
end
|
|
|
|
end
|
|
|
|
endmodule
|