blob: 866217a64bbc9cb1bd717c2e666230b3b7595b99 [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001// Copyright lowRISC contributors.
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4//
Michael Schaffnerb6fbb872020-06-05 23:40:49 -07005// Dual-Port SRAM Wrapper
6//
7// Supported configurations:
Michael Schaffnerc8ee5cb2020-12-23 13:42:35 -08008// - ECC for 32b and 64b wide memories with no write mask
9// (Width == 32 or Width == 64, DataBitsPerMask is ignored).
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070010// - Byte parity if Width is a multiple of 8 bit and write masks have Byte
11// granularity (DataBitsPerMask == 8).
12//
13// Note that the write mask needs to be per Byte if parity is enabled. If ECC is enabled, the write
14// mask cannot be used and has to be tied to {Width{1'b1}}.
lowRISC Contributors802543a2019-08-31 12:12:56 +010015
Greg Chadwickcf423082020-02-05 16:52:23 +000016`include "prim_assert.sv"
17
Timothy Chen685d6492021-03-09 21:28:39 -080018module prim_ram_2p_adv import prim_ram_2p_pkg::*; #(
Philipp Wagner80cc9232020-05-21 18:21:34 +010019 parameter int Depth = 512,
20 parameter int Width = 32,
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070021 parameter int DataBitsPerMask = 1, // Number of data bits per bit of write mask
Philipp Wagner7ad130c2020-05-21 18:34:24 +010022 parameter MemInitFile = "", // VMEM file to initialize the memory with
lowRISC Contributors802543a2019-08-31 12:12:56 +010023
24 // Configurations
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070025 parameter bit EnableECC = 0, // Enables per-word ECC
26 parameter bit EnableParity = 0, // Enables per-Byte Parity
27 parameter bit EnableInputPipeline = 0, // Adds an input register (read latency +1)
28 parameter bit EnableOutputPipeline = 0, // Adds an output register (read latency +1)
lowRISC Contributors802543a2019-08-31 12:12:56 +010029
Michael Schaffnerf561a2a2021-01-25 18:19:40 -080030 // This switch allows to switch to standard Hamming ECC instead of the HSIAO ECC.
31 // It is recommended to leave this parameter at its default setting (HSIAO),
32 // since this results in a more compact and faster implementation.
33 parameter bit HammingECC = 0,
34
Philipp Wagnereeaa69d2020-06-23 14:32:34 +010035 localparam int Aw = prim_util_pkg::vbits(Depth)
lowRISC Contributors802543a2019-08-31 12:12:56 +010036) (
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070037 input clk_i,
38 input rst_ni,
lowRISC Contributors802543a2019-08-31 12:12:56 +010039
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070040 input a_req_i,
41 input a_write_i,
42 input [Aw-1:0] a_addr_i,
43 input [Width-1:0] a_wdata_i,
44 input [Width-1:0] a_wmask_i, // cannot be used with ECC, tie to 1 in that case
45 output logic [Width-1:0] a_rdata_o,
46 output logic a_rvalid_o, // read response (a_rdata_o) is valid
47 output logic [1:0] a_rerror_o, // Bit1: Uncorrectable, Bit0: Correctable
lowRISC Contributors802543a2019-08-31 12:12:56 +010048
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070049 input b_req_i,
50 input b_write_i,
51 input [Aw-1:0] b_addr_i,
52 input [Width-1:0] b_wdata_i,
53 input [Width-1:0] b_wmask_i, // cannot be used with ECC, tie to 1 in that case
54 output logic [Width-1:0] b_rdata_o,
55 output logic b_rvalid_o, // read response (b_rdata_o) is valid
56 output logic [1:0] b_rerror_o, // Bit1: Uncorrectable, Bit0: Correctable
lowRISC Contributors802543a2019-08-31 12:12:56 +010057
Timothy Chen685d6492021-03-09 21:28:39 -080058 input ram_2p_cfg_t cfg_i
lowRISC Contributors802543a2019-08-31 12:12:56 +010059);
60
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070061 prim_ram_2p_async_adv #(
62 .Depth (Depth),
63 .Width (Width),
64 .DataBitsPerMask (DataBitsPerMask),
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070065 .MemInitFile (MemInitFile),
66 .EnableECC (EnableECC),
67 .EnableParity (EnableParity),
68 .EnableInputPipeline (EnableInputPipeline),
Michael Schaffnerf561a2a2021-01-25 18:19:40 -080069 .EnableOutputPipeline(EnableOutputPipeline),
70 .HammingECC (HammingECC)
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070071 ) i_prim_ram_2p_async_adv (
72 .clk_a_i(clk_i),
73 .rst_a_ni(rst_ni),
74 .clk_b_i(clk_i),
75 .rst_b_ni(rst_ni),
76 .a_req_i,
77 .a_write_i,
78 .a_addr_i,
79 .a_wdata_i,
80 .a_wmask_i,
81 .a_rdata_o,
82 .a_rvalid_o,
83 .a_rerror_o,
84 .b_req_i,
85 .b_write_i,
86 .b_addr_i,
87 .b_wdata_i,
88 .b_wmask_i,
89 .b_rdata_o,
90 .b_rvalid_o,
91 .b_rerror_o,
92 .cfg_i
93 );
lowRISC Contributors802543a2019-08-31 12:12:56 +010094
Michael Schaffnerb6fbb872020-06-05 23:40:49 -070095endmodule : prim_ram_2p_adv