2023-10-02 00:00:56 +02:00
|
|
|
module rom #(
|
|
|
|
parameter string FILE_NAME = "",
|
|
|
|
parameter integer unsigned ADDR_W = 8,
|
|
|
|
parameter integer unsigned DATA_W = 8
|
|
|
|
) (
|
|
|
|
input logic clk,
|
2023-10-02 22:23:39 +02:00
|
|
|
input logic nreset,
|
|
|
|
|
|
|
|
input logic cs_i,
|
2023-10-02 00:00:56 +02:00
|
|
|
input logic [ADDR_W-1:0] address_i,
|
|
|
|
output logic [DATA_W-1:0] rdata_o
|
|
|
|
);
|
|
|
|
|
|
|
|
localparam ROM_SIZE = 2**ADDR_W;
|
|
|
|
|
|
|
|
logic [DATA_W-1:0] rom [ROM_SIZE-1:0];
|
|
|
|
logic [DATA_W-1:0] rdata;
|
|
|
|
|
2023-10-02 22:23:39 +02:00
|
|
|
always_ff @(posedge clk or negedge nreset) begin
|
|
|
|
if (!nreset)
|
|
|
|
rdata <= '0;
|
|
|
|
else
|
|
|
|
rdata <= rom[address_i];
|
|
|
|
end
|
2023-10-02 00:00:56 +02:00
|
|
|
|
2023-10-02 22:23:39 +02:00
|
|
|
assign rdata_o = {8{cs_i}} & rdata;
|
2023-10-02 00:00:56 +02:00
|
|
|
|
|
|
|
initial begin
|
|
|
|
static integer fd = $fopen(FILE_NAME, "rb");
|
|
|
|
static integer rv = $fread(rom, fd);
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule : rom
|