blob: b80677f2bc36038fe1e222f94f6e88cd8a7514b5 [file] [log] [blame]
agorararmard6c766a82020-12-10 18:13:12 +02001// SPDX-FileCopyrightText: 2020 Efabless Corporation
agorararmarde5780bf2020-12-09 21:27:56 +00002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
agorararmardafa96ea2020-12-09 23:37:31 +020014// SPDX-License-Identifier: Apache-2.0
agorararmarde5780bf2020-12-09 21:27:56 +000015
Matt Venn08cd6eb2020-11-16 12:01:14 +010016`default_nettype none
Ahmed Ghazy2517fa82020-11-08 23:34:41 +020017`ifndef USE_CUSTOM_DFFRAM
18
Manar68e03632020-11-09 13:25:13 +020019module DFFRAM(
Manar61dce922020-11-10 19:26:28 +020020`ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +020021 input VPWR,
22 input VGND,
23`endif
24 input CLK,
25 input [3:0] WE,
26 input EN,
27 input [31:0] Di,
28 output reg [31:0] Do,
29 input [7:0] A
30);
31
Ahmed Ghazy2517fa82020-11-08 23:34:41 +020032
33reg [31:0] mem [0:`MEM_WORDS-1];
34
35always @(posedge CLK) begin
36 if (EN == 1'b1) begin
37 Do <= mem[A];
38 if (WE[0]) mem[A][ 7: 0] <= Di[ 7: 0];
39 if (WE[1]) mem[A][15: 8] <= Di[15: 8];
40 if (WE[2]) mem[A][23:16] <= Di[23:16];
41 if (WE[3]) mem[A][31:24] <= Di[31:24];
42 end
43end
44endmodule
45
Ahmed Ghazy2517fa82020-11-08 23:34:41 +020046`else
Manar68e03632020-11-09 13:25:13 +020047
Manar8f131792020-11-11 16:38:32 +020048module DFFRAM #( parameter COLS=1)
Manar68e03632020-11-09 13:25:13 +020049(
Manar61dce922020-11-10 19:26:28 +020050`ifdef USE_POWER_PINS
51 VPWR,
52 VGND,
53`endif
Manar68e03632020-11-09 13:25:13 +020054 CLK,
55 WE,
56 EN,
57 Di,
58 Do,
Manar61dce922020-11-10 19:26:28 +020059 A
Manar68e03632020-11-09 13:25:13 +020060);
61
62 input CLK;
63 input [3:0] WE;
64 input EN;
65 input [31:0] Di;
66 output [31:0] Do;
Manar8f131792020-11-11 16:38:32 +020067 input [7+$clog2(COLS):0] A;
Manar68e03632020-11-09 13:25:13 +020068
Manar61dce922020-11-10 19:26:28 +020069`ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +020070 input VPWR;
71 input VGND;
Manar61dce922020-11-10 19:26:28 +020072`endif
73
Manar8f131792020-11-11 16:38:32 +020074 wire [31:0] DOUT [COLS-1:0];
Manar68e03632020-11-09 13:25:13 +020075 wire [31:0] Do_pre;
Manar8f131792020-11-11 16:38:32 +020076 wire [COLS-1:0] EN_lines;
Manar68e03632020-11-09 13:25:13 +020077
Manar8f131792020-11-11 16:38:32 +020078 generate
79 genvar i;
80 for (i=0; i<COLS; i=i+1) begin : COLUMN
81 DFFRAM_COL4 RAMCOLS (
82 `ifdef USE_POWER_PINS
83 .VPWR(VPWR),
84 .VGND(VGND),
85 `endif
86 .CLK(CLK),
87 .WE(WE),
88 .EN(EN_lines[i]),
89 .Di(Di),
90 .Do(DOUT[i]),
91 .A(A[7:0])
92 );
93 end
94 if(COLS==4) begin
95 MUX4x1_32 MUX (
96 `ifdef USE_POWER_PINS
97 .VPWR(VPWR),
98 .VGND(VGND),
99 `endif
100 .A0(DOUT[0]),
101 .A1(DOUT[1]),
102 .A2(DOUT[2]),
103 .A3(DOUT[3]),
104 .S(A[9:8]),
105 .X(Do_pre)
106 );
107 DEC2x4 DEC (
108 `ifdef USE_POWER_PINS
109 .VPWR(VPWR),
110 .VGND(VGND),
111 `endif
112 .EN(EN),
113 .A(A[9:8]),
114 .SEL(EN_lines)
115 );
116 end
117 else if(COLS==2) begin
118 MUX2x1_32 MUX (
119 `ifdef USE_POWER_PINS
120 .VPWR(VPWR),
121 .VGND(VGND),
122 `endif
123 .A0(DOUT[0]),
124 .A1(DOUT[1]),
125 .S(A[8]),
126 .X(Do_pre)
127 );
128 //sky130_fd_sc_hd__inv_4 DEC0 ( .Y(EN_lines[0]), .A(A[8]) );
129 //sky130_fd_sc_hd__clkbuf_4 DEC1 (.X(EN_lines[1]), .A(A[8]) );
130 DEC1x2 DEC (
131 `ifdef USE_POWER_PINS
132 .VPWR(VPWR),
133 .VGND(VGND),
134 `endif
135 .EN(EN),
136 .A(A[8]),
137 .SEL(EN_lines[1:0])
138 );
139
140 end
141 else begin
142 PASS MUX (
143 `ifdef USE_POWER_PINS
144 .VPWR(VPWR),
145 .VGND(VGND),
146 `endif
147 .A(DOUT[0]),
148 .X(Do_pre)
149 );
150 sky130_fd_sc_hd__clkbuf_4 ENBUF (
151 `ifdef USE_POWER_PINS
152 .VPWR(VPWR),
153 .VGND(VGND),
154 .VPB(VPWR),
155 .VNB(VGND),
156 `endif
157 .X(EN_lines[0]),
158 .A(EN)
159 );
160 end
161 endgenerate
162
163 sky130_fd_sc_hd__clkbuf_4 DOBUF[31:0] (
Manar61dce922020-11-10 19:26:28 +0200164 `ifdef USE_POWER_PINS
165 .VPWR(VPWR),
166 .VGND(VGND),
167 .VPB(VPWR),
168 .VNB(VGND),
169 `endif
Manar8f131792020-11-11 16:38:32 +0200170 .X(Do),
171 .A(Do_pre)
Manar61dce922020-11-10 19:26:28 +0200172 );
Manar68e03632020-11-09 13:25:13 +0200173
Ahmed Ghazy5586f1b2020-11-06 21:34:43 +0200174endmodule
Manar68e03632020-11-09 13:25:13 +0200175
176`endif