1 |
32 |
redbear |
// (C) 2001-2017 Intel Corporation. All rights reserved.
|
2 |
|
|
// Your use of Intel Corporation's design tools, logic functions and other
|
3 |
|
|
// software and tools, and its AMPP partner logic functions, and any output
|
4 |
|
|
// files any of the foregoing (including device programming or simulation
|
5 |
|
|
// files), and any associated documentation or information are expressly subject
|
6 |
|
|
// to the terms and conditions of the Intel Program License Subscription
|
7 |
|
|
// Agreement, Intel MegaCore Function License Agreement, or other applicable
|
8 |
|
|
// license agreement, including, without limitation, that your use is for the
|
9 |
|
|
// sole purpose of programming logic devices manufactured by Intel and sold by
|
10 |
|
|
// Intel or its authorized distributors. Please refer to the applicable
|
11 |
|
|
// agreement for further details.
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
// (C) 2001-2014 Altera Corporation. All rights reserved.
|
15 |
|
|
// Your use of Altera Corporation's design tools, logic functions and other
|
16 |
|
|
// software and tools, and its AMPP partner logic functions, and any output
|
17 |
|
|
// files any of the foregoing (including device programming or simulation
|
18 |
|
|
// files), and any associated documentation or information are expressly subject
|
19 |
|
|
// to the terms and conditions of the Altera Program License Subscription
|
20 |
|
|
// Agreement, Altera MegaCore Function License Agreement, or other applicable
|
21 |
|
|
// license agreement, including, without limitation, that your use is for the
|
22 |
|
|
// sole purpose of programming logic devices manufactured by Altera and sold by
|
23 |
|
|
// Altera or its authorized distributors. Please refer to the applicable
|
24 |
|
|
// agreement for further details.
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
// $Id: //acds/rel/17.0std/ip/merlin/altera_merlin_multiplexer/altera_merlin_multiplexer.sv.terp#1 $
|
28 |
|
|
// $Revision: #1 $
|
29 |
|
|
// $Date: 2017/01/22 $
|
30 |
|
|
// $Author: swbranch $
|
31 |
|
|
|
32 |
|
|
// ------------------------------------------
|
33 |
|
|
// Merlin Multiplexer
|
34 |
|
|
// ------------------------------------------
|
35 |
|
|
|
36 |
|
|
`timescale 1 ns / 1 ns
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
// ------------------------------------------
|
40 |
|
|
// Generation parameters:
|
41 |
|
|
// output_name: ulight_fifo_mm_interconnect_0_cmd_mux
|
42 |
|
|
// NUM_INPUTS: 2
|
43 |
|
|
// ARBITRATION_SHARES: 1 1
|
44 |
|
|
// ARBITRATION_SCHEME "round-robin"
|
45 |
|
|
// PIPELINE_ARB: 1
|
46 |
|
|
// PKT_TRANS_LOCK: 70 (arbitration locking enabled)
|
47 |
|
|
// ST_DATA_W: 129
|
48 |
|
|
// ST_CHANNEL_W: 22
|
49 |
|
|
// ------------------------------------------
|
50 |
|
|
|
51 |
|
|
module ulight_fifo_mm_interconnect_0_cmd_mux
|
52 |
|
|
(
|
53 |
|
|
// ----------------------
|
54 |
|
|
// Sinks
|
55 |
|
|
// ----------------------
|
56 |
|
|
input sink0_valid,
|
57 |
|
|
input [129-1 : 0] sink0_data,
|
58 |
|
|
input [22-1: 0] sink0_channel,
|
59 |
|
|
input sink0_startofpacket,
|
60 |
|
|
input sink0_endofpacket,
|
61 |
|
|
output sink0_ready,
|
62 |
|
|
|
63 |
|
|
input sink1_valid,
|
64 |
|
|
input [129-1 : 0] sink1_data,
|
65 |
|
|
input [22-1: 0] sink1_channel,
|
66 |
|
|
input sink1_startofpacket,
|
67 |
|
|
input sink1_endofpacket,
|
68 |
|
|
output sink1_ready,
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
// ----------------------
|
72 |
|
|
// Source
|
73 |
|
|
// ----------------------
|
74 |
|
|
output src_valid,
|
75 |
|
|
output [129-1 : 0] src_data,
|
76 |
|
|
output [22-1 : 0] src_channel,
|
77 |
|
|
output src_startofpacket,
|
78 |
|
|
output src_endofpacket,
|
79 |
|
|
input src_ready,
|
80 |
|
|
|
81 |
|
|
// ----------------------
|
82 |
|
|
// Clock & Reset
|
83 |
|
|
// ----------------------
|
84 |
|
|
input clk,
|
85 |
|
|
input reset
|
86 |
|
|
);
|
87 |
|
|
localparam PAYLOAD_W = 129 + 22 + 2;
|
88 |
|
|
localparam NUM_INPUTS = 2;
|
89 |
|
|
localparam SHARE_COUNTER_W = 1;
|
90 |
|
|
localparam PIPELINE_ARB = 1;
|
91 |
|
|
localparam ST_DATA_W = 129;
|
92 |
|
|
localparam ST_CHANNEL_W = 22;
|
93 |
|
|
localparam PKT_TRANS_LOCK = 70;
|
94 |
|
|
|
95 |
|
|
// ------------------------------------------
|
96 |
|
|
// Signals
|
97 |
|
|
// ------------------------------------------
|
98 |
|
|
wire [NUM_INPUTS - 1 : 0] request;
|
99 |
|
|
wire [NUM_INPUTS - 1 : 0] valid;
|
100 |
|
|
wire [NUM_INPUTS - 1 : 0] grant;
|
101 |
|
|
wire [NUM_INPUTS - 1 : 0] next_grant;
|
102 |
|
|
reg [NUM_INPUTS - 1 : 0] saved_grant;
|
103 |
|
|
reg [PAYLOAD_W - 1 : 0] src_payload;
|
104 |
|
|
wire last_cycle;
|
105 |
|
|
reg packet_in_progress;
|
106 |
|
|
reg update_grant;
|
107 |
|
|
|
108 |
|
|
wire [PAYLOAD_W - 1 : 0] sink0_payload;
|
109 |
|
|
wire [PAYLOAD_W - 1 : 0] sink1_payload;
|
110 |
|
|
|
111 |
|
|
assign valid[0] = sink0_valid;
|
112 |
|
|
assign valid[1] = sink1_valid;
|
113 |
|
|
|
114 |
|
|
wire [NUM_INPUTS - 1 : 0] eop;
|
115 |
|
|
assign eop[0] = sink0_endofpacket;
|
116 |
|
|
assign eop[1] = sink1_endofpacket;
|
117 |
|
|
|
118 |
|
|
// ------------------------------------------
|
119 |
|
|
// ------------------------------------------
|
120 |
|
|
// Grant Logic & Updates
|
121 |
|
|
// ------------------------------------------
|
122 |
|
|
// ------------------------------------------
|
123 |
|
|
reg [NUM_INPUTS - 1 : 0] lock;
|
124 |
|
|
always @* begin
|
125 |
|
|
lock[0] = sink0_data[70];
|
126 |
|
|
lock[1] = sink1_data[70];
|
127 |
|
|
end
|
128 |
|
|
reg [NUM_INPUTS - 1 : 0] locked = '0;
|
129 |
|
|
always @(posedge clk or posedge reset) begin
|
130 |
|
|
if (reset) begin
|
131 |
|
|
locked <= '0;
|
132 |
|
|
end
|
133 |
|
|
else begin
|
134 |
|
|
locked <= next_grant & lock;
|
135 |
|
|
end
|
136 |
|
|
end
|
137 |
|
|
|
138 |
|
|
assign last_cycle = src_valid & src_ready & src_endofpacket & ~(|(lock & grant));
|
139 |
|
|
|
140 |
|
|
// ------------------------------------------
|
141 |
|
|
// We're working on a packet at any time valid is high, except
|
142 |
|
|
// when this is the endofpacket.
|
143 |
|
|
// ------------------------------------------
|
144 |
|
|
always @(posedge clk or posedge reset) begin
|
145 |
|
|
if (reset) begin
|
146 |
|
|
packet_in_progress <= 1'b0;
|
147 |
|
|
end
|
148 |
|
|
else begin
|
149 |
|
|
if (last_cycle)
|
150 |
|
|
packet_in_progress <= 1'b0;
|
151 |
|
|
else if (src_valid)
|
152 |
|
|
packet_in_progress <= 1'b1;
|
153 |
|
|
end
|
154 |
|
|
end
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
// ------------------------------------------
|
158 |
|
|
// Shares
|
159 |
|
|
//
|
160 |
|
|
// Special case: all-equal shares _should_ be optimized into assigning a
|
161 |
|
|
// constant to next_grant_share.
|
162 |
|
|
// Special case: all-1's shares _should_ result in the share counter
|
163 |
|
|
// being optimized away.
|
164 |
|
|
// ------------------------------------------
|
165 |
|
|
// Input | arb shares | counter load value
|
166 |
|
|
// 0 | 1 | 0
|
167 |
|
|
// 1 | 1 | 0
|
168 |
|
|
wire [SHARE_COUNTER_W - 1 : 0] share_0 = 1'd0;
|
169 |
|
|
wire [SHARE_COUNTER_W - 1 : 0] share_1 = 1'd0;
|
170 |
|
|
|
171 |
|
|
// ------------------------------------------
|
172 |
|
|
// Choose the share value corresponding to the grant.
|
173 |
|
|
// ------------------------------------------
|
174 |
|
|
reg [SHARE_COUNTER_W - 1 : 0] next_grant_share;
|
175 |
|
|
always @* begin
|
176 |
|
|
next_grant_share =
|
177 |
|
|
share_0 & { SHARE_COUNTER_W {next_grant[0]} } |
|
178 |
|
|
share_1 & { SHARE_COUNTER_W {next_grant[1]} };
|
179 |
|
|
end
|
180 |
|
|
|
181 |
|
|
// ------------------------------------------
|
182 |
|
|
// Flag to indicate first packet of an arb sequence.
|
183 |
|
|
// ------------------------------------------
|
184 |
|
|
|
185 |
|
|
// ------------------------------------------
|
186 |
|
|
// Compute the next share-count value.
|
187 |
|
|
// ------------------------------------------
|
188 |
|
|
reg [SHARE_COUNTER_W - 1 : 0] p1_share_count;
|
189 |
|
|
reg [SHARE_COUNTER_W - 1 : 0] share_count;
|
190 |
|
|
reg share_count_zero_flag;
|
191 |
|
|
|
192 |
|
|
always @* begin
|
193 |
|
|
// Update the counter, but don't decrement below 0.
|
194 |
|
|
p1_share_count = share_count_zero_flag ? '0 : share_count - 1'b1;
|
195 |
|
|
end
|
196 |
|
|
|
197 |
|
|
// ------------------------------------------
|
198 |
|
|
// Update the share counter and share-counter=zero flag.
|
199 |
|
|
// ------------------------------------------
|
200 |
|
|
always @(posedge clk or posedge reset) begin
|
201 |
|
|
if (reset) begin
|
202 |
|
|
share_count <= '0;
|
203 |
|
|
share_count_zero_flag <= 1'b1;
|
204 |
|
|
end
|
205 |
|
|
else begin
|
206 |
|
|
if (update_grant) begin
|
207 |
|
|
share_count <= next_grant_share;
|
208 |
|
|
share_count_zero_flag <= (next_grant_share == '0);
|
209 |
|
|
end
|
210 |
|
|
else if (last_cycle) begin
|
211 |
|
|
share_count <= p1_share_count;
|
212 |
|
|
share_count_zero_flag <= (p1_share_count == '0);
|
213 |
|
|
end
|
214 |
|
|
end
|
215 |
|
|
end
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
always @* begin
|
219 |
|
|
update_grant = 0;
|
220 |
|
|
|
221 |
|
|
// ------------------------------------------
|
222 |
|
|
// The pipeline delays grant by one cycle, so
|
223 |
|
|
// we have to calculate the update_grant signal
|
224 |
|
|
// one cycle ahead of time.
|
225 |
|
|
//
|
226 |
|
|
// Possible optimization: omit the first clause
|
227 |
|
|
// "if (!packet_in_progress & ~src_valid) ..."
|
228 |
|
|
// cost: one idle cycle at the the beginning of each
|
229 |
|
|
// grant cycle.
|
230 |
|
|
// benefit: save a small amount of logic.
|
231 |
|
|
// ------------------------------------------
|
232 |
|
|
if (!packet_in_progress & !src_valid)
|
233 |
|
|
update_grant = 1;
|
234 |
|
|
if (last_cycle && share_count_zero_flag)
|
235 |
|
|
update_grant = 1;
|
236 |
|
|
end
|
237 |
|
|
|
238 |
|
|
wire save_grant;
|
239 |
|
|
assign save_grant = update_grant;
|
240 |
|
|
assign grant = saved_grant;
|
241 |
|
|
|
242 |
|
|
always @(posedge clk, posedge reset) begin
|
243 |
|
|
if (reset)
|
244 |
|
|
saved_grant <= '0;
|
245 |
|
|
else if (save_grant)
|
246 |
|
|
saved_grant <= next_grant;
|
247 |
|
|
end
|
248 |
|
|
|
249 |
|
|
// ------------------------------------------
|
250 |
|
|
// ------------------------------------------
|
251 |
|
|
// Arbitrator
|
252 |
|
|
// ------------------------------------------
|
253 |
|
|
// ------------------------------------------
|
254 |
|
|
|
255 |
|
|
// ------------------------------------------
|
256 |
|
|
// Create a request vector that stays high during
|
257 |
|
|
// the packet for unpipelined arbitration.
|
258 |
|
|
//
|
259 |
|
|
// The pipelined arbitration scheme does not require
|
260 |
|
|
// request to be held high during the packet.
|
261 |
|
|
// ------------------------------------------
|
262 |
|
|
reg [NUM_INPUTS - 1 : 0] prev_request;
|
263 |
|
|
always @(posedge clk, posedge reset) begin
|
264 |
|
|
if (reset)
|
265 |
|
|
prev_request <= '0;
|
266 |
|
|
else
|
267 |
|
|
prev_request <= request & ~(valid & eop);
|
268 |
|
|
end
|
269 |
|
|
|
270 |
|
|
assign request = (PIPELINE_ARB == 1) ? valid | locked :
|
271 |
|
|
prev_request | valid | locked;
|
272 |
|
|
|
273 |
|
|
wire [NUM_INPUTS - 1 : 0] next_grant_from_arb;
|
274 |
|
|
|
275 |
|
|
altera_merlin_arbitrator
|
276 |
|
|
#(
|
277 |
|
|
.NUM_REQUESTERS(NUM_INPUTS),
|
278 |
|
|
.SCHEME ("round-robin"),
|
279 |
|
|
.PIPELINE (1)
|
280 |
|
|
) arb (
|
281 |
|
|
.clk (clk),
|
282 |
|
|
.reset (reset),
|
283 |
|
|
.request (request),
|
284 |
|
|
.grant (next_grant_from_arb),
|
285 |
|
|
.save_top_priority (src_valid),
|
286 |
|
|
.increment_top_priority (update_grant)
|
287 |
|
|
);
|
288 |
|
|
|
289 |
|
|
assign next_grant = next_grant_from_arb;
|
290 |
|
|
|
291 |
|
|
// ------------------------------------------
|
292 |
|
|
// ------------------------------------------
|
293 |
|
|
// Mux
|
294 |
|
|
//
|
295 |
|
|
// Implemented as a sum of products.
|
296 |
|
|
// ------------------------------------------
|
297 |
|
|
// ------------------------------------------
|
298 |
|
|
|
299 |
|
|
assign sink0_ready = src_ready && grant[0];
|
300 |
|
|
assign sink1_ready = src_ready && grant[1];
|
301 |
|
|
|
302 |
|
|
assign src_valid = |(grant & valid);
|
303 |
|
|
|
304 |
|
|
always @* begin
|
305 |
|
|
src_payload =
|
306 |
|
|
sink0_payload & {PAYLOAD_W {grant[0]} } |
|
307 |
|
|
sink1_payload & {PAYLOAD_W {grant[1]} };
|
308 |
|
|
end
|
309 |
|
|
|
310 |
|
|
// ------------------------------------------
|
311 |
|
|
// Mux Payload Mapping
|
312 |
|
|
// ------------------------------------------
|
313 |
|
|
|
314 |
|
|
assign sink0_payload = {sink0_channel,sink0_data,
|
315 |
|
|
sink0_startofpacket,sink0_endofpacket};
|
316 |
|
|
assign sink1_payload = {sink1_channel,sink1_data,
|
317 |
|
|
sink1_startofpacket,sink1_endofpacket};
|
318 |
|
|
|
319 |
|
|
assign {src_channel,src_data,src_startofpacket,src_endofpacket} = src_payload;
|
320 |
|
|
endmodule
|
321 |
|
|
|
322 |
|
|
|