lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | // 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 Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 5 | // Dual-Port SRAM Wrapper |
| 6 | // |
| 7 | // Supported configurations: |
Michael Schaffner | c8ee5cb | 2020-12-23 13:42:35 -0800 | [diff] [blame] | 8 | // - ECC for 32b and 64b wide memories with no write mask |
| 9 | // (Width == 32 or Width == 64, DataBitsPerMask is ignored). |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 10 | // - 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 Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 15 | |
Greg Chadwick | cf42308 | 2020-02-05 16:52:23 +0000 | [diff] [blame] | 16 | `include "prim_assert.sv" |
| 17 | |
Timothy Chen | 685d649 | 2021-03-09 21:28:39 -0800 | [diff] [blame] | 18 | module prim_ram_2p_adv import prim_ram_2p_pkg::*; #( |
Philipp Wagner | 80cc923 | 2020-05-21 18:21:34 +0100 | [diff] [blame] | 19 | parameter int Depth = 512, |
| 20 | parameter int Width = 32, |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 21 | parameter int DataBitsPerMask = 1, // Number of data bits per bit of write mask |
Philipp Wagner | 7ad130c | 2020-05-21 18:34:24 +0100 | [diff] [blame] | 22 | parameter MemInitFile = "", // VMEM file to initialize the memory with |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 23 | |
| 24 | // Configurations |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 25 | 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 Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 29 | |
Michael Schaffner | f561a2a | 2021-01-25 18:19:40 -0800 | [diff] [blame] | 30 | // 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 Wagner | eeaa69d | 2020-06-23 14:32:34 +0100 | [diff] [blame] | 35 | localparam int Aw = prim_util_pkg::vbits(Depth) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 36 | ) ( |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 37 | input clk_i, |
| 38 | input rst_ni, |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 39 | |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 40 | 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 Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 48 | |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 49 | 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 Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 57 | |
Timothy Chen | 685d649 | 2021-03-09 21:28:39 -0800 | [diff] [blame] | 58 | input ram_2p_cfg_t cfg_i |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 59 | ); |
| 60 | |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 61 | prim_ram_2p_async_adv #( |
| 62 | .Depth (Depth), |
| 63 | .Width (Width), |
| 64 | .DataBitsPerMask (DataBitsPerMask), |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 65 | .MemInitFile (MemInitFile), |
| 66 | .EnableECC (EnableECC), |
| 67 | .EnableParity (EnableParity), |
| 68 | .EnableInputPipeline (EnableInputPipeline), |
Michael Schaffner | f561a2a | 2021-01-25 18:19:40 -0800 | [diff] [blame] | 69 | .EnableOutputPipeline(EnableOutputPipeline), |
| 70 | .HammingECC (HammingECC) |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 71 | ) 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 Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 94 | |
Michael Schaffner | b6fbb87 | 2020-06-05 23:40:49 -0700 | [diff] [blame] | 95 | endmodule : prim_ram_2p_adv |