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 |
40 |
redbear |
// files from any of the foregoing (including device programming or simulation
|
5 |
32 |
redbear |
// files), and any associated documentation or information are expressly subject
|
6 |
|
|
// to the terms and conditions of the Intel Program License Subscription
|
7 |
40 |
redbear |
// Agreement, Intel FPGA IP License Agreement, or other applicable
|
8 |
32 |
redbear |
// 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 |
40 |
redbear |
// $Id: //acds/rel/17.1std/ip/merlin/altera_merlin_axi_master_ni/altera_merlin_axi_master_ni.sv#1 $
|
15 |
32 |
redbear |
// $Revision: #1 $
|
16 |
40 |
redbear |
// $Date: 2017/07/30 $
|
17 |
32 |
redbear |
// $Author: swbranch $
|
18 |
|
|
|
19 |
|
|
//-----------------------------------------
|
20 |
|
|
// AXI Master Agent
|
21 |
|
|
//
|
22 |
|
|
// Converts AXI master transactions into
|
23 |
|
|
// Merlin network packets.
|
24 |
|
|
//-----------------------------------------
|
25 |
|
|
`timescale 1 ns / 1 ns
|
26 |
|
|
|
27 |
|
|
module altera_merlin_axi_master_ni
|
28 |
|
|
#(
|
29 |
|
|
//----------------
|
30 |
|
|
// AXI Interface Parameters
|
31 |
|
|
//----------------
|
32 |
|
|
parameter ID_WIDTH = 2,
|
33 |
|
|
ADDR_WIDTH = 32,
|
34 |
|
|
RDATA_WIDTH = 32,
|
35 |
|
|
WDATA_WIDTH = 32,
|
36 |
|
|
ADDR_USER_WIDTH = 8,
|
37 |
|
|
DATA_USER_WIDTH = 8,
|
38 |
|
|
AXI_LOCK_WIDTH = 2,
|
39 |
|
|
AXI_BURST_LENGTH_WIDTH = 4,
|
40 |
|
|
WRITE_ISSUING_CAPABILITY = 16,
|
41 |
|
|
READ_ISSUING_CAPABILITY = 16,
|
42 |
|
|
AXI_VERSION = "AXI3",
|
43 |
|
|
|
44 |
|
|
//-------------------------
|
45 |
|
|
// Packet Format Parameters
|
46 |
|
|
//-------------------------
|
47 |
|
|
PKT_THREAD_ID_H = 109,
|
48 |
|
|
PKT_THREAD_ID_L = 108,
|
49 |
|
|
PKT_QOS_H = 113,
|
50 |
|
|
PKT_QOS_L = 110,
|
51 |
|
|
PKT_BEGIN_BURST = 104,
|
52 |
|
|
PKT_CACHE_H = 103,
|
53 |
|
|
PKT_CACHE_L = 100,
|
54 |
|
|
PKT_ADDR_SIDEBAND_H = 99,
|
55 |
|
|
PKT_ADDR_SIDEBAND_L = 92,
|
56 |
|
|
PKT_DATA_SIDEBAND_H = 124,
|
57 |
|
|
|
58 |
|
|
PKT_DATA_SIDEBAND_L = 118,
|
59 |
|
|
PKT_PROTECTION_H = 89,
|
60 |
|
|
PKT_PROTECTION_L = 87,
|
61 |
|
|
PKT_BURST_SIZE_H = 84,
|
62 |
|
|
PKT_BURST_SIZE_L = 82,
|
63 |
|
|
PKT_BURST_TYPE_H = 86,
|
64 |
|
|
PKT_BURST_TYPE_L = 85,
|
65 |
|
|
PKT_RESPONSE_STATUS_L = 106,
|
66 |
|
|
PKT_RESPONSE_STATUS_H = 107,
|
67 |
|
|
PKT_BURSTWRAP_H = 79,
|
68 |
|
|
PKT_BURSTWRAP_L = 77,
|
69 |
|
|
PKT_BYTE_CNT_H = 76,
|
70 |
|
|
PKT_BYTE_CNT_L = 74,
|
71 |
|
|
PKT_ADDR_H = 73,
|
72 |
|
|
PKT_ADDR_L = 42,
|
73 |
|
|
PKT_TRANS_EXCLUSIVE = 80,
|
74 |
|
|
PKT_TRANS_LOCK = 105,
|
75 |
|
|
PKT_TRANS_COMPRESSED_READ = 41,
|
76 |
|
|
PKT_TRANS_POSTED = 40,
|
77 |
|
|
PKT_TRANS_WRITE = 39,
|
78 |
|
|
PKT_TRANS_READ = 38,
|
79 |
|
|
PKT_DATA_H = 37,
|
80 |
|
|
PKT_DATA_L = 6,
|
81 |
|
|
PKT_BYTEEN_H = 5,
|
82 |
|
|
PKT_BYTEEN_L = 2,
|
83 |
|
|
PKT_SRC_ID_H = 1,
|
84 |
|
|
PKT_SRC_ID_L = 1,
|
85 |
|
|
PKT_DEST_ID_H = 0,
|
86 |
|
|
PKT_DEST_ID_L = 0,
|
87 |
|
|
PKT_ORI_BURST_SIZE_H = 127,
|
88 |
|
|
PKT_ORI_BURST_SIZE_L = 125,
|
89 |
|
|
ST_DATA_W = 128,
|
90 |
|
|
ST_CHANNEL_W = 1,
|
91 |
|
|
|
92 |
|
|
//----------------
|
93 |
|
|
// Agent Parameters
|
94 |
|
|
//----------------
|
95 |
|
|
ID = 1,
|
96 |
|
|
//----------------
|
97 |
|
|
// Derived Parameters
|
98 |
|
|
//----------------
|
99 |
|
|
PKT_BURSTWRAP_W = PKT_BURSTWRAP_H - PKT_BURSTWRAP_L + 1,
|
100 |
|
|
PKT_BYTE_CNT_W = PKT_BYTE_CNT_H - PKT_BYTE_CNT_L + 1,
|
101 |
|
|
PKT_ADDR_W = PKT_ADDR_H - PKT_ADDR_L + 1,
|
102 |
|
|
PKT_DATA_W = PKT_DATA_H - PKT_DATA_L + 1,
|
103 |
|
|
PKT_BYTEEN_W = PKT_BYTEEN_H - PKT_BYTEEN_L + 1,
|
104 |
|
|
PKT_SRC_ID_W = PKT_SRC_ID_H - PKT_SRC_ID_L + 1,
|
105 |
|
|
PKT_DEST_ID_W = PKT_DEST_ID_H - PKT_DEST_ID_L + 1
|
106 |
|
|
)
|
107 |
|
|
(
|
108 |
|
|
//----------------
|
109 |
|
|
// Global Signals
|
110 |
|
|
//----------------
|
111 |
|
|
input aclk,
|
112 |
|
|
input aresetn,
|
113 |
|
|
//----------------------------
|
114 |
|
|
// AXI SLAVE SIDE INTERFACES
|
115 |
|
|
//----------------------------
|
116 |
|
|
// Write Address Channel
|
117 |
|
|
//----------------
|
118 |
|
|
input [ID_WIDTH-1:0] awid,
|
119 |
|
|
input [ADDR_WIDTH-1:0] awaddr,
|
120 |
|
|
input [AXI_BURST_LENGTH_WIDTH - 1:0] awlen,
|
121 |
|
|
input [2:0] awsize,
|
122 |
|
|
input [1:0] awburst,
|
123 |
|
|
input [AXI_LOCK_WIDTH-1:0] awlock,
|
124 |
|
|
input [3:0] awcache,
|
125 |
|
|
input [2:0] awprot,
|
126 |
|
|
input [3:0] awqos,
|
127 |
|
|
input [3:0] awregion,
|
128 |
|
|
input [ADDR_USER_WIDTH-1:0] awuser,
|
129 |
|
|
input awvalid,
|
130 |
|
|
output reg awready,
|
131 |
|
|
//----------------
|
132 |
|
|
// Write Data Channel
|
133 |
|
|
//----------------
|
134 |
|
|
input [ID_WIDTH-1:0] wid,
|
135 |
|
|
input [PKT_DATA_W-1:0] wdata,
|
136 |
|
|
input [(PKT_DATA_W/8)-1:0] wstrb,
|
137 |
|
|
input wlast,
|
138 |
|
|
input wvalid,
|
139 |
|
|
input [DATA_USER_WIDTH-1:0] wuser,
|
140 |
|
|
output reg wready,
|
141 |
|
|
//----------------
|
142 |
|
|
// Write Response Channel
|
143 |
|
|
//----------------
|
144 |
|
|
output reg [ID_WIDTH-1:0] bid,
|
145 |
|
|
output reg [1:0] bresp,
|
146 |
|
|
output bvalid,
|
147 |
|
|
input bready,
|
148 |
|
|
output reg [DATA_USER_WIDTH-1:0] buser,
|
149 |
|
|
//----------------
|
150 |
|
|
// Read Address Channel
|
151 |
|
|
//----------------
|
152 |
|
|
input [ID_WIDTH-1:0] arid,
|
153 |
|
|
input [ADDR_WIDTH-1:0] araddr,
|
154 |
|
|
input [AXI_BURST_LENGTH_WIDTH - 1:0] arlen,
|
155 |
|
|
input [2:0] arsize,
|
156 |
|
|
input [1:0] arburst,
|
157 |
|
|
input [AXI_LOCK_WIDTH-1:0] arlock,
|
158 |
|
|
input [3:0] arcache,
|
159 |
|
|
input [2:0] arprot,
|
160 |
|
|
input [3:0] arqos,
|
161 |
|
|
input [3:0] arregion,
|
162 |
|
|
input [ADDR_USER_WIDTH-1:0] aruser,
|
163 |
|
|
input arvalid,
|
164 |
|
|
output arready,
|
165 |
|
|
//----------------
|
166 |
|
|
// Read Data Channel
|
167 |
|
|
//----------------
|
168 |
|
|
output reg [ID_WIDTH-1:0] rid,
|
169 |
|
|
output reg [PKT_DATA_W-1:0] rdata,
|
170 |
|
|
output reg [1:0] rresp,
|
171 |
|
|
output rlast,
|
172 |
|
|
output rvalid,
|
173 |
|
|
input rready,
|
174 |
|
|
output reg [DATA_USER_WIDTH-1:0] ruser,
|
175 |
|
|
//----------------------------
|
176 |
|
|
// NETWORK SIDE INTERFACES
|
177 |
|
|
//----------------------------
|
178 |
|
|
// WRITE Channel
|
179 |
|
|
//------------------
|
180 |
|
|
// Command Source
|
181 |
|
|
//----------------
|
182 |
|
|
output reg write_cp_valid,
|
183 |
|
|
output reg [ST_DATA_W-1:0] write_cp_data,
|
184 |
|
|
output wire write_cp_startofpacket,
|
185 |
|
|
output wire write_cp_endofpacket,
|
186 |
|
|
input write_cp_ready,
|
187 |
|
|
//----------------
|
188 |
|
|
// Response Sink
|
189 |
|
|
//----------------
|
190 |
|
|
input write_rp_valid,
|
191 |
|
|
input [ST_DATA_W-1 : 0] write_rp_data,
|
192 |
|
|
input [ST_CHANNEL_W-1 : 0] write_rp_channel,
|
193 |
|
|
input write_rp_startofpacket,
|
194 |
|
|
input write_rp_endofpacket,
|
195 |
|
|
output reg write_rp_ready,
|
196 |
|
|
//-------------------
|
197 |
|
|
// READ Channel
|
198 |
|
|
//-------------------
|
199 |
|
|
// Command Source
|
200 |
|
|
//----------------
|
201 |
|
|
output reg read_cp_valid,
|
202 |
|
|
output reg [ST_DATA_W-1:0] read_cp_data,
|
203 |
|
|
output wire read_cp_startofpacket,
|
204 |
|
|
output wire read_cp_endofpacket,
|
205 |
|
|
input read_cp_ready,
|
206 |
|
|
//----------------
|
207 |
|
|
// Response Sink
|
208 |
|
|
//----------------
|
209 |
|
|
input read_rp_valid,
|
210 |
|
|
input [ST_DATA_W-1 : 0] read_rp_data,
|
211 |
|
|
input [ST_CHANNEL_W-1 : 0] read_rp_channel,
|
212 |
|
|
input read_rp_startofpacket,
|
213 |
|
|
input read_rp_endofpacket,
|
214 |
|
|
output reg read_rp_ready
|
215 |
|
|
|
216 |
|
|
);
|
217 |
|
|
|
218 |
|
|
//--------------------------------------
|
219 |
|
|
// Local parameters
|
220 |
|
|
//--------------------------------------
|
221 |
|
|
localparam NUMSYMBOLS = PKT_DATA_W/8;
|
222 |
|
|
localparam BITS_PER_SYMBOL = 8;
|
223 |
|
|
|
224 |
|
|
typedef enum bit [1:0]
|
225 |
|
|
{
|
226 |
|
|
FIXED = 2'b00,
|
227 |
|
|
INCR = 2'b01,
|
228 |
|
|
WRAP = 2'b10,
|
229 |
|
|
RESERVED = 2'b11
|
230 |
|
|
} AxiBurstType;
|
231 |
|
|
|
232 |
|
|
//----------------------------------------------------
|
233 |
|
|
// AXSIZE decoding
|
234 |
|
|
//
|
235 |
|
|
// Turns the axsize value into the actual number of bytes
|
236 |
|
|
// being transferred.
|
237 |
|
|
// ---------------------------------------------------
|
238 |
|
|
function reg[7:0] bytes_in_transfer;
|
239 |
|
|
input [2:0] axsize;
|
240 |
|
|
|
241 |
|
|
case (axsize)
|
242 |
|
|
3'b000: bytes_in_transfer = 8'b00000001;
|
243 |
|
|
3'b001: bytes_in_transfer = 8'b00000010;
|
244 |
|
|
3'b010: bytes_in_transfer = 8'b00000100;
|
245 |
|
|
3'b011: bytes_in_transfer = 8'b00001000;
|
246 |
|
|
3'b100: bytes_in_transfer = 8'b00010000;
|
247 |
|
|
3'b101: bytes_in_transfer = 8'b00100000;
|
248 |
|
|
3'b110: bytes_in_transfer = 8'b01000000;
|
249 |
|
|
3'b111: bytes_in_transfer = 8'b10000000;
|
250 |
|
|
default:bytes_in_transfer = 8'b00000001;
|
251 |
|
|
endcase
|
252 |
|
|
|
253 |
|
|
endfunction
|
254 |
|
|
|
255 |
|
|
// --------------------------------------------------
|
256 |
|
|
// Ceil(log2()) function log2ceil of 4 = 2
|
257 |
|
|
// --------------------------------------------------
|
258 |
|
|
function integer log2ceil;
|
259 |
|
|
input reg[63:0] val;
|
260 |
|
|
reg [63:0] i;
|
261 |
|
|
|
262 |
|
|
begin
|
263 |
|
|
i = 1;
|
264 |
|
|
log2ceil = 0;
|
265 |
|
|
|
266 |
|
|
while (i < val) begin
|
267 |
|
|
log2ceil = log2ceil + 1;
|
268 |
|
|
i = i << 1;
|
269 |
|
|
end
|
270 |
|
|
end
|
271 |
|
|
endfunction
|
272 |
|
|
|
273 |
|
|
//--------------------------------------
|
274 |
|
|
// Burst type decode
|
275 |
|
|
//--------------------------------------
|
276 |
|
|
AxiBurstType write_burst_type, read_burst_type;
|
277 |
|
|
|
278 |
|
|
function AxiBurstType burst_type_decode
|
279 |
|
|
(
|
280 |
|
|
input [1:0] axburst
|
281 |
|
|
);
|
282 |
|
|
AxiBurstType burst_type;
|
283 |
|
|
begin
|
284 |
|
|
case (axburst)
|
285 |
|
|
2'b00 : burst_type = FIXED;
|
286 |
|
|
2'b01 : burst_type = INCR;
|
287 |
|
|
2'b10 : burst_type = WRAP;
|
288 |
|
|
2'b11 : burst_type = RESERVED;
|
289 |
|
|
default : burst_type = INCR;
|
290 |
|
|
endcase
|
291 |
|
|
return burst_type;
|
292 |
|
|
end
|
293 |
|
|
endfunction
|
294 |
|
|
|
295 |
|
|
always_comb
|
296 |
|
|
begin
|
297 |
|
|
write_burst_type = burst_type_decode(awburst);
|
298 |
|
|
read_burst_type = burst_type_decode(arburst);
|
299 |
|
|
end
|
300 |
|
|
|
301 |
|
|
//--------------------------------------
|
302 |
|
|
// Calculate the value of burstwrap for a wrapping burst.
|
303 |
|
|
// The algorithm figures out the width of the burstwrap
|
304 |
|
|
// boundary, and uses that to set a bit mask for burstwrap.
|
305 |
|
|
//
|
306 |
|
|
// This should synthesize to a small adder, followed by a
|
307 |
|
|
// per-bit comparator (which gets folded into the adder).
|
308 |
|
|
//--------------------------------------
|
309 |
|
|
reg [31 : 0] burstwrap_value_write;
|
310 |
|
|
reg [31 : 0] burstwrap_value_read;
|
311 |
|
|
reg [PKT_BURSTWRAP_W - 2 : 0] burstwrap_boundary_write;
|
312 |
|
|
reg [PKT_BURSTWRAP_W - 2 : 0] burstwrap_boundary_read;
|
313 |
|
|
wire [31 : 0] burstwrap_boundary_width_write;
|
314 |
|
|
wire [31 : 0] burstwrap_boundary_width_read;
|
315 |
|
|
|
316 |
|
|
reg [PKT_ADDR_W-1 : 0] incremented_burst_address;
|
317 |
|
|
reg [PKT_ADDR_W-1 : 0] burstwrap_mask;
|
318 |
|
|
reg [PKT_ADDR_W-1 : 0] burst_address_high;
|
319 |
|
|
reg [PKT_ADDR_W-1 : 0] burst_address_low;
|
320 |
|
|
|
321 |
|
|
assign burstwrap_boundary_width_write = awsize + log2ceil(awlen + 1);
|
322 |
|
|
assign burstwrap_boundary_width_read = arsize + log2ceil(arlen + 1);
|
323 |
|
|
|
324 |
|
|
function reg [PKT_BURSTWRAP_W - 2 : 0] burstwrap_boundary_calculation
|
325 |
|
|
(
|
326 |
|
|
input [31 : 0] burstwrap_boundary_width,
|
327 |
|
|
input int width = PKT_BURSTWRAP_W - 1
|
328 |
|
|
);
|
329 |
|
|
integer i;
|
330 |
|
|
|
331 |
|
|
burstwrap_boundary_calculation = 0;
|
332 |
|
|
for (i = 0; i < width; i++) begin
|
333 |
|
|
if (burstwrap_boundary_width > i)
|
334 |
|
|
burstwrap_boundary_calculation[i] = 1;
|
335 |
|
|
end
|
336 |
|
|
|
337 |
|
|
endfunction
|
338 |
|
|
|
339 |
|
|
assign burstwrap_boundary_write = burstwrap_boundary_calculation(burstwrap_boundary_width_write, PKT_BURSTWRAP_W - 1);
|
340 |
|
|
assign burstwrap_boundary_read = burstwrap_boundary_calculation(burstwrap_boundary_width_read, PKT_BURSTWRAP_W - 1);
|
341 |
|
|
|
342 |
|
|
//--------------------------------------
|
343 |
|
|
// Use the burst type to set correct burstwrap value and address increment
|
344 |
|
|
//--------------------------------------
|
345 |
|
|
|
346 |
|
|
wire [31:0] bytes_in_transfer_minusone_write_wire; // eliminates synthesis warning
|
347 |
|
|
wire [31:0] bytes_in_transfer_minusone_read_wire; // eliminates synthesis warning
|
348 |
|
|
|
349 |
|
|
assign bytes_in_transfer_minusone_write_wire = bytes_in_transfer(awsize) - 1;
|
350 |
|
|
assign bytes_in_transfer_minusone_read_wire = bytes_in_transfer(arsize) - 1;
|
351 |
|
|
|
352 |
|
|
always_comb
|
353 |
|
|
begin
|
354 |
|
|
burstwrap_value_write = 0;
|
355 |
|
|
case (write_burst_type)
|
356 |
|
|
INCR:
|
357 |
|
|
begin
|
358 |
|
|
burstwrap_value_write[PKT_BURSTWRAP_W - 1 : 0] = {PKT_BURSTWRAP_W {1'b1}};
|
359 |
|
|
end
|
360 |
|
|
WRAP:
|
361 |
|
|
begin
|
362 |
|
|
burstwrap_value_write[PKT_BURSTWRAP_W - 1 : 0] = {1'b0, burstwrap_boundary_write};
|
363 |
|
|
end
|
364 |
|
|
FIXED:
|
365 |
|
|
begin
|
366 |
|
|
burstwrap_value_write[PKT_BURSTWRAP_W - 1 : 0] = bytes_in_transfer_minusone_write_wire[PKT_BURSTWRAP_W -1 : 0];
|
367 |
|
|
end
|
368 |
|
|
default:
|
369 |
|
|
begin
|
370 |
|
|
burstwrap_value_write[PKT_BURSTWRAP_W - 1 : 0] = {PKT_BURSTWRAP_W {1'b1}};
|
371 |
|
|
end
|
372 |
|
|
endcase
|
373 |
|
|
end
|
374 |
|
|
|
375 |
|
|
always_comb
|
376 |
|
|
begin
|
377 |
|
|
burstwrap_value_read = 0;
|
378 |
|
|
case (read_burst_type)
|
379 |
|
|
INCR:
|
380 |
|
|
begin
|
381 |
|
|
burstwrap_value_read[PKT_BURSTWRAP_W - 1 : 0] = {PKT_BURSTWRAP_W {1'b1}};
|
382 |
|
|
end
|
383 |
|
|
WRAP:
|
384 |
|
|
begin
|
385 |
|
|
burstwrap_value_read[PKT_BURSTWRAP_W - 1 : 0] = {1'b0, burstwrap_boundary_read};
|
386 |
|
|
end
|
387 |
|
|
FIXED:
|
388 |
|
|
begin
|
389 |
|
|
burstwrap_value_read[PKT_BURSTWRAP_W - 1 : 0] = bytes_in_transfer_minusone_read_wire[PKT_BURSTWRAP_W -1 : 0];
|
390 |
|
|
end
|
391 |
|
|
default:
|
392 |
|
|
begin
|
393 |
|
|
burstwrap_value_read[PKT_BURSTWRAP_W - 1 : 0] = {PKT_BURSTWRAP_W {1'b1}};
|
394 |
|
|
end
|
395 |
|
|
endcase
|
396 |
|
|
end
|
397 |
|
|
|
398 |
|
|
//--------------------------------------
|
399 |
|
|
// Global signals
|
400 |
|
|
//--------------------------------------
|
401 |
|
|
wire [31:0] id_int = ID;
|
402 |
|
|
|
403 |
|
|
//--------------------------------------
|
404 |
|
|
// Command control for write packet
|
405 |
|
|
//--------------------------------------
|
406 |
|
|
// Handling address and data
|
407 |
|
|
//
|
408 |
|
|
// The master NI will only send a packet
|
409 |
|
|
// when it receives both address and data.
|
410 |
|
|
|
411 |
|
|
wire write_addr_data_both_valid;
|
412 |
|
|
wire network_ready;
|
413 |
|
|
|
414 |
|
|
assign write_addr_data_both_valid = awvalid && wvalid;
|
415 |
|
|
assign network_ready = write_cp_ready;
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
//-------------------------
|
419 |
|
|
// Burst address and bytecount assignment
|
420 |
|
|
// ------------------------
|
421 |
|
|
reg [PKT_ADDR_W-1 : 0] start_address;
|
422 |
|
|
reg [PKT_BYTE_CNT_W-1 : 0] total_write_bytecount;
|
423 |
|
|
reg [PKT_BYTE_CNT_W-1 : 0] total_read_bytecount;
|
424 |
|
|
reg [PKT_BYTE_CNT_W-1 : 0] write_burst_bytecount;
|
425 |
|
|
|
426 |
|
|
reg [PKT_ADDR_W-1 : 0] burst_address;
|
427 |
|
|
reg [PKT_BYTE_CNT_W-1 : 0] burst_bytecount;
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
// Keep temporary address
|
431 |
|
|
wire [PKT_ADDR_W-1 : 0] second_burst_address;
|
432 |
|
|
wire [PKT_ADDR_W-1 : 0] burst_address_incr;
|
433 |
|
|
reg [PKT_BYTE_CNT_W-1 : 0] total_bytecount_left;
|
434 |
|
|
|
435 |
|
|
reg [31:0] total_write_bytecount_wire; // to eliminate QIS warning
|
436 |
|
|
reg [31:0] total_read_bytecount_wire; // to eliminate QIS warning
|
437 |
|
|
reg [31:0] total_bytecount_left_wire; // to eliminate QIS warning
|
438 |
|
|
|
439 |
|
|
// First address and bytecount of a burst
|
440 |
|
|
always_comb
|
441 |
|
|
begin
|
442 |
|
|
total_write_bytecount_wire = (awlen + 1) << log2ceil(NUMSYMBOLS);
|
443 |
|
|
total_read_bytecount_wire = (arlen + 1) << log2ceil(NUMSYMBOLS);
|
444 |
|
|
total_write_bytecount = total_write_bytecount_wire[PKT_BYTE_CNT_W-1:0];
|
445 |
|
|
total_read_bytecount = total_read_bytecount_wire[PKT_BYTE_CNT_W-1:0];
|
446 |
|
|
start_address = awaddr;
|
447 |
|
|
end
|
448 |
|
|
//-----------------------------------------------------------------------
|
449 |
|
|
// The address_alignment is used to align address to size and increment burst address if needed
|
450 |
|
|
// it has input: {burswrap_boundary, start_addr, bursttype, burst_zize}
|
451 |
|
|
// return output is aligned address and increment if set, with Wrap the output address will wrap
|
452 |
|
|
// according to wrap boundary. Fixed burst, address will be kept same
|
453 |
|
|
// In case INCREMENT_ADDRESS = 0, the component acts as combinational logic and return algined address
|
454 |
|
|
// and a mask to algin address if wish to use.
|
455 |
|
|
//
|
456 |
|
|
// Refer for comments inside the component for more details
|
457 |
|
|
//-----------------------------------------------------------------------
|
458 |
|
|
|
459 |
|
|
reg [PKT_ADDR_W-1 : 0] address_aligned;
|
460 |
|
|
|
461 |
|
|
generate
|
462 |
|
|
if (AXI_VERSION != "AXI4Lite") begin
|
463 |
|
|
reg [PKT_ADDR_W + (PKT_BURSTWRAP_W-1) + 4 : 0] address_for_alignment;
|
464 |
|
|
reg [PKT_ADDR_W+log2ceil(NUMSYMBOLS)-1 :0] address_after_alignment;
|
465 |
|
|
assign address_aligned = address_after_alignment[PKT_ADDR_W - 1 : 0];
|
466 |
|
|
assign address_for_alignment = {burstwrap_boundary_write,awburst, start_address, awsize};
|
467 |
|
|
|
468 |
|
|
altera_merlin_address_alignment
|
469 |
|
|
#(
|
470 |
|
|
.ADDR_W (PKT_ADDR_W),
|
471 |
|
|
.BURSTWRAP_W (PKT_BURSTWRAP_W),
|
472 |
|
|
.INCREMENT_ADDRESS (1),
|
473 |
|
|
.NUMSYMBOLS (NUMSYMBOLS)
|
474 |
|
|
) align_address_to_size
|
475 |
|
|
(
|
476 |
|
|
.clk (aclk),
|
477 |
|
|
.reset (aresetn),
|
478 |
|
|
.in_data (address_for_alignment),
|
479 |
|
|
.in_valid (write_addr_data_both_valid),
|
480 |
|
|
.in_sop (write_cp_startofpacket),
|
481 |
|
|
.in_eop (wlast),
|
482 |
|
|
|
483 |
|
|
.out_data (address_after_alignment),
|
484 |
|
|
.out_ready (write_cp_ready)
|
485 |
|
|
);
|
486 |
|
|
end else begin
|
487 |
|
|
assign address_aligned = start_address;
|
488 |
|
|
end
|
489 |
|
|
endgenerate
|
490 |
|
|
|
491 |
|
|
|
492 |
|
|
// -----------------------------------------------------------------------------
|
493 |
|
|
|
494 |
|
|
// increase address and decrease bytecount
|
495 |
|
|
assign total_bytecount_left_wire = write_burst_bytecount - NUMSYMBOLS;
|
496 |
|
|
assign total_bytecount_left = total_bytecount_left_wire[PKT_BYTE_CNT_W-1:0];
|
497 |
|
|
|
498 |
|
|
always_comb
|
499 |
|
|
begin
|
500 |
|
|
if (write_cp_startofpacket)
|
501 |
|
|
begin
|
502 |
|
|
write_burst_bytecount = total_write_bytecount;
|
503 |
|
|
end
|
504 |
|
|
else
|
505 |
|
|
begin
|
506 |
|
|
write_burst_bytecount = burst_bytecount;
|
507 |
|
|
end
|
508 |
|
|
end
|
509 |
|
|
|
510 |
|
|
always_ff @(posedge aclk, negedge aresetn)
|
511 |
|
|
begin
|
512 |
|
|
if (!aresetn)
|
513 |
|
|
begin
|
514 |
|
|
burst_bytecount <= {PKT_BYTE_CNT_W{1'b0}};
|
515 |
|
|
end
|
516 |
|
|
else
|
517 |
|
|
begin
|
518 |
|
|
if (write_addr_data_both_valid && write_cp_ready)
|
519 |
|
|
begin
|
520 |
|
|
burst_bytecount <= total_bytecount_left;
|
521 |
|
|
end
|
522 |
|
|
end
|
523 |
|
|
|
524 |
|
|
end
|
525 |
|
|
|
526 |
|
|
//------------------------------------------------------
|
527 |
|
|
// Generate startofpacket ~ beginbursttransfer
|
528 |
|
|
// -----------------------------------------------------
|
529 |
|
|
reg sop_enable;
|
530 |
|
|
always_ff @(posedge aclk, negedge aresetn)
|
531 |
|
|
begin
|
532 |
|
|
if (!aresetn)
|
533 |
|
|
begin
|
534 |
|
|
sop_enable <= 1'b1;
|
535 |
|
|
end
|
536 |
|
|
else
|
537 |
|
|
begin
|
538 |
|
|
// sop for write channel
|
539 |
|
|
if (write_addr_data_both_valid && write_cp_ready)
|
540 |
|
|
begin
|
541 |
|
|
sop_enable <= 1'b0;
|
542 |
|
|
if (wlast)
|
543 |
|
|
sop_enable <= 1'b1;
|
544 |
|
|
end
|
545 |
|
|
end
|
546 |
|
|
end
|
547 |
|
|
|
548 |
|
|
assign write_cp_startofpacket = sop_enable;
|
549 |
|
|
assign write_cp_endofpacket = wlast;
|
550 |
|
|
assign read_cp_startofpacket = 1'b1;
|
551 |
|
|
assign read_cp_endofpacket = 1'b1;
|
552 |
|
|
|
553 |
|
|
|
554 |
|
|
//--------------------------------------------------------
|
555 |
|
|
// AW/WREADY control
|
556 |
|
|
//
|
557 |
|
|
// Backpresure AWREADY until the data phase is complete
|
558 |
|
|
//--------------------------------------------------------
|
559 |
|
|
always_comb
|
560 |
|
|
begin
|
561 |
|
|
awready = 0;
|
562 |
|
|
wready = 0;
|
563 |
|
|
if (write_addr_data_both_valid)
|
564 |
|
|
begin
|
565 |
|
|
wready = network_ready;
|
566 |
|
|
if (wlast)
|
567 |
|
|
// allow AWREADY on the last burst cycle
|
568 |
|
|
awready = network_ready;
|
569 |
|
|
end
|
570 |
|
|
end
|
571 |
|
|
|
572 |
|
|
assign write_cp_valid = write_addr_data_both_valid;
|
573 |
|
|
|
574 |
|
|
//--------------------------------------
|
575 |
|
|
// Command control for write response packet
|
576 |
|
|
//--------------------------------------
|
577 |
|
|
assign bvalid = write_rp_valid;
|
578 |
|
|
assign write_rp_ready = bready;
|
579 |
|
|
|
580 |
|
|
|
581 |
|
|
//--------------------------------------
|
582 |
|
|
// Form write transaction packet
|
583 |
|
|
//--------------------------------------
|
584 |
|
|
always_comb
|
585 |
|
|
begin
|
586 |
|
|
write_cp_data = '0;
|
587 |
|
|
write_cp_data[PKT_BYTE_CNT_H :PKT_BYTE_CNT_L ] = write_burst_bytecount;
|
588 |
|
|
write_cp_data[PKT_TRANS_EXCLUSIVE ] = awlock[0];
|
589 |
|
|
write_cp_data[PKT_TRANS_LOCK ] = '0;
|
590 |
|
|
write_cp_data[PKT_TRANS_COMPRESSED_READ ] = '0;
|
591 |
|
|
write_cp_data[PKT_TRANS_READ ] = '0;
|
592 |
|
|
write_cp_data[PKT_TRANS_WRITE ] = 1'b1;
|
593 |
|
|
write_cp_data[PKT_TRANS_POSTED ] = '0;
|
594 |
|
|
write_cp_data[PKT_BURSTWRAP_H:PKT_BURSTWRAP_L] = burstwrap_value_write[PKT_BURSTWRAP_W - 1 : 0];
|
595 |
|
|
write_cp_data[PKT_ADDR_H :PKT_ADDR_L ] = address_aligned;
|
596 |
|
|
write_cp_data[PKT_DATA_H :PKT_DATA_L ] = wdata;
|
597 |
|
|
write_cp_data[PKT_BYTEEN_H :PKT_BYTEEN_L ] = wstrb;
|
598 |
|
|
write_cp_data[PKT_BURST_SIZE_H :PKT_BURST_SIZE_L] = awsize;
|
599 |
|
|
write_cp_data[PKT_BURST_TYPE_H :PKT_BURST_TYPE_L] = awburst;
|
600 |
|
|
write_cp_data[PKT_SRC_ID_H :PKT_SRC_ID_L ] = id_int[PKT_SRC_ID_W-1:0];
|
601 |
|
|
write_cp_data[PKT_PROTECTION_H :PKT_PROTECTION_L] = awprot;
|
602 |
|
|
write_cp_data[PKT_THREAD_ID_H :PKT_THREAD_ID_L] = awid;
|
603 |
|
|
write_cp_data[PKT_CACHE_H :PKT_CACHE_L] = awcache;
|
604 |
|
|
write_cp_data[PKT_ADDR_SIDEBAND_H:PKT_ADDR_SIDEBAND_L] = awuser;
|
605 |
|
|
write_cp_data[PKT_ORI_BURST_SIZE_H :PKT_ORI_BURST_SIZE_L] = awsize;
|
606 |
|
|
|
607 |
|
|
// AXI4 signals: receive from the translator
|
608 |
|
|
if (AXI_VERSION == "AXI4") begin
|
609 |
|
|
write_cp_data[PKT_QOS_H : PKT_QOS_L] = awqos;
|
610 |
|
|
write_cp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L] = wuser;
|
611 |
|
|
end else begin //AXI3: set with default value
|
612 |
|
|
write_cp_data[PKT_QOS_H : PKT_QOS_L] = '0;
|
613 |
|
|
write_cp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L] = '0;
|
614 |
|
|
end
|
615 |
|
|
|
616 |
|
|
// Receive Response packet from the Slave
|
617 |
|
|
bresp = write_rp_data[PKT_RESPONSE_STATUS_H : PKT_RESPONSE_STATUS_L];
|
618 |
|
|
bid = write_rp_data[PKT_THREAD_ID_H : PKT_THREAD_ID_L];
|
619 |
|
|
// AXI4 signals
|
620 |
|
|
buser = write_rp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L];
|
621 |
|
|
end
|
622 |
|
|
|
623 |
|
|
|
624 |
|
|
//--------------------------------------
|
625 |
|
|
// Form read transaction packet
|
626 |
|
|
//--------------------------------------
|
627 |
|
|
always_comb
|
628 |
|
|
begin
|
629 |
|
|
read_cp_data = '0;
|
630 |
|
|
read_cp_data[PKT_BYTE_CNT_H :PKT_BYTE_CNT_L ] = total_read_bytecount;
|
631 |
|
|
read_cp_data[PKT_TRANS_EXCLUSIVE ] = arlock[0];
|
632 |
|
|
read_cp_data[PKT_TRANS_LOCK ] = '0;
|
633 |
|
|
if (AXI_VERSION != "AXI4Lite") begin
|
634 |
|
|
read_cp_data[PKT_TRANS_COMPRESSED_READ] = 1'b1;
|
635 |
|
|
end else begin
|
636 |
|
|
read_cp_data[PKT_TRANS_COMPRESSED_READ] = '0;
|
637 |
|
|
end
|
638 |
|
|
read_cp_data[PKT_TRANS_READ ] = '1;
|
639 |
|
|
read_cp_data[PKT_TRANS_WRITE ] = '0;
|
640 |
|
|
read_cp_data[PKT_TRANS_POSTED ] = '0;
|
641 |
|
|
read_cp_data[PKT_BURSTWRAP_H:PKT_BURSTWRAP_L] = burstwrap_value_read[PKT_BURSTWRAP_W - 1 : 0];
|
642 |
|
|
read_cp_data[PKT_ADDR_H :PKT_ADDR_L ] = araddr;
|
643 |
|
|
read_cp_data[PKT_DATA_H :PKT_DATA_L ] = '0;
|
644 |
|
|
read_cp_data[PKT_BYTEEN_H :PKT_BYTEEN_L ] = {PKT_BYTEEN_W{1'b1}};
|
645 |
|
|
read_cp_data[PKT_SRC_ID_H :PKT_SRC_ID_L ] = id_int[PKT_SRC_ID_W-1:0];
|
646 |
|
|
read_cp_data[PKT_BURST_SIZE_H :PKT_BURST_SIZE_L] = arsize;
|
647 |
|
|
read_cp_data[PKT_ORI_BURST_SIZE_H :PKT_ORI_BURST_SIZE_L] = arsize;
|
648 |
|
|
read_cp_data[PKT_BURST_TYPE_H :PKT_BURST_TYPE_L] = arburst;
|
649 |
|
|
read_cp_data[PKT_PROTECTION_H : PKT_PROTECTION_L] = arprot;
|
650 |
|
|
read_cp_data[PKT_THREAD_ID_H : PKT_THREAD_ID_L] = arid;
|
651 |
|
|
read_cp_data[PKT_CACHE_H : PKT_CACHE_L] = arcache;
|
652 |
|
|
|
653 |
|
|
read_cp_data[PKT_ADDR_SIDEBAND_H:PKT_ADDR_SIDEBAND_L] = aruser;
|
654 |
|
|
// AXI4 signals: receive from translator
|
655 |
|
|
if (AXI_VERSION == "AXI4") begin
|
656 |
|
|
read_cp_data[PKT_QOS_H : PKT_QOS_L] = arqos;
|
657 |
|
|
read_cp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L] = aruser;
|
658 |
|
|
end else begin
|
659 |
|
|
read_cp_data[PKT_QOS_H : PKT_QOS_L] = '0;
|
660 |
|
|
read_cp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L] = '0;
|
661 |
|
|
end
|
662 |
|
|
|
663 |
|
|
// Read data packet from the Slave, connect to rdata
|
664 |
|
|
rdata = read_rp_data[PKT_DATA_H :PKT_DATA_L];
|
665 |
|
|
rresp = read_rp_data[PKT_RESPONSE_STATUS_H : PKT_RESPONSE_STATUS_L];
|
666 |
|
|
rid = read_rp_data[PKT_THREAD_ID_H : PKT_THREAD_ID_L];
|
667 |
|
|
// AXI4 signals
|
668 |
|
|
ruser = read_rp_data[PKT_DATA_SIDEBAND_H : PKT_DATA_SIDEBAND_L];
|
669 |
|
|
end
|
670 |
|
|
|
671 |
|
|
//--------------------------------------
|
672 |
|
|
// Command control for read packets
|
673 |
|
|
//--------------------------------------
|
674 |
|
|
assign read_cp_valid = arvalid;
|
675 |
|
|
assign arready = read_cp_ready;
|
676 |
|
|
|
677 |
|
|
//--------------------------------------
|
678 |
|
|
// Command for handling read data
|
679 |
|
|
//--------------------------------------
|
680 |
|
|
assign rvalid = read_rp_valid;
|
681 |
|
|
assign read_rp_ready = rready;
|
682 |
|
|
assign rlast = read_rp_endofpacket;
|
683 |
|
|
|
684 |
|
|
//--------------------------------------
|
685 |
|
|
// Assertions
|
686 |
|
|
//--------------------------------------
|
687 |
|
|
// synthesis translate_off
|
688 |
|
|
generate
|
689 |
|
|
if (WRITE_ISSUING_CAPABILITY == 1) begin
|
690 |
|
|
wire write_cmd_accepted;
|
691 |
|
|
wire write_response_accepted;
|
692 |
|
|
wire write_response_count_is_1;
|
693 |
|
|
reg [log2ceil(WRITE_ISSUING_CAPABILITY+1)-1:0] pending_write_response_count;
|
694 |
|
|
reg [log2ceil(WRITE_ISSUING_CAPABILITY+1)-1:0] next_pending_write_response_count;
|
695 |
|
|
|
696 |
|
|
assign write_cmd_accepted = write_cp_valid && write_cp_ready && write_cp_endofpacket;
|
697 |
|
|
assign write_response_accepted = write_rp_valid && write_rp_ready && write_rp_endofpacket;
|
698 |
|
|
|
699 |
|
|
always_comb
|
700 |
|
|
begin
|
701 |
|
|
next_pending_write_response_count = pending_write_response_count;
|
702 |
|
|
if (write_cmd_accepted)
|
703 |
|
|
next_pending_write_response_count = pending_write_response_count + 1'b1;
|
704 |
|
|
if (write_response_accepted)
|
705 |
|
|
next_pending_write_response_count = pending_write_response_count - 1'b1;
|
706 |
|
|
if (write_cmd_accepted && write_response_accepted)
|
707 |
|
|
next_pending_write_response_count = pending_write_response_count;
|
708 |
|
|
end
|
709 |
|
|
always_ff @(posedge aclk, negedge aresetn)
|
710 |
|
|
begin
|
711 |
|
|
if (!aresetn) begin
|
712 |
|
|
pending_write_response_count <= '0;
|
713 |
|
|
end else begin
|
714 |
|
|
pending_write_response_count <= next_pending_write_response_count;
|
715 |
|
|
end
|
716 |
|
|
end
|
717 |
|
|
|
718 |
|
|
assign write_response_count_is_1 = (pending_write_response_count == 1);
|
719 |
|
|
// assertion
|
720 |
|
|
ERROR_WRITE_ISSUING_CAPABILITY_equal_1_but_master_sends_more_commands_or_switch_slave_before_response_back_please_visit_the_parameter:
|
721 |
|
|
assert property (@(posedge aclk)
|
722 |
|
|
disable iff (!aresetn) !(write_response_count_is_1 && write_cmd_accepted));
|
723 |
|
|
end // if (WRITE_ISSUING_CAPABILITY == 1)
|
724 |
|
|
|
725 |
|
|
if (READ_ISSUING_CAPABILITY == 1) begin
|
726 |
|
|
wire read_cmd_accepted;
|
727 |
|
|
wire read_response_accepted;
|
728 |
|
|
wire read_response_count_is_1;
|
729 |
|
|
|
730 |
|
|
reg [log2ceil(READ_ISSUING_CAPABILITY+1)-1:0] pending_read_response_count;
|
731 |
|
|
reg [log2ceil(READ_ISSUING_CAPABILITY+1)-1:0] next_pending_read_response_count;
|
732 |
|
|
|
733 |
|
|
assign read_cmd_accepted = read_cp_valid && read_cp_ready && read_cp_endofpacket;
|
734 |
|
|
assign read_response_accepted = read_rp_valid && read_rp_ready && read_rp_endofpacket;
|
735 |
|
|
|
736 |
|
|
always_comb
|
737 |
|
|
begin
|
738 |
|
|
next_pending_read_response_count = pending_read_response_count;
|
739 |
|
|
if (read_cmd_accepted)
|
740 |
|
|
next_pending_read_response_count = pending_read_response_count + 1'b1;
|
741 |
|
|
if (read_response_accepted)
|
742 |
|
|
next_pending_read_response_count = pending_read_response_count - 1'b1;
|
743 |
|
|
if (read_cmd_accepted && read_response_accepted)
|
744 |
|
|
next_pending_read_response_count = pending_read_response_count;
|
745 |
|
|
end
|
746 |
|
|
always_ff @(posedge aclk, negedge aresetn)
|
747 |
|
|
begin
|
748 |
|
|
if (!aresetn) begin
|
749 |
|
|
pending_read_response_count <= '0;
|
750 |
|
|
end else begin
|
751 |
|
|
pending_read_response_count <= next_pending_read_response_count;
|
752 |
|
|
end
|
753 |
|
|
end
|
754 |
|
|
assign read_response_count_is_1 = (pending_read_response_count == 1);
|
755 |
|
|
ERROR_READ_ISSUING_CAPABILITY_equal_1_but_master_sends_more_commands_or_switch_slave_before_response_back_please_visit_the_parameter:
|
756 |
|
|
assert property (@(posedge aclk)
|
757 |
|
|
disable iff (!aresetn) !(read_response_count_is_1 && read_cmd_accepted));
|
758 |
|
|
end // if (READ_ISSUING_CAPABILITY == 1)
|
759 |
|
|
endgenerate
|
760 |
|
|
|
761 |
|
|
ERROR_awlock_reserved_value:
|
762 |
|
|
assert property (@(posedge aclk)
|
763 |
|
|
disable iff (!aresetn) ( !(awvalid && awlock == 2'b11) ));
|
764 |
|
|
|
765 |
|
|
ERROR_arlock_reserved_value:
|
766 |
|
|
assert property (@(posedge aclk)
|
767 |
|
|
disable iff (!aresetn) ( !(arvalid && arlock == 2'b11) ));
|
768 |
|
|
|
769 |
|
|
// synthesis translate_on
|
770 |
|
|
endmodule
|