2023-10-02 00:00:56 +02:00
|
|
|
module ram #(
|
|
|
|
parameter DATA_W = 8,
|
|
|
|
parameter ADDR_W = 8
|
|
|
|
)(
|
|
|
|
input logic clk,
|
2023-10-02 22:23:39 +02:00
|
|
|
input logic nreset,
|
2023-10-02 00:00:56 +02:00
|
|
|
|
2023-10-02 22:23:39 +02:00
|
|
|
input logic cs_i,
|
2023-10-02 00:00:56 +02:00
|
|
|
input logic [ADDR_W-1:0] address_i,
|
|
|
|
input logic we_i,
|
|
|
|
input logic [DATA_W-1:0] wdata_i,
|
|
|
|
output logic [DATA_W-1:0] rdata_o
|
|
|
|
);
|
|
|
|
|
|
|
|
localparam RAM_SIZE = 2**ADDR_W;
|
|
|
|
|
|
|
|
logic [DATA_W-1:0] ram [RAM_SIZE-1:0];
|
|
|
|
|
|
|
|
logic [DATA_W-1:0] rdata;
|
|
|
|
|
2023-10-02 22:23:39 +02:00
|
|
|
logic we;
|
|
|
|
|
|
|
|
assign we = cs_i & we_i;
|
|
|
|
|
|
|
|
always_ff @(posedge clk) begin
|
|
|
|
if (we)
|
2023-10-02 00:00:56 +02:00
|
|
|
ram[address_i] <= wdata_i;
|
2023-10-02 22:23:39 +02:00
|
|
|
end
|
2023-10-02 00:00:56 +02:00
|
|
|
|
2023-10-02 22:23:39 +02:00
|
|
|
always_ff @(posedge clk or negedge nreset) begin
|
|
|
|
if (!nreset)
|
|
|
|
rdata <= '0;
|
|
|
|
else
|
|
|
|
rdata <= ram[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
|
|
|
|
|
|
|
endmodule
|