agorararmard | 6c766a8 | 2020-12-10 18:13:12 +0200 | [diff] [blame] | 1 | // SPDX-FileCopyrightText: 2020 Efabless Corporation |
agorararmard | e5780bf | 2020-12-09 21:27:56 +0000 | [diff] [blame] | 2 | // |
| 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. |
agorararmard | afa96ea | 2020-12-09 23:37:31 +0200 | [diff] [blame] | 14 | // SPDX-License-Identifier: Apache-2.0 |
agorararmard | e5780bf | 2020-12-09 21:27:56 +0000 | [diff] [blame] | 15 | |
Matt Venn | 08cd6eb | 2020-11-16 12:01:14 +0100 | [diff] [blame] | 16 | `default_nettype none |
Ahmed Ghazy | 2517fa8 | 2020-11-08 23:34:41 +0200 | [diff] [blame] | 17 | `ifndef USE_CUSTOM_DFFRAM |
| 18 | |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 19 | module DFFRAM( |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 20 | `ifdef USE_POWER_PINS |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 21 | 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 Ghazy | 2517fa8 | 2020-11-08 23:34:41 +0200 | [diff] [blame] | 32 | |
| 33 | reg [31:0] mem [0:`MEM_WORDS-1]; |
| 34 | |
| 35 | always @(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 |
| 43 | end |
| 44 | endmodule |
| 45 | |
Ahmed Ghazy | 2517fa8 | 2020-11-08 23:34:41 +0200 | [diff] [blame] | 46 | `else |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 47 | |
Manar | 8f13179 | 2020-11-11 16:38:32 +0200 | [diff] [blame] | 48 | module DFFRAM #( parameter COLS=1) |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 49 | ( |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 50 | `ifdef USE_POWER_PINS |
| 51 | VPWR, |
| 52 | VGND, |
| 53 | `endif |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 54 | CLK, |
| 55 | WE, |
| 56 | EN, |
| 57 | Di, |
| 58 | Do, |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 59 | A |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 60 | ); |
| 61 | |
| 62 | input CLK; |
| 63 | input [3:0] WE; |
| 64 | input EN; |
| 65 | input [31:0] Di; |
| 66 | output [31:0] Do; |
Manar | 8f13179 | 2020-11-11 16:38:32 +0200 | [diff] [blame] | 67 | input [7+$clog2(COLS):0] A; |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 68 | |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 69 | `ifdef USE_POWER_PINS |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 70 | input VPWR; |
| 71 | input VGND; |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 72 | `endif |
| 73 | |
Manar | 8f13179 | 2020-11-11 16:38:32 +0200 | [diff] [blame] | 74 | wire [31:0] DOUT [COLS-1:0]; |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 75 | wire [31:0] Do_pre; |
Manar | 8f13179 | 2020-11-11 16:38:32 +0200 | [diff] [blame] | 76 | wire [COLS-1:0] EN_lines; |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 77 | |
Manar | 8f13179 | 2020-11-11 16:38:32 +0200 | [diff] [blame] | 78 | 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] ( |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 164 | `ifdef USE_POWER_PINS |
| 165 | .VPWR(VPWR), |
| 166 | .VGND(VGND), |
| 167 | .VPB(VPWR), |
| 168 | .VNB(VGND), |
| 169 | `endif |
Manar | 8f13179 | 2020-11-11 16:38:32 +0200 | [diff] [blame] | 170 | .X(Do), |
| 171 | .A(Do_pre) |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 172 | ); |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 173 | |
Ahmed Ghazy | 5586f1b | 2020-11-06 21:34:43 +0200 | [diff] [blame] | 174 | endmodule |
Manar | 68e0363 | 2020-11-09 13:25:13 +0200 | [diff] [blame] | 175 | |
| 176 | `endif |