RVSCC/rtl/DataMemory.sv

29 lines
795 B
Systemverilog
Raw Normal View History

2023-01-01 22:28:56 +00:00
`timescale 1ns / 1ps
module DataMemory #(
2023-02-11 22:29:27 +00:00
parameter int N = 32,
parameter int SIZE = 32,
parameter int BYTE_WIDTH = 8)(
2023-01-01 22:28:56 +00:00
input logic clk, rst,
input logic[N-1:0] addr,
input logic write_enable,
input logic[N-1:0] write_data,
output logic[N-1:0] read_data
);
2023-02-11 22:29:27 +00:00
logic[SIZE*BYTE_WIDTH-1:0][BYTE_WIDTH-1:0] mem;
2023-01-01 22:28:56 +00:00
assign read_data = {mem[addr + 'd0],
mem[addr + 'd1],
mem[addr + 'd2],
mem[addr + 'd3]};
always_ff @(posedge clk) begin
if (rst)
2023-02-11 22:29:27 +00:00
mem <= '{default: '0};
2023-01-01 22:28:56 +00:00
else if (write_enable)
{mem[addr + 'd0],
mem[addr + 'd1],
mem[addr + 'd2],
mem[addr + 'd3]} <= write_data;
end
2023-02-11 22:29:27 +00:00
endmodule