blob: c6af2a6e399591debfcd1c0a79923c3b6409d8b2 [file] [log] [blame]
Matt Venn08cd6eb2020-11-16 12:01:14 +01001`default_nettype none
Ahmed Ghazy2517fa82020-11-08 23:34:41 +02002`ifndef USE_CUSTOM_DFFRAM
3
Manar68e03632020-11-09 13:25:13 +02004module DFFRAM(
Manar61dce922020-11-10 19:26:28 +02005`ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +02006 input VPWR,
7 input VGND,
8`endif
9 input CLK,
10 input [3:0] WE,
11 input EN,
12 input [31:0] Di,
13 output reg [31:0] Do,
14 input [7:0] A
15);
16
Ahmed Ghazy2517fa82020-11-08 23:34:41 +020017
18reg [31:0] mem [0:`MEM_WORDS-1];
19
20always @(posedge CLK) begin
21 if (EN == 1'b1) begin
22 Do <= mem[A];
23 if (WE[0]) mem[A][ 7: 0] <= Di[ 7: 0];
24 if (WE[1]) mem[A][15: 8] <= Di[15: 8];
25 if (WE[2]) mem[A][23:16] <= Di[23:16];
26 if (WE[3]) mem[A][31:24] <= Di[31:24];
27 end
28end
29endmodule
30
Ahmed Ghazy2517fa82020-11-08 23:34:41 +020031`else
Manar68e03632020-11-09 13:25:13 +020032
Manar8f131792020-11-11 16:38:32 +020033module DFFRAM #( parameter COLS=1)
Manar68e03632020-11-09 13:25:13 +020034(
Manar61dce922020-11-10 19:26:28 +020035`ifdef USE_POWER_PINS
36 VPWR,
37 VGND,
38`endif
Manar68e03632020-11-09 13:25:13 +020039 CLK,
40 WE,
41 EN,
42 Di,
43 Do,
Manar61dce922020-11-10 19:26:28 +020044 A
Manar68e03632020-11-09 13:25:13 +020045);
46
47 input CLK;
48 input [3:0] WE;
49 input EN;
50 input [31:0] Di;
51 output [31:0] Do;
Manar8f131792020-11-11 16:38:32 +020052 input [7+$clog2(COLS):0] A;
Manar68e03632020-11-09 13:25:13 +020053
Manar61dce922020-11-10 19:26:28 +020054`ifdef USE_POWER_PINS
Manar68e03632020-11-09 13:25:13 +020055 input VPWR;
56 input VGND;
Manar61dce922020-11-10 19:26:28 +020057`endif
58
Manar8f131792020-11-11 16:38:32 +020059 wire [31:0] DOUT [COLS-1:0];
Manar68e03632020-11-09 13:25:13 +020060 wire [31:0] Do_pre;
Manar8f131792020-11-11 16:38:32 +020061 wire [COLS-1:0] EN_lines;
Manar68e03632020-11-09 13:25:13 +020062
Manar8f131792020-11-11 16:38:32 +020063 generate
64 genvar i;
65 for (i=0; i<COLS; i=i+1) begin : COLUMN
66 DFFRAM_COL4 RAMCOLS (
67 `ifdef USE_POWER_PINS
68 .VPWR(VPWR),
69 .VGND(VGND),
70 `endif
71 .CLK(CLK),
72 .WE(WE),
73 .EN(EN_lines[i]),
74 .Di(Di),
75 .Do(DOUT[i]),
76 .A(A[7:0])
77 );
78 end
79 if(COLS==4) begin
80 MUX4x1_32 MUX (
81 `ifdef USE_POWER_PINS
82 .VPWR(VPWR),
83 .VGND(VGND),
84 `endif
85 .A0(DOUT[0]),
86 .A1(DOUT[1]),
87 .A2(DOUT[2]),
88 .A3(DOUT[3]),
89 .S(A[9:8]),
90 .X(Do_pre)
91 );
92 DEC2x4 DEC (
93 `ifdef USE_POWER_PINS
94 .VPWR(VPWR),
95 .VGND(VGND),
96 `endif
97 .EN(EN),
98 .A(A[9:8]),
99 .SEL(EN_lines)
100 );
101 end
102 else if(COLS==2) begin
103 MUX2x1_32 MUX (
104 `ifdef USE_POWER_PINS
105 .VPWR(VPWR),
106 .VGND(VGND),
107 `endif
108 .A0(DOUT[0]),
109 .A1(DOUT[1]),
110 .S(A[8]),
111 .X(Do_pre)
112 );
113 //sky130_fd_sc_hd__inv_4 DEC0 ( .Y(EN_lines[0]), .A(A[8]) );
114 //sky130_fd_sc_hd__clkbuf_4 DEC1 (.X(EN_lines[1]), .A(A[8]) );
115 DEC1x2 DEC (
116 `ifdef USE_POWER_PINS
117 .VPWR(VPWR),
118 .VGND(VGND),
119 `endif
120 .EN(EN),
121 .A(A[8]),
122 .SEL(EN_lines[1:0])
123 );
124
125 end
126 else begin
127 PASS MUX (
128 `ifdef USE_POWER_PINS
129 .VPWR(VPWR),
130 .VGND(VGND),
131 `endif
132 .A(DOUT[0]),
133 .X(Do_pre)
134 );
135 sky130_fd_sc_hd__clkbuf_4 ENBUF (
136 `ifdef USE_POWER_PINS
137 .VPWR(VPWR),
138 .VGND(VGND),
139 .VPB(VPWR),
140 .VNB(VGND),
141 `endif
142 .X(EN_lines[0]),
143 .A(EN)
144 );
145 end
146 endgenerate
147
148 sky130_fd_sc_hd__clkbuf_4 DOBUF[31:0] (
Manar61dce922020-11-10 19:26:28 +0200149 `ifdef USE_POWER_PINS
150 .VPWR(VPWR),
151 .VGND(VGND),
152 .VPB(VPWR),
153 .VNB(VGND),
154 `endif
Manar8f131792020-11-11 16:38:32 +0200155 .X(Do),
156 .A(Do_pre)
Manar61dce922020-11-10 19:26:28 +0200157 );
Manar68e03632020-11-09 13:25:13 +0200158
Ahmed Ghazy5586f1b2020-11-06 21:34:43 +0200159endmodule
Manar68e03632020-11-09 13:25:13 +0200160
161`endif