RVSCC/rtl/DataMemory.sv

28 lines
753 B
Systemverilog
Raw Normal View History

2022-11-26 10:44:00 +00:00
`timescale 1ns / 1ps
2022-11-27 06:32:55 +00:00
module DataMemory #(
parameter N = 32,
2022-12-20 05:19:32 +00:00
parameter SIZE = 32,
parameter BYTE_WIDTH = 8)(
input logic clk, rst,
2022-11-26 10:44:00 +00:00
input logic[N-1:0] addr,
2022-11-27 06:32:55 +00:00
input logic write_enable,
2022-11-26 10:44:00 +00:00
input logic[N-1:0] write_data,
output logic[N-1:0] read_data
);
2022-12-20 05:19:32 +00:00
logic[BYTE_WIDTH-1:0] mem[SIZE*BYTE_WIDTH-1:0];
assign read_data = {mem[addr + 'd0],
mem[addr + 'd1],
mem[addr + 'd2],
mem[addr + 'd3]};
2022-11-27 06:32:55 +00:00
always_ff @(posedge clk) begin
2022-12-20 05:19:32 +00:00
if (rst)
mem = '{default: '0};
else if (write_enable)
{mem[addr + 'd0],
mem[addr + 'd1],
mem[addr + 'd2],
mem[addr + 'd3]} <= write_data;
2022-11-27 06:32:55 +00:00
end
2022-11-28 03:46:24 +00:00
endmodule