2021-02-14 21:06:53 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// SRAM2P1R1W
|
|
|
|
//
|
|
|
|
// Written: Ross Thomposn
|
|
|
|
// Email: ross1728@gmail.com
|
|
|
|
// Created: February 14, 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
2021-02-18 04:19:17 +00:00
|
|
|
// Purpose: Behavioral model of two port SRAM. While this is synthesizable it will produce a flip flop based memory whi
|
|
|
|
// behaves with the timing of an SRAM typical of GF 14nm, 32nm, and 45nm.
|
|
|
|
//
|
2021-02-14 21:06:53 +00:00
|
|
|
//
|
2021-02-18 04:19:17 +00:00
|
|
|
// to preload this memory we can use the following command
|
|
|
|
// in modelsim's do file.
|
|
|
|
// mem load -infile <relative path to the text file > -format <bin|hex> <hierarchy to the memory.>
|
|
|
|
// example
|
2022-01-20 16:02:08 +00:00
|
|
|
// mem load -infile twoBitPredictor.txt -format bin testbench/dut/core/ifu/bpred/DirPredictor/memory/memory
|
2021-02-18 04:19:17 +00:00
|
|
|
//
|
2021-02-14 21:06:53 +00:00
|
|
|
// A component of the Wally configurable RISC-V project.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
|
|
|
|
//
|
2022-01-07 12:58:40 +00:00
|
|
|
// MIT LICENSE
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
|
|
|
// software and associated documentation files (the "Software"), to deal in the Software
|
|
|
|
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
|
|
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
|
|
|
// to whom the Software is furnished to do so, subject to the following conditions:
|
2021-02-14 21:06:53 +00:00
|
|
|
//
|
2022-01-07 12:58:40 +00:00
|
|
|
// The above copyright notice and this permission notice shall be included in all copies or
|
|
|
|
// substantial portions of the Software.
|
2021-02-14 21:06:53 +00:00
|
|
|
//
|
2022-01-07 12:58:40 +00:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
|
|
|
// OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-02-14 21:06:53 +00:00
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module SRAM2P1R1W
|
2021-10-23 13:28:49 +00:00
|
|
|
#(parameter int DEPTH = 10,
|
|
|
|
parameter int WIDTH = 2
|
2021-02-18 04:19:17 +00:00
|
|
|
)
|
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
(input logic clk,
|
2021-02-19 03:32:15 +00:00
|
|
|
// *** have to remove reset eventually
|
2021-10-27 19:43:55 +00:00
|
|
|
input logic reset,
|
2021-02-19 03:32:15 +00:00
|
|
|
|
2021-02-14 21:06:53 +00:00
|
|
|
// port 1 is read only
|
2021-10-23 13:28:49 +00:00
|
|
|
input logic [DEPTH-1:0] RA1,
|
|
|
|
output logic [WIDTH-1:0] RD1,
|
2021-10-27 19:43:55 +00:00
|
|
|
input logic REN1,
|
2021-02-14 21:06:53 +00:00
|
|
|
|
|
|
|
// port 2 is write only
|
2021-10-23 13:28:49 +00:00
|
|
|
input logic [DEPTH-1:0] WA1,
|
|
|
|
input logic [WIDTH-1:0] WD1,
|
2021-10-27 19:43:55 +00:00
|
|
|
input logic WEN1,
|
2021-10-23 13:28:49 +00:00
|
|
|
input logic [WIDTH-1:0] BitWEN1
|
2021-02-14 21:06:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
logic [DEPTH-1:0] RA1Q, WA1Q;
|
|
|
|
logic WEN1Q;
|
|
|
|
logic [WIDTH-1:0] WD1Q;
|
2021-02-14 21:06:53 +00:00
|
|
|
|
2021-10-27 19:43:55 +00:00
|
|
|
logic [WIDTH-1:0] mem[2**DEPTH-1:0];
|
2022-03-09 17:49:28 +00:00
|
|
|
logic [WIDTH-1:0] bwe;
|
2021-02-18 04:19:17 +00:00
|
|
|
|
2021-02-14 21:06:53 +00:00
|
|
|
|
|
|
|
// SRAMs address busses are always registered first.
|
|
|
|
|
2021-10-23 13:28:49 +00:00
|
|
|
flopenr #(DEPTH) RA1Reg(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(REN1),
|
|
|
|
.d(RA1),
|
|
|
|
.q(RA1Q));
|
2021-02-14 21:06:53 +00:00
|
|
|
|
|
|
|
|
2021-10-23 13:28:49 +00:00
|
|
|
flopenr #(DEPTH) WA1Reg(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(REN1),
|
|
|
|
.d(WA1),
|
|
|
|
.q(WA1Q));
|
2021-02-14 21:06:53 +00:00
|
|
|
|
|
|
|
flopenr #(1) WEN1Reg(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(1'b1),
|
|
|
|
.d(WEN1),
|
|
|
|
.q(WEN1Q));
|
2021-02-14 21:06:53 +00:00
|
|
|
|
2021-10-23 13:28:49 +00:00
|
|
|
flopenr #(WIDTH) WD1Reg(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(REN1),
|
|
|
|
.d(WD1),
|
|
|
|
.q(WD1Q));
|
2021-02-14 21:06:53 +00:00
|
|
|
// read port
|
2021-10-23 13:28:49 +00:00
|
|
|
assign RD1 = mem[RA1Q];
|
2021-02-14 21:06:53 +00:00
|
|
|
|
|
|
|
// write port
|
2022-03-09 17:49:28 +00:00
|
|
|
assign bwe = {WIDTH{WEN1Q}} & BitWEN1;
|
2022-03-09 19:09:20 +00:00
|
|
|
always_ff @(posedge clk)
|
2022-03-09 17:49:28 +00:00
|
|
|
mem[WA1Q] <= WD1Q & bwe | mem[WA1Q] & ~bwe;
|
2022-01-05 14:35:25 +00:00
|
|
|
|
2021-02-14 21:06:53 +00:00
|
|
|
endmodule
|
|
|
|
|
|
|
|
|