1 |
11 |
juko |
/*
|
2 |
|
|
* .--------------. .----------------. .------------.
|
3 |
|
|
* | .------------. | .--------------. | .----------. |
|
4 |
|
|
* | | ____ ____ | | | ____ ____ | | | ______ | |
|
5 |
|
|
* | ||_ || _|| | ||_ \ / _|| | | .' ___ || |
|
6 |
|
|
* ___ _ __ ___ _ __ | | | |__| | | | | | \/ | | | |/ .' \_|| |
|
7 |
|
|
* / _ \| '_ \ / _ \ '_ \ | | | __ | | | | | |\ /| | | | || | | |
|
8 |
|
|
* (_) | |_) | __/ | | || | _| | | |_ | | | _| |_\/_| |_ | | |\ `.___.'\| |
|
9 |
|
|
* \___/| .__/ \___|_| |_|| ||____||____|| | ||_____||_____|| | | `._____.'| |
|
10 |
|
|
* | | | | | | | | | | | |
|
11 |
|
|
* |_| | '------------' | '--------------' | '----------' |
|
12 |
|
|
* '--------------' '----------------' '------------'
|
13 |
|
|
*
|
14 |
|
|
* openHMC - An Open Source Hybrid Memory Cube Controller
|
15 |
|
|
* (C) Copyright 2014 Computer Architecture Group - University of Heidelberg
|
16 |
|
|
* www.ziti.uni-heidelberg.de
|
17 |
|
|
* B6, 26
|
18 |
|
|
* 68159 Mannheim
|
19 |
|
|
* Germany
|
20 |
|
|
*
|
21 |
|
|
* Contact: openhmc@ziti.uni-heidelberg.de
|
22 |
|
|
* http://ra.ziti.uni-heidelberg.de/openhmc
|
23 |
|
|
*
|
24 |
|
|
* This source file is free software: you can redistribute it and/or modify
|
25 |
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
26 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
27 |
|
|
* (at your option) any later version.
|
28 |
|
|
*
|
29 |
|
|
* This source file is distributed in the hope that it will be useful,
|
30 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
|
|
* GNU Lesser General Public License for more details.
|
33 |
|
|
*
|
34 |
|
|
* You should have received a copy of the GNU Lesser General Public License
|
35 |
|
|
* along with this source file. If not, see <http://www.gnu.org/licenses/>.
|
36 |
|
|
*
|
37 |
|
|
*
|
38 |
|
|
* Module name: openhmc_sync_fifo
|
39 |
|
|
*
|
40 |
|
|
*/
|
41 |
|
|
|
42 |
|
|
`default_nettype none
|
43 |
|
|
|
44 |
|
|
module openhmc_sync_fifo #(
|
45 |
|
|
`ifdef CAG_ASSERTIONS
|
46 |
|
|
parameter DISABLE_EMPTY_ASSERT = 0,
|
47 |
|
|
parameter DISABLE_SHIFT_OUT_ASSERT = 0,
|
48 |
|
|
parameter DISABLE_XCHECK_ASSERT = 0,
|
49 |
|
|
`endif
|
50 |
|
|
parameter DATASIZE = 8,
|
51 |
|
|
parameter ADDRSIZE = 8
|
52 |
|
|
) (
|
53 |
|
|
//----------------------------------
|
54 |
|
|
//----SYSTEM INTERFACE
|
55 |
|
|
//----------------------------------
|
56 |
|
|
input wire clk,
|
57 |
|
|
input wire res_n,
|
58 |
|
|
|
59 |
|
|
//----------------------------------
|
60 |
|
|
//----Signals
|
61 |
|
|
//----------------------------------
|
62 |
|
|
input wire [DATASIZE-1:0] d_in,
|
63 |
|
|
input wire shift_in,
|
64 |
|
|
input wire shift_out,
|
65 |
|
|
output wire [DATASIZE-1:0] d_out,
|
66 |
|
|
output wire empty
|
67 |
|
|
);
|
68 |
|
|
|
69 |
|
|
//=====================================================================================================
|
70 |
|
|
//-----------------------------------------------------------------------------------------------------
|
71 |
|
|
//---------WIRING AND SIGNAL STUFF---------------------------------------------------------------------
|
72 |
|
|
//-----------------------------------------------------------------------------------------------------
|
73 |
|
|
//=====================================================================================================
|
74 |
|
|
|
75 |
|
|
wire si, so; // internal gated shift signals
|
76 |
|
|
reg full_r1, full_r2;
|
77 |
|
|
wire full_1, full_2, full_3;
|
78 |
|
|
reg full_m2, full_m1;
|
79 |
|
|
|
80 |
|
|
reg [DATASIZE-1:0] d_out_r1, d_out_r2;
|
81 |
|
|
wire [DATASIZE-1:0] d_out_m2, d_out_2, d_out_3;
|
82 |
|
|
wire mux_rm_2;
|
83 |
|
|
|
84 |
|
|
reg [ADDRSIZE -1:0] ra_m, wa_m; //addr after register similar to signal internal to sram
|
85 |
|
|
reg [ADDRSIZE -1:0] ra, wa; // address calculated for the next read
|
86 |
|
|
wire wen, ren;
|
87 |
|
|
|
88 |
|
|
wire m_empty;
|
89 |
|
|
|
90 |
|
|
assign full_1 = full_r1 || full_m1 || (full_m2 && full_r2);
|
91 |
|
|
assign full_2 = full_r2 || full_m2;
|
92 |
|
|
|
93 |
|
|
//=====================================================================================================
|
94 |
|
|
//-----------------------------------------------------------------------------------------------------
|
95 |
|
|
//---------LOGIC STARTS HERE---------------------------------------------------------------------------
|
96 |
|
|
//-----------------------------------------------------------------------------------------------------
|
97 |
|
|
//=====================================================================================================
|
98 |
|
|
|
99 |
|
|
always @ (posedge clk or negedge res_n) begin
|
100 |
|
|
if (!res_n) begin
|
101 |
|
|
d_out_r1 <= {DATASIZE {1'b0}};
|
102 |
|
|
d_out_r2 <= {DATASIZE {1'b0}};
|
103 |
|
|
full_r1 <= 1'b0;
|
104 |
|
|
full_r2 <= 1'b0;
|
105 |
|
|
end else begin
|
106 |
|
|
|
107 |
|
|
// Register stage 1 (conditions shouldn't overlap)
|
108 |
|
|
if ((full_2 && !full_1 && si && !so) || // fill stage
|
109 |
|
|
(full_1 && m_empty && si && so)) begin // shift through
|
110 |
|
|
d_out_r1 <= d_in;
|
111 |
|
|
full_r1 <= 1'b1;
|
112 |
|
|
end
|
113 |
|
|
if (full_r1 && so && (!si || !m_empty)) begin // shift out
|
114 |
|
|
full_r1 <= 1'b0;
|
115 |
|
|
end
|
116 |
|
|
|
117 |
|
|
// Register stage 2 (conditions shouldn't overlap)
|
118 |
|
|
if (full_3 && ((!full_2 && si && !so) || // fill stage
|
119 |
|
|
(full_2 && !full_1 && si && so))) begin // shift through
|
120 |
|
|
d_out_r2 <= d_in;
|
121 |
|
|
full_r2 <= 1'b1;
|
122 |
|
|
end
|
123 |
|
|
if (full_r1 && so) begin // shift through
|
124 |
|
|
d_out_r2 <= d_out_r1;
|
125 |
|
|
full_r2 <= 1'b1;
|
126 |
|
|
end
|
127 |
|
|
if (full_m2 && ((!full_r2 && !so) || // Rescue
|
128 |
|
|
(full_r2 && so))) begin
|
129 |
|
|
d_out_r2 <= d_out_m2;
|
130 |
|
|
full_r2 <= 1'b1;
|
131 |
|
|
end
|
132 |
|
|
if (full_r2 &&
|
133 |
|
|
((!full_r1 && !full_m2 && so && !si) || // shift out
|
134 |
|
|
(full_m1 && si && so))) begin // shift through with RAM
|
135 |
|
|
full_r2 <= 1'b0;
|
136 |
|
|
end
|
137 |
|
|
end
|
138 |
|
|
end
|
139 |
|
|
|
140 |
|
|
// assign outputs and inputs to module interface
|
141 |
|
|
assign d_out = d_out_3;
|
142 |
|
|
|
143 |
|
|
assign empty = !full_3; // if the last stage is empty, the fifo is empty
|
144 |
|
|
|
145 |
|
|
assign si = shift_in;
|
146 |
|
|
assign so = shift_out;
|
147 |
|
|
|
148 |
|
|
wire [ADDRSIZE:0] fifo_ram_count = wa_m - ra_m;
|
149 |
|
|
|
150 |
|
|
assign mux_rm_2 = full_r2; // mux control of SRAM data bypass if only one value in stage r2
|
151 |
|
|
assign d_out_2 = mux_rm_2 ? d_out_r2 : d_out_m2; // additional data mux for SRAM bypass
|
152 |
|
|
|
153 |
|
|
// write port control of SRAM
|
154 |
|
|
assign wen = si && !so && full_1 // enter new value into SRAM, because regs are filled
|
155 |
|
|
|| si && !m_empty; // if a value is in the SRAM, then we have to shift through or shift in
|
156 |
|
|
|
157 |
|
|
// read port control of SRAM
|
158 |
|
|
assign ren = so && !m_empty;
|
159 |
|
|
|
160 |
|
|
assign m_empty = (wa_m == ra_m);
|
161 |
|
|
|
162 |
|
|
always @ (posedge clk or negedge res_n) begin
|
163 |
|
|
if (!res_n) begin
|
164 |
|
|
full_m1 <= 1'b0;
|
165 |
|
|
full_m2 <= 1'b0;
|
166 |
|
|
end else begin
|
167 |
|
|
full_m1 <= ren; // no control of m1
|
168 |
|
|
full_m2 <= full_m1
|
169 |
|
|
|| full_m2 && !so && full_r2; // no rescue possible
|
170 |
|
|
end
|
171 |
|
|
end
|
172 |
|
|
|
173 |
|
|
// pointer management
|
174 |
|
|
always @(*) begin
|
175 |
|
|
wa = wa_m + 1'b1; // wa_m is the address stored in mem addr register
|
176 |
|
|
ra = ra_m + 1'b1;
|
177 |
|
|
end
|
178 |
|
|
|
179 |
|
|
always @ (posedge clk or negedge res_n) begin
|
180 |
|
|
if (!res_n) begin
|
181 |
|
|
wa_m <= {ADDRSIZE {1'b0}};
|
182 |
|
|
ra_m <= {ADDRSIZE {1'b0}};
|
183 |
|
|
end else begin
|
184 |
|
|
if (wen) begin
|
185 |
|
|
wa_m <= wa; // next mem write addr to mem addr register
|
186 |
|
|
end
|
187 |
|
|
|
188 |
|
|
if (ren) begin
|
189 |
|
|
ra_m <= ra;
|
190 |
|
|
end
|
191 |
|
|
end
|
192 |
|
|
end
|
193 |
|
|
|
194 |
|
|
//=====================================================================================================
|
195 |
|
|
//-----------------------------------------------------------------------------------------------------
|
196 |
|
|
//---------INSTANTIATIONS HERE-------------------------------------------------------------------------
|
197 |
|
|
//-----------------------------------------------------------------------------------------------------
|
198 |
|
|
//=====================================================================================================
|
199 |
|
|
openhmc_sync_fifo_reg_stage #(.DWIDTH(DATASIZE))
|
200 |
|
|
sync_fifo_reg_stage_3_I (
|
201 |
|
|
.clk(clk),
|
202 |
|
|
.res_n(res_n),
|
203 |
|
|
.d_in(d_in),
|
204 |
|
|
.d_in_p(d_out_2),
|
205 |
|
|
.p_full(full_2),
|
206 |
|
|
.n_full(1'b1),
|
207 |
|
|
.si(si),
|
208 |
|
|
.so(so),
|
209 |
|
|
.full(full_3),
|
210 |
|
|
.d_out(d_out_3)
|
211 |
|
|
);
|
212 |
|
|
|
213 |
|
|
openhmc_ram #(
|
214 |
|
|
.DATASIZE(DATASIZE), // Memory data word width
|
215 |
|
|
.ADDRSIZE(ADDRSIZE), // Number of memory address bits
|
216 |
|
|
.PIPELINED(1)
|
217 |
|
|
)
|
218 |
|
|
ram(
|
219 |
|
|
.clk(clk),
|
220 |
|
|
.wen(wen),
|
221 |
|
|
.wdata(d_in),
|
222 |
|
|
.waddr(wa),
|
223 |
|
|
.ren(ren),
|
224 |
|
|
.raddr(ra),
|
225 |
|
|
.rdata(d_out_m2)
|
226 |
|
|
);
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
`ifdef CAG_ASSERTIONS
|
230 |
|
|
|
231 |
|
|
if (DISABLE_SHIFT_OUT_ASSERT == 0)
|
232 |
|
|
shift_out_and_empty: assert property (@(posedge clk) disable iff(!res_n) (shift_out |-> !empty));
|
233 |
|
|
|
234 |
|
|
if (DISABLE_XCHECK_ASSERT == 0)
|
235 |
|
|
dout_known: assert property (@(posedge clk) disable iff(!res_n) (!empty |-> !$isunknown(d_out)));
|
236 |
|
|
|
237 |
|
|
final
|
238 |
|
|
begin
|
239 |
|
|
if (DISABLE_EMPTY_ASSERT == 0)
|
240 |
|
|
begin
|
241 |
|
|
empty_not_set_assert: assert (empty);
|
242 |
|
|
end
|
243 |
|
|
end
|
244 |
|
|
|
245 |
|
|
`endif // CAG_ASSERTIONS
|
246 |
|
|
|
247 |
|
|
endmodule
|
248 |
|
|
|
249 |
|
|
`default_nettype wire
|
250 |
|
|
|