1 |
4 |
magro732 |
-------------------------------------------------------------------------------
|
2 |
|
|
--
|
3 |
|
|
-- RapidIO IP Library Core
|
4 |
|
|
--
|
5 |
|
|
-- This file is part of the RapidIO IP library project
|
6 |
|
|
-- http://www.opencores.org/cores/rio/
|
7 |
|
|
--
|
8 |
|
|
-- Description
|
9 |
|
|
-- Containing the transmission channel independent parts of the LP-Serial
|
10 |
|
|
-- Physical Layer Specification (RapidIO 2.2, part 6).
|
11 |
|
|
--
|
12 |
|
|
-- To Do:
|
13 |
|
|
-- -
|
14 |
|
|
--
|
15 |
|
|
-- Author(s):
|
16 |
|
|
-- - Magnus Rosenius, magro732@opencores.org
|
17 |
|
|
--
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
--
|
20 |
|
|
-- Copyright (C) 2013 Authors and OPENCORES.ORG
|
21 |
|
|
--
|
22 |
|
|
-- This source file may be used and distributed without
|
23 |
|
|
-- restriction provided that this copyright statement is not
|
24 |
|
|
-- removed from the file and that any derivative work contains
|
25 |
|
|
-- the original copyright notice and the associated disclaimer.
|
26 |
|
|
--
|
27 |
|
|
-- This source file is free software; you can redistribute it
|
28 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
29 |
|
|
-- Public License as published by the Free Software Foundation;
|
30 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
31 |
|
|
-- later version.
|
32 |
|
|
--
|
33 |
|
|
-- This source is distributed in the hope that it will be
|
34 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
35 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
36 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
37 |
|
|
-- details.
|
38 |
|
|
--
|
39 |
|
|
-- You should have received a copy of the GNU Lesser General
|
40 |
|
|
-- Public License along with this source; if not, download it
|
41 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
42 |
|
|
--
|
43 |
|
|
-------------------------------------------------------------------------------
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
-------------------------------------------------------------------------------
|
47 |
|
|
-- RioSerial
|
48 |
|
|
-------------------------------------------------------------------------------
|
49 |
|
|
library ieee;
|
50 |
|
|
use ieee.std_logic_1164.all;
|
51 |
|
|
use ieee.numeric_std.all;
|
52 |
|
|
use work.rio_common.all;
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
-------------------------------------------------------------------------------
|
56 |
|
|
-- Entity for RioSerial.
|
57 |
|
|
-------------------------------------------------------------------------------
|
58 |
|
|
entity RioSerial is
|
59 |
|
|
generic(
|
60 |
|
|
TIMEOUT_WIDTH : natural);
|
61 |
|
|
port(
|
62 |
|
|
-- System signals.
|
63 |
|
|
clk : in std_logic;
|
64 |
|
|
areset_n : in std_logic;
|
65 |
|
|
|
66 |
|
|
-- Status signals for maintenance operations.
|
67 |
|
|
portLinkTimeout_i : in std_logic_vector(TIMEOUT_WIDTH-1 downto 0);
|
68 |
|
|
linkInitialized_o : out std_logic;
|
69 |
|
|
inputPortEnable_i : in std_logic;
|
70 |
|
|
outputPortEnable_i : in std_logic;
|
71 |
|
|
|
72 |
|
|
-- Support for portLocalAckIdCSR.
|
73 |
|
|
localAckIdWrite_i : in std_logic;
|
74 |
|
|
clrOutstandingAckId_i : in std_logic;
|
75 |
|
|
inboundAckId_i : in std_logic_vector(4 downto 0);
|
76 |
|
|
outstandingAckId_i : in std_logic_vector(4 downto 0);
|
77 |
|
|
outboundAckId_i : in std_logic_vector(4 downto 0);
|
78 |
|
|
inboundAckId_o : out std_logic_vector(4 downto 0);
|
79 |
|
|
outstandingAckId_o : out std_logic_vector(4 downto 0);
|
80 |
|
|
outboundAckId_o : out std_logic_vector(4 downto 0);
|
81 |
|
|
|
82 |
|
|
-- Outbound frame interface.
|
83 |
|
|
readFrameEmpty_i : in std_logic;
|
84 |
|
|
readFrame_o : out std_logic;
|
85 |
|
|
readFrameRestart_o : out std_logic;
|
86 |
|
|
readFrameAborted_i : in std_logic;
|
87 |
|
|
readWindowEmpty_i : in std_logic;
|
88 |
|
|
readWindowReset_o : out std_logic;
|
89 |
|
|
readWindowNext_o : out std_logic;
|
90 |
|
|
readContentEmpty_i : in std_logic;
|
91 |
|
|
readContent_o : out std_logic;
|
92 |
|
|
readContentEnd_i : in std_logic;
|
93 |
|
|
readContentData_i : in std_logic_vector(31 downto 0);
|
94 |
|
|
|
95 |
|
|
-- Inbound frame interface.
|
96 |
|
|
writeFrameFull_i : in std_logic;
|
97 |
|
|
writeFrame_o : out std_logic;
|
98 |
|
|
writeFrameAbort_o : out std_logic;
|
99 |
|
|
writeContent_o : out std_logic;
|
100 |
|
|
writeContentData_o : out std_logic_vector(31 downto 0);
|
101 |
|
|
|
102 |
|
|
-- PCS layer signals.
|
103 |
|
|
portInitialized_i : in std_logic;
|
104 |
|
|
outboundSymbolEmpty_o : out std_logic;
|
105 |
|
|
outboundSymbolRead_i : in std_logic;
|
106 |
|
|
outboundSymbol_o : out std_logic_vector(33 downto 0);
|
107 |
|
|
inboundSymbolFull_o : out std_logic;
|
108 |
|
|
inboundSymbolWrite_i : in std_logic;
|
109 |
|
|
inboundSymbol_i : in std_logic_vector(33 downto 0));
|
110 |
|
|
end entity;
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
-------------------------------------------------------------------------------
|
114 |
|
|
-- Architecture for RioSerial.
|
115 |
|
|
-------------------------------------------------------------------------------
|
116 |
|
|
architecture RioSerialImpl of RioSerial is
|
117 |
|
|
|
118 |
|
|
component RioFifo1 is
|
119 |
|
|
generic(
|
120 |
|
|
WIDTH : natural);
|
121 |
|
|
port(
|
122 |
|
|
clk : in std_logic;
|
123 |
|
|
areset_n : in std_logic;
|
124 |
|
|
|
125 |
|
|
empty_o : out std_logic;
|
126 |
|
|
read_i : in std_logic;
|
127 |
|
|
data_o : out std_logic_vector(WIDTH-1 downto 0);
|
128 |
|
|
|
129 |
|
|
full_o : out std_logic;
|
130 |
|
|
write_i : in std_logic;
|
131 |
|
|
data_i : in std_logic_vector(WIDTH-1 downto 0));
|
132 |
|
|
end component;
|
133 |
|
|
|
134 |
|
|
component RioTransmitter is
|
135 |
|
|
generic(
|
136 |
|
|
TIMEOUT_WIDTH : natural);
|
137 |
|
|
port(
|
138 |
|
|
clk : in std_logic;
|
139 |
|
|
areset_n : in std_logic;
|
140 |
|
|
|
141 |
|
|
portLinkTimeout_i : in std_logic_vector(TIMEOUT_WIDTH-1 downto 0);
|
142 |
|
|
portEnable_i : in std_logic;
|
143 |
|
|
|
144 |
|
|
localAckIdWrite_i : in std_logic;
|
145 |
|
|
clrOutstandingAckId_i : in std_logic;
|
146 |
|
|
outstandingAckId_i : in std_logic_vector(4 downto 0);
|
147 |
|
|
outboundAckId_i : in std_logic_vector(4 downto 0);
|
148 |
|
|
outstandingAckId_o : out std_logic_vector(4 downto 0);
|
149 |
|
|
outboundAckId_o : out std_logic_vector(4 downto 0);
|
150 |
|
|
|
151 |
|
|
portInitialized_i : in std_logic;
|
152 |
|
|
txFull_i : in std_logic;
|
153 |
|
|
txWrite_o : out std_logic;
|
154 |
|
|
txControl_o : out std_logic_vector(1 downto 0);
|
155 |
|
|
txData_o : out std_logic_vector(31 downto 0);
|
156 |
|
|
|
157 |
|
|
txControlEmpty_i : in std_logic;
|
158 |
|
|
txControlSymbol_i : in std_logic_vector(12 downto 0);
|
159 |
|
|
txControlUpdate_o : out std_logic;
|
160 |
|
|
rxControlEmpty_i : in std_logic;
|
161 |
|
|
rxControlSymbol_i : in std_logic_vector(12 downto 0);
|
162 |
|
|
rxControlUpdate_o : out std_logic;
|
163 |
|
|
|
164 |
|
|
linkInitialized_i : in std_logic;
|
165 |
|
|
linkInitialized_o : out std_logic;
|
166 |
|
|
ackIdStatus_i : in std_logic_vector(4 downto 0);
|
167 |
|
|
|
168 |
|
|
readFrameEmpty_i : in std_logic;
|
169 |
|
|
readFrame_o : out std_logic;
|
170 |
|
|
readFrameRestart_o : out std_logic;
|
171 |
|
|
readFrameAborted_i : in std_logic;
|
172 |
|
|
readWindowEmpty_i : in std_logic;
|
173 |
|
|
readWindowReset_o : out std_logic;
|
174 |
|
|
readWindowNext_o : out std_logic;
|
175 |
|
|
readContentEmpty_i : in std_logic;
|
176 |
|
|
readContent_o : out std_logic;
|
177 |
|
|
readContentEnd_i : in std_logic;
|
178 |
|
|
readContentData_i : in std_logic_vector(31 downto 0));
|
179 |
|
|
end component;
|
180 |
|
|
|
181 |
|
|
component RioReceiver is
|
182 |
|
|
port(
|
183 |
|
|
clk : in std_logic;
|
184 |
|
|
areset_n : in std_logic;
|
185 |
|
|
|
186 |
|
|
portEnable_i : in std_logic;
|
187 |
|
|
|
188 |
|
|
localAckIdWrite_i : in std_logic;
|
189 |
|
|
inboundAckId_i : in std_logic_vector(4 downto 0);
|
190 |
|
|
inboundAckId_o : out std_logic_vector(4 downto 0);
|
191 |
|
|
|
192 |
|
|
portInitialized_i : in std_logic;
|
193 |
|
|
rxEmpty_i : in std_logic;
|
194 |
|
|
rxRead_o : out std_logic;
|
195 |
|
|
rxControl_i : in std_logic_vector(1 downto 0);
|
196 |
|
|
rxData_i : in std_logic_vector(31 downto 0);
|
197 |
|
|
|
198 |
|
|
txControlWrite_o : out std_logic;
|
199 |
|
|
txControlSymbol_o : out std_logic_vector(12 downto 0);
|
200 |
|
|
rxControlWrite_o : out std_logic;
|
201 |
|
|
rxControlSymbol_o : out std_logic_vector(12 downto 0);
|
202 |
|
|
|
203 |
|
|
ackIdStatus_o : out std_logic_vector(4 downto 0);
|
204 |
|
|
linkInitialized_o : out std_logic;
|
205 |
|
|
|
206 |
|
|
writeFrameFull_i : in std_logic;
|
207 |
|
|
writeFrame_o : out std_logic;
|
208 |
|
|
writeFrameAbort_o : out std_logic;
|
209 |
|
|
writeContent_o : out std_logic;
|
210 |
|
|
writeContentData_o : out std_logic_vector(31 downto 0));
|
211 |
|
|
end component;
|
212 |
|
|
|
213 |
|
|
signal linkInitializedRx : std_logic;
|
214 |
|
|
signal linkInitializedTx : std_logic;
|
215 |
|
|
signal ackIdStatus : std_logic_vector(4 downto 0);
|
216 |
|
|
|
217 |
|
|
signal txControlWrite : std_logic;
|
218 |
|
|
signal txControlWriteSymbol : std_logic_vector(12 downto 0);
|
219 |
|
|
signal txControlReadEmpty : std_logic;
|
220 |
|
|
signal txControlRead : std_logic;
|
221 |
|
|
signal txControlReadSymbol : std_logic_vector(12 downto 0);
|
222 |
|
|
|
223 |
|
|
signal rxControlWrite : std_logic;
|
224 |
|
|
signal rxControlWriteSymbol : std_logic_vector(12 downto 0);
|
225 |
|
|
signal rxControlReadEmpty : std_logic;
|
226 |
|
|
signal rxControlRead : std_logic;
|
227 |
|
|
signal rxControlReadSymbol : std_logic_vector(12 downto 0);
|
228 |
|
|
|
229 |
|
|
signal outboundFull : std_logic;
|
230 |
|
|
signal outboundWrite : std_logic;
|
231 |
|
|
signal outboundControl : std_logic_vector(1 downto 0);
|
232 |
|
|
signal outboundData : std_logic_vector(31 downto 0);
|
233 |
|
|
signal outboundSymbol : std_logic_vector(33 downto 0);
|
234 |
|
|
|
235 |
|
|
signal inboundEmpty : std_logic;
|
236 |
|
|
signal inboundRead : std_logic;
|
237 |
|
|
signal inboundControl : std_logic_vector(1 downto 0);
|
238 |
|
|
signal inboundData : std_logic_vector(31 downto 0);
|
239 |
|
|
signal inboundSymbol : std_logic_vector(33 downto 0);
|
240 |
|
|
|
241 |
|
|
begin
|
242 |
|
|
|
243 |
|
|
linkInitialized_o <=
|
244 |
|
|
'1' when ((linkInitializedRx = '1') and (linkInitializedTx = '1')) else '0';
|
245 |
|
|
|
246 |
|
|
-----------------------------------------------------------------------------
|
247 |
|
|
-- Serial layer modules.
|
248 |
|
|
-----------------------------------------------------------------------------
|
249 |
|
|
|
250 |
|
|
Transmitter: RioTransmitter
|
251 |
|
|
generic map(
|
252 |
|
|
TIMEOUT_WIDTH=>TIMEOUT_WIDTH)
|
253 |
|
|
port map(
|
254 |
|
|
clk=>clk, areset_n=>areset_n,
|
255 |
|
|
portLinkTimeout_i=>portLinkTimeout_i,
|
256 |
|
|
portEnable_i=>outputPortEnable_i,
|
257 |
|
|
localAckIdWrite_i=>localAckIdWrite_i,
|
258 |
|
|
clrOutstandingAckId_i=>clrOutstandingAckId_i,
|
259 |
|
|
outstandingAckId_i=>outstandingAckId_i,
|
260 |
|
|
outboundAckId_i=>outboundAckId_i,
|
261 |
|
|
outstandingAckId_o=>outstandingAckId_o,
|
262 |
|
|
outboundAckId_o=>outboundAckId_o,
|
263 |
|
|
portInitialized_i=>portInitialized_i,
|
264 |
|
|
txFull_i=>outboundFull, txWrite_o=>outboundWrite,
|
265 |
|
|
txControl_o=>outboundControl, txData_o=>outboundData,
|
266 |
|
|
txControlEmpty_i=>txControlReadEmpty, txControlSymbol_i=>txControlReadSymbol,
|
267 |
|
|
txControlUpdate_o=>txControlRead,
|
268 |
|
|
rxControlEmpty_i=>rxControlReadEmpty, rxControlSymbol_i=>rxControlReadSymbol,
|
269 |
|
|
rxControlUpdate_o=>rxControlRead,
|
270 |
|
|
linkInitialized_o=>linkInitializedTx,
|
271 |
|
|
linkInitialized_i=>linkInitializedRx, ackIdStatus_i=>ackIdStatus,
|
272 |
|
|
readFrameEmpty_i=>readFrameEmpty_i, readFrame_o=>readFrame_o,
|
273 |
|
|
readFrameRestart_o=>readFrameRestart_o, readFrameAborted_i=>readFrameAborted_i,
|
274 |
|
|
readWindowEmpty_i=>readWindowEmpty_i,
|
275 |
|
|
readWindowReset_o=>readWindowReset_o, readWindowNext_o=>readWindowNext_o,
|
276 |
|
|
readContentEmpty_i=>readContentEmpty_i, readContent_o=>readContent_o,
|
277 |
|
|
readContentEnd_i=>readContentEnd_i, readContentData_i=>readContentData_i);
|
278 |
|
|
|
279 |
|
|
TxSymbolFifo: RioFifo1
|
280 |
|
|
generic map(WIDTH=>13)
|
281 |
|
|
port map(
|
282 |
|
|
clk=>clk, areset_n=>areset_n,
|
283 |
|
|
empty_o=>txControlReadEmpty, read_i=>txControlRead, data_o=>txControlReadSymbol,
|
284 |
|
|
full_o=>open, write_i=>txControlWrite, data_i=>txControlWriteSymbol);
|
285 |
|
|
|
286 |
|
|
RxSymbolFifo: RioFifo1
|
287 |
|
|
generic map(WIDTH=>13)
|
288 |
|
|
port map(
|
289 |
|
|
clk=>clk, areset_n=>areset_n,
|
290 |
|
|
empty_o=>rxControlReadEmpty, read_i=>rxControlRead, data_o=>rxControlReadSymbol,
|
291 |
|
|
full_o=>open, write_i=>rxControlWrite, data_i=>rxControlWriteSymbol);
|
292 |
|
|
|
293 |
|
|
Receiver: RioReceiver
|
294 |
|
|
port map(
|
295 |
|
|
clk=>clk, areset_n=>areset_n,
|
296 |
|
|
portEnable_i=>inputPortEnable_i,
|
297 |
|
|
localAckIdWrite_i=>localAckIdWrite_i,
|
298 |
|
|
inboundAckId_i=>inboundAckId_i,
|
299 |
|
|
inboundAckId_o=>inboundAckId_o,
|
300 |
|
|
portInitialized_i=>portInitialized_i,
|
301 |
|
|
rxEmpty_i=>inboundEmpty, rxRead_o=>inboundRead,
|
302 |
|
|
rxControl_i=>inboundControl, rxData_i=>inboundData,
|
303 |
|
|
txControlWrite_o=>txControlWrite, txControlSymbol_o=>txControlWriteSymbol,
|
304 |
|
|
rxControlWrite_o=>rxControlWrite, rxControlSymbol_o=>rxControlWriteSymbol,
|
305 |
|
|
ackIdStatus_o=>ackIdStatus,
|
306 |
|
|
linkInitialized_o=>linkInitializedRx,
|
307 |
|
|
writeFrameFull_i=>writeFrameFull_i,
|
308 |
|
|
writeFrame_o=>writeFrame_o, writeFrameAbort_o=>writeFrameAbort_o,
|
309 |
|
|
writeContent_o=>writeContent_o, writeContentData_o=>writeContentData_o);
|
310 |
|
|
|
311 |
|
|
-----------------------------------------------------------------------------
|
312 |
|
|
-- PCS layer FIFO interface.
|
313 |
|
|
-----------------------------------------------------------------------------
|
314 |
|
|
|
315 |
|
|
outboundSymbol <= outboundControl & outboundData;
|
316 |
|
|
OutboundSymbolFifo: RioFifo1
|
317 |
|
|
generic map(WIDTH=>34)
|
318 |
|
|
port map(
|
319 |
|
|
clk=>clk, areset_n=>areset_n,
|
320 |
|
|
empty_o=>outboundSymbolEmpty_o, read_i=>outboundSymbolRead_i, data_o=>outboundSymbol_o,
|
321 |
|
|
full_o=>outboundFull, write_i=>outboundWrite, data_i=>outboundSymbol);
|
322 |
|
|
|
323 |
|
|
inboundControl <= inboundSymbol(33 downto 32);
|
324 |
|
|
inboundData <= inboundSymbol(31 downto 0);
|
325 |
|
|
InboundSymbolFifo: RioFifo1
|
326 |
|
|
generic map(WIDTH=>34)
|
327 |
|
|
port map(
|
328 |
|
|
clk=>clk, areset_n=>areset_n,
|
329 |
|
|
empty_o=>inboundEmpty, read_i=>inboundRead, data_o=>inboundSymbol,
|
330 |
|
|
full_o=>inboundSymbolFull_o, write_i=>inboundSymbolWrite_i, data_i=>inboundSymbol_i);
|
331 |
|
|
|
332 |
|
|
end architecture;
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
|
336 |
|
|
-------------------------------------------------------------------------------
|
337 |
|
|
-- RioTransmitter
|
338 |
|
|
-------------------------------------------------------------------------------
|
339 |
|
|
library ieee;
|
340 |
|
|
use ieee.std_logic_1164.all;
|
341 |
|
|
use ieee.numeric_std.all;
|
342 |
|
|
use work.rio_common.all;
|
343 |
|
|
|
344 |
|
|
|
345 |
|
|
-------------------------------------------------------------------------------
|
346 |
|
|
-- Entity for RioTransmitter.
|
347 |
|
|
-------------------------------------------------------------------------------
|
348 |
|
|
entity RioTransmitter is
|
349 |
|
|
generic(
|
350 |
|
|
TIMEOUT_WIDTH : natural);
|
351 |
|
|
port(
|
352 |
|
|
-- System signals.
|
353 |
|
|
clk : in std_logic;
|
354 |
|
|
areset_n : in std_logic;
|
355 |
|
|
|
356 |
|
|
-- Status signals used for maintenance.
|
357 |
|
|
portLinkTimeout_i : in std_logic_vector(TIMEOUT_WIDTH-1 downto 0);
|
358 |
|
|
portEnable_i : in std_logic;
|
359 |
|
|
|
360 |
|
|
-- Support for localAckIdCSR.
|
361 |
|
|
localAckIdWrite_i : in std_logic;
|
362 |
|
|
clrOutstandingAckId_i : in std_logic;
|
363 |
|
|
outstandingAckId_i : in std_logic_vector(4 downto 0);
|
364 |
|
|
outboundAckId_i : in std_logic_vector(4 downto 0);
|
365 |
|
|
outstandingAckId_o : out std_logic_vector(4 downto 0);
|
366 |
|
|
outboundAckId_o : out std_logic_vector(4 downto 0);
|
367 |
|
|
|
368 |
|
|
-- Port output interface.
|
369 |
|
|
portInitialized_i : in std_logic;
|
370 |
|
|
txFull_i : in std_logic;
|
371 |
|
|
txWrite_o : out std_logic;
|
372 |
|
|
txControl_o : out std_logic_vector(1 downto 0);
|
373 |
|
|
txData_o : out std_logic_vector(31 downto 0);
|
374 |
|
|
|
375 |
|
|
-- Control symbols aimed to the transmitter.
|
376 |
|
|
txControlEmpty_i : in std_logic;
|
377 |
|
|
txControlSymbol_i : in std_logic_vector(12 downto 0);
|
378 |
|
|
txControlUpdate_o : out std_logic;
|
379 |
|
|
|
380 |
|
|
-- Control symbols from the receiver to send.
|
381 |
|
|
rxControlEmpty_i : in std_logic;
|
382 |
|
|
rxControlSymbol_i : in std_logic_vector(12 downto 0);
|
383 |
|
|
rxControlUpdate_o : out std_logic;
|
384 |
|
|
|
385 |
|
|
-- Internal signalling from the receiver part.
|
386 |
|
|
linkInitialized_o : out std_logic;
|
387 |
|
|
linkInitialized_i : in std_logic;
|
388 |
|
|
ackIdStatus_i : in std_logic_vector(4 downto 0);
|
389 |
|
|
|
390 |
|
|
-- Frame buffer interface.
|
391 |
|
|
readFrameEmpty_i : in std_logic;
|
392 |
|
|
readFrame_o : out std_logic;
|
393 |
|
|
readFrameRestart_o : out std_logic;
|
394 |
|
|
readFrameAborted_i : in std_logic;
|
395 |
|
|
readWindowEmpty_i : in std_logic;
|
396 |
|
|
readWindowReset_o : out std_logic;
|
397 |
|
|
readWindowNext_o : out std_logic;
|
398 |
|
|
readContentEmpty_i : in std_logic;
|
399 |
|
|
readContent_o : out std_logic;
|
400 |
|
|
readContentEnd_i : in std_logic;
|
401 |
|
|
readContentData_i : in std_logic_vector(31 downto 0));
|
402 |
|
|
end entity;
|
403 |
|
|
|
404 |
|
|
|
405 |
|
|
-------------------------------------------------------------------------------
|
406 |
|
|
-- Architecture for RioTransmitter.
|
407 |
|
|
-------------------------------------------------------------------------------
|
408 |
|
|
architecture RioTransmitterImpl of RioTransmitter is
|
409 |
|
|
|
410 |
|
|
constant NUMBER_STATUS_TRANSMIT : natural := 15;
|
411 |
|
|
constant NUMBER_LINK_RESPONSE_RETRIES : natural := 2;
|
412 |
|
|
|
413 |
|
|
component MemorySimpleDualPortAsync is
|
414 |
|
|
generic(
|
415 |
|
|
ADDRESS_WIDTH : natural := 1;
|
416 |
|
|
DATA_WIDTH : natural := 1;
|
417 |
|
|
INIT_VALUE : std_logic := 'U');
|
418 |
|
|
port(
|
419 |
|
|
clkA_i : in std_logic;
|
420 |
|
|
enableA_i : in std_logic;
|
421 |
|
|
addressA_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
|
422 |
|
|
dataA_i : in std_logic_vector(DATA_WIDTH-1 downto 0);
|
423 |
|
|
|
424 |
|
|
addressB_i : in std_logic_vector(ADDRESS_WIDTH-1 downto 0);
|
425 |
|
|
dataB_o : out std_logic_vector(DATA_WIDTH-1 downto 0));
|
426 |
|
|
end component;
|
427 |
|
|
|
428 |
|
|
component Crc5ITU is
|
429 |
|
|
port(
|
430 |
|
|
d_i : in std_logic_vector(18 downto 0);
|
431 |
|
|
crc_o : out std_logic_vector(4 downto 0));
|
432 |
|
|
end component;
|
433 |
|
|
|
434 |
|
|
type StateType is (STATE_UNINITIALIZED, STATE_PORT_INITIALIZED,
|
435 |
|
|
STATE_NORMAL,
|
436 |
|
|
STATE_OUTPUT_RETRY_STOPPED,
|
437 |
|
|
STATE_SEND_LINK_REQUEST, STATE_OUTPUT_ERROR_STOPPED,
|
438 |
|
|
STATE_RECOVER, STATE_FATAL_ERROR);
|
439 |
|
|
signal stateCurrent, stateNext : StateType;
|
440 |
|
|
|
441 |
|
|
signal statusReceivedCurrent, statusReceivedNext : std_logic;
|
442 |
|
|
signal counterCurrent, counterNext : natural range 0 to 15;
|
443 |
|
|
signal symbolsTransmittedCurrent, symbolsTransmittedNext : natural range 0 to 255;
|
444 |
|
|
|
445 |
|
|
type FrameStateType is (FRAME_START, FRAME_CHECK, FRAME_ACKID, FRAME_BODY, FRAME_END);
|
446 |
|
|
signal frameStateCurrent, frameStateNext : FrameStateType;
|
447 |
|
|
signal ackIdCurrent, ackIdNext : unsigned(4 downto 0) := (others=>'0');
|
448 |
|
|
signal ackIdWindowCurrent, ackIdWindowNext : unsigned(4 downto 0) := (others=>'0');
|
449 |
|
|
signal bufferStatusCurrent, bufferStatusNext : std_logic_vector(4 downto 0);
|
450 |
|
|
|
451 |
|
|
signal stype0 : std_logic_vector(2 downto 0);
|
452 |
|
|
signal parameter0 : std_logic_vector(4 downto 0);
|
453 |
|
|
signal parameter1 : std_logic_vector(4 downto 0);
|
454 |
|
|
signal stype1 : std_logic_vector(2 downto 0);
|
455 |
|
|
signal cmd : std_logic_vector(2 downto 0);
|
456 |
|
|
|
457 |
|
|
signal txControlStype0 : std_logic_vector(2 downto 0);
|
458 |
|
|
signal txControlParameter0 : std_logic_vector(4 downto 0);
|
459 |
|
|
signal txControlParameter1 : std_logic_vector(4 downto 0);
|
460 |
|
|
|
461 |
|
|
signal rxControlStype0 : std_logic_vector(2 downto 0);
|
462 |
|
|
signal rxControlParameter0 : std_logic_vector(4 downto 0);
|
463 |
|
|
signal rxControlParameter1 : std_logic_vector(4 downto 0);
|
464 |
|
|
|
465 |
|
|
signal symbolWrite : std_logic;
|
466 |
|
|
signal symbolType : std_logic_vector(1 downto 0);
|
467 |
|
|
signal symbolControl : std_logic_vector(31 downto 0);
|
468 |
|
|
signal symbolData : std_logic_vector(31 downto 0);
|
469 |
|
|
signal crcCalculated : std_logic_vector(4 downto 0);
|
470 |
|
|
|
471 |
|
|
signal timeoutWrite : std_logic;
|
472 |
|
|
signal timeoutCounter : unsigned(TIMEOUT_WIDTH downto 0);
|
473 |
|
|
signal timeoutFrame : unsigned(TIMEOUT_WIDTH downto 0);
|
474 |
|
|
signal timeoutElapsed : unsigned(TIMEOUT_WIDTH downto 0);
|
475 |
|
|
signal timeoutDelta : unsigned(TIMEOUT_WIDTH downto 0);
|
476 |
|
|
signal timeoutExpired : std_logic;
|
477 |
|
|
|
478 |
|
|
signal timeoutAddress : std_logic_vector(4 downto 0);
|
479 |
|
|
signal timeoutMemoryOut : std_logic_vector(TIMEOUT_WIDTH downto 0);
|
480 |
|
|
|
481 |
|
|
begin
|
482 |
|
|
|
483 |
|
|
linkInitialized_o <= '0' when ((stateCurrent = STATE_UNINITIALIZED) or
|
484 |
|
|
(stateCurrent = STATE_PORT_INITIALIZED)) else '1';
|
485 |
|
|
|
486 |
|
|
-----------------------------------------------------------------------------
|
487 |
|
|
-- Assign control symbol from fifo signals.
|
488 |
|
|
-----------------------------------------------------------------------------
|
489 |
|
|
|
490 |
|
|
txControlStype0 <= txControlSymbol_i(12 downto 10);
|
491 |
|
|
txControlParameter0 <= txControlSymbol_i(9 downto 5);
|
492 |
|
|
txControlParameter1 <= txControlSymbol_i(4 downto 0);
|
493 |
|
|
|
494 |
|
|
rxControlStype0 <= rxControlSymbol_i(12 downto 10);
|
495 |
|
|
rxControlParameter0 <= rxControlSymbol_i(9 downto 5);
|
496 |
|
|
rxControlParameter1 <= rxControlSymbol_i(4 downto 0);
|
497 |
|
|
|
498 |
|
|
-----------------------------------------------------------------------------
|
499 |
|
|
-- Outbound symbol creation logic.
|
500 |
|
|
-----------------------------------------------------------------------------
|
501 |
|
|
|
502 |
|
|
symbolControl(31 downto 29) <= stype0;
|
503 |
|
|
symbolControl(28 downto 24) <= parameter0;
|
504 |
|
|
symbolControl(23 downto 19) <= parameter1;
|
505 |
|
|
symbolControl(18 downto 16) <= stype1;
|
506 |
|
|
symbolControl(15 downto 13) <= cmd;
|
507 |
|
|
symbolControl(12 downto 8) <= crcCalculated;
|
508 |
|
|
symbolControl(7 downto 0) <= x"00";
|
509 |
|
|
|
510 |
|
|
Crc5Calculator: Crc5ITU
|
511 |
|
|
port map(
|
512 |
|
|
d_i=>symbolControl(31 downto 13), crc_o=>crcCalculated);
|
513 |
|
|
|
514 |
|
|
txWrite_o <= symbolWrite;
|
515 |
|
|
txControl_o <= symbolType;
|
516 |
|
|
txData_o <= symbolControl when (symbolType = SYMBOL_CONTROL) else symbolData;
|
517 |
|
|
|
518 |
|
|
-----------------------------------------------------------------------------
|
519 |
|
|
-- Packet timeout logic.
|
520 |
|
|
-----------------------------------------------------------------------------
|
521 |
|
|
|
522 |
|
|
-- Note that the timer is one bit larger to be able to detect a timeout on a
|
523 |
|
|
-- free-running counter.
|
524 |
|
|
process(areset_n, clk)
|
525 |
|
|
begin
|
526 |
|
|
if (areset_n = '0') then
|
527 |
|
|
timeoutCounter <= (others=>'0');
|
528 |
|
|
elsif (clk'event and clk = '1') then
|
529 |
|
|
timeoutCounter <= timeoutCounter + 1;
|
530 |
|
|
end if;
|
531 |
|
|
end process;
|
532 |
|
|
|
533 |
|
|
timeoutElapsed <= timeoutCounter - timeoutFrame;
|
534 |
|
|
timeoutDelta <= unsigned('0' & portLinkTimeout_i) - timeoutElapsed;
|
535 |
|
|
timeoutExpired <= timeoutDelta(TIMEOUT_WIDTH);
|
536 |
|
|
|
537 |
|
|
timeoutFrame <= unsigned(timeoutMemoryOut);
|
538 |
|
|
TimeoutMemory: MemorySimpleDualPortAsync
|
539 |
|
|
generic map(ADDRESS_WIDTH=>5, DATA_WIDTH=>TIMEOUT_WIDTH+1, INIT_VALUE=>'0')
|
540 |
|
|
port map(
|
541 |
|
|
clkA_i=>clk, enableA_i=>timeoutWrite,
|
542 |
|
|
addressA_i=>timeoutAddress, dataA_i=>std_logic_vector(timeoutCounter),
|
543 |
|
|
addressB_i=>std_logic_vector(ackIdCurrent), dataB_o=>timeoutMemoryOut);
|
544 |
|
|
|
545 |
|
|
-----------------------------------------------------------------------------
|
546 |
|
|
-- Main outbound symbol handler, synchronous part.
|
547 |
|
|
-----------------------------------------------------------------------------
|
548 |
|
|
process(areset_n, clk)
|
549 |
|
|
begin
|
550 |
|
|
if (areset_n = '0') then
|
551 |
|
|
stateCurrent <= STATE_UNINITIALIZED;
|
552 |
|
|
|
553 |
|
|
statusReceivedCurrent <= '0';
|
554 |
|
|
counterCurrent <= 0;
|
555 |
|
|
symbolsTransmittedCurrent <= 0;
|
556 |
|
|
|
557 |
|
|
frameStateCurrent <= FRAME_START;
|
558 |
|
|
ackIdCurrent <= (others => '0');
|
559 |
|
|
ackIdWindowCurrent <= (others => '0');
|
560 |
|
|
bufferStatusCurrent <= (others => '0');
|
561 |
|
|
elsif (clk'event and clk = '1') then
|
562 |
|
|
stateCurrent <= stateNext;
|
563 |
|
|
|
564 |
|
|
statusReceivedCurrent <= statusReceivedNext;
|
565 |
|
|
counterCurrent <= counterNext;
|
566 |
|
|
symbolsTransmittedCurrent <= symbolsTransmittedNext;
|
567 |
|
|
|
568 |
|
|
frameStateCurrent <= frameStateNext;
|
569 |
|
|
ackIdCurrent <= ackIdNext;
|
570 |
|
|
ackIdWindowCurrent <= ackIdWindowNext;
|
571 |
|
|
bufferStatusCurrent <= bufferStatusNext;
|
572 |
|
|
end if;
|
573 |
|
|
end process;
|
574 |
|
|
|
575 |
|
|
-----------------------------------------------------------------------------
|
576 |
|
|
-- Main outbound symbol handler, combinatorial part.
|
577 |
|
|
-----------------------------------------------------------------------------
|
578 |
|
|
process(stateCurrent,
|
579 |
|
|
statusReceivedCurrent, counterCurrent,
|
580 |
|
|
symbolsTransmittedCurrent,
|
581 |
|
|
frameStateCurrent, ackIdCurrent, ackIdWindowCurrent, bufferStatusCurrent,
|
582 |
|
|
txControlStype0, txControlParameter0, txControlParameter1,
|
583 |
|
|
rxControlStype0, rxControlParameter0, rxControlParameter1,
|
584 |
|
|
portEnable_i,
|
585 |
|
|
localAckIdWrite_i, clrOutstandingAckId_i,
|
586 |
|
|
outstandingAckId_i, outboundAckId_i,
|
587 |
|
|
txFull_i,
|
588 |
|
|
txControlEmpty_i, txControlSymbol_i,
|
589 |
|
|
rxControlEmpty_i, rxControlSymbol_i,
|
590 |
|
|
portInitialized_i, linkInitialized_i, ackIdStatus_i,
|
591 |
|
|
readFrameEmpty_i, readFrameAborted_i,
|
592 |
|
|
readWindowEmpty_i,
|
593 |
|
|
readContentEmpty_i, readContentEnd_i, readContentData_i,
|
594 |
|
|
timeoutExpired)
|
595 |
|
|
begin
|
596 |
|
|
stateNext <= stateCurrent;
|
597 |
|
|
statusReceivedNext <= statusReceivedCurrent;
|
598 |
|
|
counterNext <= counterCurrent;
|
599 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent;
|
600 |
|
|
|
601 |
|
|
frameStateNext <= frameStateCurrent;
|
602 |
|
|
ackIdNext <= ackIdCurrent;
|
603 |
|
|
ackIdWindowNext <= ackIdWindowCurrent;
|
604 |
|
|
bufferStatusNext <= bufferStatusCurrent;
|
605 |
|
|
|
606 |
|
|
txControlUpdate_o <= '0';
|
607 |
|
|
rxControlUpdate_o <= '0';
|
608 |
|
|
|
609 |
|
|
readFrame_o <= '0';
|
610 |
|
|
readFrameRestart_o <= '0';
|
611 |
|
|
readWindowReset_o <= '0';
|
612 |
|
|
readWindowNext_o <= '0';
|
613 |
|
|
readContent_o <= '0';
|
614 |
|
|
|
615 |
|
|
symbolWrite <= '0';
|
616 |
|
|
symbolType <= (others=>'U');
|
617 |
|
|
stype0 <= (others=>'U');
|
618 |
|
|
parameter0 <= (others=>'U');
|
619 |
|
|
parameter1 <= (others=>'U');
|
620 |
|
|
stype1 <= (others=>'U');
|
621 |
|
|
cmd <= (others=>'U');
|
622 |
|
|
symbolData <= (others=>'U');
|
623 |
|
|
|
624 |
|
|
timeoutWrite <= '0';
|
625 |
|
|
timeoutAddress <= (others=>'U');
|
626 |
|
|
|
627 |
|
|
outstandingAckId_o <= std_logic_vector(ackIdCurrent);
|
628 |
|
|
outboundAckId_o <= std_logic_vector(ackIdWindowCurrent);
|
629 |
|
|
|
630 |
|
|
-- Check if a localAckIdWrite is active.
|
631 |
|
|
if (localAckIdWrite_i = '1') then
|
632 |
|
|
-- A localAckIdWrite is active.
|
633 |
|
|
|
634 |
|
|
-- Check if all outstanding packets should be discarded.
|
635 |
|
|
if (clrOutstandingAckId_i = '1') then
|
636 |
|
|
-- Delete all outbound packets.
|
637 |
|
|
-- REMARK: Remove all packets in another way... what if uninitialized???
|
638 |
|
|
stateNext <= STATE_RECOVER;
|
639 |
|
|
end if;
|
640 |
|
|
|
641 |
|
|
-- Set ackIds.
|
642 |
|
|
ackIdNext <= unsigned(outstandingAckId_i);
|
643 |
|
|
ackIdWindowNext <= unsigned(outboundAckId_i);
|
644 |
|
|
else
|
645 |
|
|
-- A localAckIdWrite is not active.
|
646 |
|
|
|
647 |
|
|
-- Act on the current state.
|
648 |
|
|
case (stateCurrent) is
|
649 |
|
|
|
650 |
|
|
when STATE_UNINITIALIZED =>
|
651 |
|
|
-----------------------------------------------------------------------
|
652 |
|
|
-- This state is entered at startup. A port that is not initialized
|
653 |
|
|
-- should only transmit idle sequences.
|
654 |
|
|
-----------------------------------------------------------------------
|
655 |
|
|
|
656 |
|
|
-- Check if the port is initialized.
|
657 |
|
|
if (portInitialized_i = '0') then
|
658 |
|
|
-- Port not initialized.
|
659 |
|
|
|
660 |
|
|
-- Check if any new symbols from the link partner has been received.
|
661 |
|
|
if (txControlEmpty_i = '0') then
|
662 |
|
|
-- New symbols have been received.
|
663 |
|
|
-- Discard all new symbols in this state.
|
664 |
|
|
txControlUpdate_o <= '1';
|
665 |
|
|
else
|
666 |
|
|
-- No new symbols from the link partner.
|
667 |
|
|
-- Dont do anything.
|
668 |
|
|
end if;
|
669 |
|
|
|
670 |
|
|
-- Check if any new symbols should be transmitted to the link partner.
|
671 |
|
|
if (rxControlEmpty_i = '0') then
|
672 |
|
|
-- New symbols should be transmitted.
|
673 |
|
|
-- Do not forward any symbols in this state.
|
674 |
|
|
rxControlUpdate_o <= '1';
|
675 |
|
|
else
|
676 |
|
|
-- No new symbols to transmit.
|
677 |
|
|
-- Dont do anything.
|
678 |
|
|
end if;
|
679 |
|
|
|
680 |
|
|
-- Check if a new symbol should be transmitted.
|
681 |
|
|
if (txFull_i = '0') then
|
682 |
|
|
-- A new symbol should be transmitted.
|
683 |
|
|
|
684 |
|
|
-- Send idle sequence.
|
685 |
|
|
symbolWrite <= '1';
|
686 |
|
|
symbolType <= SYMBOL_IDLE;
|
687 |
|
|
else
|
688 |
|
|
-- The outbound fifo is full.
|
689 |
|
|
-- Dont do anything.
|
690 |
|
|
end if;
|
691 |
|
|
|
692 |
|
|
-- Check if a new full packet is ready.
|
693 |
|
|
if (readFrameEmpty_i = '0') then
|
694 |
|
|
-- A new full packet is ready.
|
695 |
|
|
-- It is not possible to send the packet now. If the packet is not
|
696 |
|
|
-- discarded it might congest the full system if the link does not
|
697 |
|
|
-- go initialized. To avoid a congested switch, the packet is
|
698 |
|
|
-- discarded and will have to be resent by the source when the link
|
699 |
|
|
-- is up and running.
|
700 |
|
|
readFrame_o <= '1';
|
701 |
|
|
else
|
702 |
|
|
-- No new full packets are ready.
|
703 |
|
|
-- Dont do anything.
|
704 |
|
|
end if;
|
705 |
|
|
else
|
706 |
|
|
-- Port is initialized.
|
707 |
|
|
|
708 |
|
|
-- Go to the initialized state and reset the counters.
|
709 |
|
|
statusReceivedNext <= '0';
|
710 |
|
|
counterNext <= NUMBER_STATUS_TRANSMIT;
|
711 |
|
|
symbolsTransmittedNext <= 0;
|
712 |
|
|
stateNext <= STATE_PORT_INITIALIZED;
|
713 |
|
|
end if;
|
714 |
|
|
|
715 |
|
|
when STATE_PORT_INITIALIZED =>
|
716 |
|
|
-----------------------------------------------------------------------
|
717 |
|
|
-- The specification requires a status control symbol being sent at
|
718 |
|
|
-- least every 1024 code word until an error-free status has been
|
719 |
|
|
-- received. This implies that at most 256 idle sequences should be
|
720 |
|
|
-- sent in between status control symbols. Once an error-free status has
|
721 |
|
|
-- been received, status symbols may be sent more rapidly. At least 15
|
722 |
|
|
-- statuses has to be transmitted once an error-free status has been
|
723 |
|
|
-- received.
|
724 |
|
|
---------------------------------------------------------------------
|
725 |
|
|
|
726 |
|
|
-- Check if the port is initialized.
|
727 |
|
|
if (portInitialized_i = '1') then
|
728 |
|
|
-- Port is initialized.
|
729 |
|
|
|
730 |
|
|
-- Check if we are ready to change state to linkInitialized.
|
731 |
|
|
if ((linkInitialized_i = '1') and (counterCurrent = 0)) then
|
732 |
|
|
-- Receiver has received enough error free status symbols and we have
|
733 |
|
|
-- transmitted enough.
|
734 |
|
|
|
735 |
|
|
-- Initialize framing before entering the normal state.
|
736 |
|
|
ackIdWindowNext <= ackIdCurrent;
|
737 |
|
|
frameStateNext <= FRAME_START;
|
738 |
|
|
readWindowReset_o <= '1';
|
739 |
|
|
|
740 |
|
|
-- Considder the link initialized.
|
741 |
|
|
stateNext <= STATE_NORMAL;
|
742 |
|
|
else
|
743 |
|
|
-- Not ready to change state to linkInitialized.
|
744 |
|
|
-- Dont do anything.
|
745 |
|
|
end if;
|
746 |
|
|
|
747 |
|
|
-- Check if any new symbols from the link partner has been received.
|
748 |
|
|
if (txControlEmpty_i = '0') then
|
749 |
|
|
-- New symbols have been received.
|
750 |
|
|
|
751 |
|
|
-- Check if the new symbol is a status.
|
752 |
|
|
if (txControlStype0 = STYPE0_STATUS) then
|
753 |
|
|
-- A new status control symbol has been received.
|
754 |
|
|
statusReceivedNext <= '1';
|
755 |
|
|
|
756 |
|
|
-- Set the ackId and the linkpartner buffer status to what is indicated
|
757 |
|
|
-- in the received control symbol.
|
758 |
|
|
ackIdNext <= unsigned(txControlParameter0);
|
759 |
|
|
bufferStatusNext <= txControlParameter1;
|
760 |
|
|
else
|
761 |
|
|
-- Did not receive a status control symbol.
|
762 |
|
|
-- Discard it.
|
763 |
|
|
end if;
|
764 |
|
|
|
765 |
|
|
-- Update to the next control symbol received by the receiver.
|
766 |
|
|
txControlUpdate_o <= '1';
|
767 |
|
|
else
|
768 |
|
|
-- No new symbols from the link partner.
|
769 |
|
|
-- Dont do anything.
|
770 |
|
|
end if;
|
771 |
|
|
|
772 |
|
|
-- Check if any new symbols should be transmitted to the link partner.
|
773 |
|
|
if (rxControlEmpty_i = '0') then
|
774 |
|
|
-- New symbols should be transmitted.
|
775 |
|
|
-- Do not forward any symbols in this state.
|
776 |
|
|
rxControlUpdate_o <= '1';
|
777 |
|
|
else
|
778 |
|
|
-- No new symbols to transmit.
|
779 |
|
|
-- Dont do anything.
|
780 |
|
|
end if;
|
781 |
|
|
|
782 |
|
|
-- Check if a new symbol may be transmitted.
|
783 |
|
|
if (txFull_i = '0') then
|
784 |
|
|
-- A new symbol can be transmitted.
|
785 |
|
|
|
786 |
|
|
-- Check if idle sequence or a status symbol should be transmitted.
|
787 |
|
|
if (((statusReceivedCurrent = '0') and (symbolsTransmittedCurrent = 255)) or
|
788 |
|
|
((statusReceivedCurrent = '1') and (symbolsTransmittedCurrent > 15))) then
|
789 |
|
|
-- A status symbol should be transmitted.
|
790 |
|
|
|
791 |
|
|
-- Send a status control symbol to the link partner.
|
792 |
|
|
symbolWrite <= '1';
|
793 |
|
|
symbolType <= SYMBOL_CONTROL;
|
794 |
|
|
stype0 <= STYPE0_STATUS;
|
795 |
|
|
parameter0 <= ackIdStatus_i;
|
796 |
|
|
parameter1 <= "11111";
|
797 |
|
|
stype1 <= STYPE1_NOP;
|
798 |
|
|
cmd <= "000";
|
799 |
|
|
|
800 |
|
|
-- Reset idle sequence transmission counter.
|
801 |
|
|
symbolsTransmittedNext <= 0;
|
802 |
|
|
|
803 |
|
|
-- Check if the number of transmitted statuses should be updated.
|
804 |
|
|
if (statusReceivedCurrent = '1') and (counterCurrent /= 0) then
|
805 |
|
|
counterNext <= counterCurrent - 1;
|
806 |
|
|
end if;
|
807 |
|
|
else
|
808 |
|
|
-- A idle sequence should be transmitted.
|
809 |
|
|
symbolWrite <= '1';
|
810 |
|
|
symbolType <= SYMBOL_IDLE;
|
811 |
|
|
|
812 |
|
|
-- Increment the idle sequence transmission counter.
|
813 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
814 |
|
|
end if;
|
815 |
|
|
else
|
816 |
|
|
-- Cannot send a new symbol.
|
817 |
|
|
-- Dont do anything.
|
818 |
|
|
end if;
|
819 |
|
|
else
|
820 |
|
|
-- Go back to the uninitialized state.
|
821 |
|
|
stateNext <= STATE_UNINITIALIZED;
|
822 |
|
|
end if;
|
823 |
|
|
|
824 |
|
|
when STATE_NORMAL =>
|
825 |
|
|
-------------------------------------------------------------------
|
826 |
|
|
-- This state is the normal state. It relays frames and handle flow
|
827 |
|
|
-- control.
|
828 |
|
|
-------------------------------------------------------------------
|
829 |
|
|
|
830 |
|
|
-- Check that both the port and link is initialized.
|
831 |
|
|
if (portInitialized_i = '1') and (linkInitialized_i = '1') then
|
832 |
|
|
-- The port and link is initialized.
|
833 |
|
|
|
834 |
|
|
-- Check if any control symbol has been received from the link
|
835 |
|
|
-- partner.
|
836 |
|
|
if (txControlEmpty_i = '0') then
|
837 |
|
|
-- A control symbol has been received.
|
838 |
|
|
|
839 |
|
|
-- Check the received control symbol.
|
840 |
|
|
case txControlStype0 is
|
841 |
|
|
|
842 |
|
|
when STYPE0_STATUS =>
|
843 |
|
|
-- Save the number of buffers in the link partner.
|
844 |
|
|
bufferStatusNext <= txControlParameter1;
|
845 |
|
|
|
846 |
|
|
when STYPE0_PACKET_ACCEPTED =>
|
847 |
|
|
-- The link partner is accepting a frame.
|
848 |
|
|
|
849 |
|
|
-- Save the number of buffers in the link partner.
|
850 |
|
|
bufferStatusNext <= txControlParameter1;
|
851 |
|
|
|
852 |
|
|
-- Check if expecting this type of reply and that the ackId is
|
853 |
|
|
-- expected.
|
854 |
|
|
if ((ackIdCurrent /= ackIdWindowCurrent) and
|
855 |
|
|
(ackIdCurrent = unsigned(txControlParameter0))) then
|
856 |
|
|
-- The packet-accepted is expected and the ackId is the expected.
|
857 |
|
|
-- The frame has been accepted by the link partner.
|
858 |
|
|
|
859 |
|
|
-- Update to a new buffer and increment the ackId.
|
860 |
|
|
readFrame_o <= '1';
|
861 |
|
|
ackIdNext <= ackIdCurrent + 1;
|
862 |
|
|
else
|
863 |
|
|
-- Unexpected packet-accepted or packet-accepted for
|
864 |
|
|
-- unexpected ackId.
|
865 |
|
|
counterNext <= NUMBER_LINK_RESPONSE_RETRIES;
|
866 |
|
|
stateNext <= STATE_SEND_LINK_REQUEST;
|
867 |
|
|
end if;
|
868 |
|
|
|
869 |
|
|
when STYPE0_PACKET_RETRY =>
|
870 |
|
|
-- The link partner has asked for a frame retransmission.
|
871 |
|
|
|
872 |
|
|
-- Save the number of buffers in the link partner.
|
873 |
|
|
bufferStatusNext <= txControlParameter1;
|
874 |
|
|
|
875 |
|
|
-- Check if the ackId is the one expected.
|
876 |
|
|
if (ackIdCurrent = unsigned(txControlParameter0)) then
|
877 |
|
|
-- The ackId to retry is expected.
|
878 |
|
|
-- Go to the output-retry-stopped state.
|
879 |
|
|
stateNext <= STATE_OUTPUT_RETRY_STOPPED;
|
880 |
|
|
else
|
881 |
|
|
-- Unexpected ackId to retry.
|
882 |
|
|
counterNext <= NUMBER_LINK_RESPONSE_RETRIES;
|
883 |
|
|
stateNext <= STATE_SEND_LINK_REQUEST;
|
884 |
|
|
end if;
|
885 |
|
|
|
886 |
|
|
when STYPE0_PACKET_NOT_ACCEPTED =>
|
887 |
|
|
-- Packet was rejected by the link-partner.
|
888 |
|
|
-- REMARK: Indicate that this has happened to the outside...
|
889 |
|
|
counterNext <= NUMBER_LINK_RESPONSE_RETRIES;
|
890 |
|
|
stateNext <= STATE_SEND_LINK_REQUEST;
|
891 |
|
|
|
892 |
|
|
when STYPE0_LINK_RESPONSE =>
|
893 |
|
|
-- Dont expect or need a link-response in this state.
|
894 |
|
|
-- Discard it.
|
895 |
|
|
|
896 |
|
|
when STYPE0_VC_STATUS =>
|
897 |
|
|
-- Not supported.
|
898 |
|
|
-- Discard it.
|
899 |
|
|
|
900 |
|
|
when STYPE0_RESERVED =>
|
901 |
|
|
-- Not supported.
|
902 |
|
|
-- Discard it.
|
903 |
|
|
|
904 |
|
|
when STYPE0_IMPLEMENTATION_DEFINED =>
|
905 |
|
|
-- Not supported.
|
906 |
|
|
-- Discard it.
|
907 |
|
|
|
908 |
|
|
when others =>
|
909 |
|
|
null;
|
910 |
|
|
end case;
|
911 |
|
|
|
912 |
|
|
-- Indicate the control symbol has been processed.
|
913 |
|
|
txControlUpdate_o <= '1';
|
914 |
|
|
else
|
915 |
|
|
-- No control symbol has been received.
|
916 |
|
|
|
917 |
|
|
-- Check if the oldest frame timeout has expired.
|
918 |
|
|
if ((ackIdCurrent /= ackIdWindowCurrent) and
|
919 |
|
|
(timeoutExpired = '1')) then
|
920 |
|
|
-- There has been a timeout on a transmitted frame.
|
921 |
|
|
|
922 |
|
|
-- Send link-request.
|
923 |
|
|
counterNext <= NUMBER_LINK_RESPONSE_RETRIES;
|
924 |
|
|
stateNext <= STATE_SEND_LINK_REQUEST;
|
925 |
|
|
else
|
926 |
|
|
-- There has been no timeout.
|
927 |
|
|
|
928 |
|
|
-- Check if the outbound fifo needs new data.
|
929 |
|
|
if (txFull_i = '0') then
|
930 |
|
|
-- There is room available in the outbound FIFO.
|
931 |
|
|
|
932 |
|
|
-- Check if there are any events from the receiver.
|
933 |
|
|
if (rxControlEmpty_i = '0') then
|
934 |
|
|
-- A symbol from the receiver should be transmitted.
|
935 |
|
|
|
936 |
|
|
-- Send the receiver symbol and a NOP.
|
937 |
|
|
-- REMARK: Combine this symbol with an STYPE1 to more effectivly
|
938 |
|
|
-- utilize the link.
|
939 |
|
|
symbolWrite <= '1';
|
940 |
|
|
symbolType <= SYMBOL_CONTROL;
|
941 |
|
|
stype0 <= rxControlStype0;
|
942 |
|
|
parameter0 <= rxControlParameter0;
|
943 |
|
|
parameter1 <= rxControlParameter1;
|
944 |
|
|
stype1 <= STYPE1_NOP;
|
945 |
|
|
cmd <= "000";
|
946 |
|
|
|
947 |
|
|
-- Remove the symbol from the fifo.
|
948 |
|
|
rxControlUpdate_o <= '1';
|
949 |
|
|
|
950 |
|
|
-- Check if the transmitted symbol contains status about
|
951 |
|
|
-- available buffers.
|
952 |
|
|
if ((rxControlStype0 = STYPE0_PACKET_ACCEPTED) or
|
953 |
|
|
(rxControlStype0 = STYPE0_PACKET_RETRY)) then
|
954 |
|
|
-- A symbol containing the bufferStatus has been sent.
|
955 |
|
|
symbolsTransmittedNext <= 0;
|
956 |
|
|
else
|
957 |
|
|
-- A symbol not containing the bufferStatus has been sent.
|
958 |
|
|
-- REMARK: symbolsTransmitted might overflow...
|
959 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
960 |
|
|
end if;
|
961 |
|
|
else
|
962 |
|
|
-- No events from the receiver.
|
963 |
|
|
|
964 |
|
|
-- Check if a status symbol must be sent.
|
965 |
|
|
if (symbolsTransmittedCurrent = 255) then
|
966 |
|
|
-- A status symbol must be sent.
|
967 |
|
|
|
968 |
|
|
-- Reset the number of transmitted symbols between statuses.
|
969 |
|
|
symbolsTransmittedNext <= 0;
|
970 |
|
|
|
971 |
|
|
-- Send status.
|
972 |
|
|
symbolWrite <= '1';
|
973 |
|
|
symbolType <= SYMBOL_CONTROL;
|
974 |
|
|
stype0 <= STYPE0_STATUS;
|
975 |
|
|
parameter0 <= ackIdStatus_i;
|
976 |
|
|
parameter1 <= "11111";
|
977 |
|
|
stype1 <= STYPE1_NOP;
|
978 |
|
|
cmd <= "000";
|
979 |
|
|
else
|
980 |
|
|
-- A status symbol does not have to be sent.
|
981 |
|
|
|
982 |
|
|
-- Check if a frame transfer is in progress.
|
983 |
|
|
case frameStateCurrent is
|
984 |
|
|
|
985 |
|
|
when FRAME_START =>
|
986 |
|
|
---------------------------------------------------------------
|
987 |
|
|
-- No frame has been started.
|
988 |
|
|
---------------------------------------------------------------
|
989 |
|
|
|
990 |
|
|
-- Wait for a new frame to arrive from the frame buffer,
|
991 |
|
|
-- for new buffers to be available at the link-partner
|
992 |
|
|
-- and also check that a maximum 31 frames are outstanding.
|
993 |
|
|
if ((readWindowEmpty_i = '0') and (bufferStatusCurrent /= "00000") and
|
994 |
|
|
((ackIdWindowCurrent - ackIdCurrent) /= 31)) then
|
995 |
|
|
-- New data is available for transmission and there
|
996 |
|
|
-- is room to receive it at the other side.
|
997 |
|
|
|
998 |
|
|
-- Indicate that a control symbol has been sent to start the
|
999 |
|
|
-- transmission of the frame.
|
1000 |
|
|
frameStateNext <= FRAME_CHECK;
|
1001 |
|
|
|
1002 |
|
|
-- Update the output from the frame buffer to contain the
|
1003 |
|
|
-- data when it is read later.
|
1004 |
|
|
readContent_o <= '1';
|
1005 |
|
|
else
|
1006 |
|
|
-- There are no frame data to send or the link partner has
|
1007 |
|
|
-- no available buffers.
|
1008 |
|
|
|
1009 |
|
|
-- Send idle-sequence.
|
1010 |
|
|
symbolWrite <= '1';
|
1011 |
|
|
symbolType <= SYMBOL_IDLE;
|
1012 |
|
|
|
1013 |
|
|
-- A symbol not containing the buffer status has been sent.
|
1014 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
1015 |
|
|
end if;
|
1016 |
|
|
|
1017 |
|
|
when FRAME_CHECK =>
|
1018 |
|
|
-------------------------------------------------------
|
1019 |
|
|
-- Check if we are allowed to transmit this packet.
|
1020 |
|
|
-------------------------------------------------------
|
1021 |
|
|
|
1022 |
|
|
-- Check if this packet is allowed to be transmitted.
|
1023 |
|
|
if ((portEnable_i = '1') or (readContentData_i(19 downto 16) = FTYPE_MAINTENANCE_CLASS)) then
|
1024 |
|
|
-- The packet may be transmitted.
|
1025 |
|
|
|
1026 |
|
|
-- Indicate that a control symbol has been sent to start the
|
1027 |
|
|
-- transmission of the frame.
|
1028 |
|
|
frameStateNext <= FRAME_ACKID;
|
1029 |
|
|
|
1030 |
|
|
-- Send a control symbol to start the packet and a status to complete
|
1031 |
|
|
-- the symbol.
|
1032 |
|
|
symbolWrite <= '1';
|
1033 |
|
|
symbolType <= SYMBOL_CONTROL;
|
1034 |
|
|
stype0 <= STYPE0_STATUS;
|
1035 |
|
|
parameter0 <= ackIdStatus_i;
|
1036 |
|
|
parameter1 <= "11111";
|
1037 |
|
|
stype1 <= STYPE1_START_OF_PACKET;
|
1038 |
|
|
cmd <= "000";
|
1039 |
|
|
|
1040 |
|
|
-- A symbol containing the bufferStatus has been sent.
|
1041 |
|
|
symbolsTransmittedNext <= 0;
|
1042 |
|
|
else
|
1043 |
|
|
-- The packet should be discarded.
|
1044 |
|
|
|
1045 |
|
|
-- Check that there are no outstanding packets that
|
1046 |
|
|
-- has not been acknowledged.
|
1047 |
|
|
if(ackIdWindowCurrent /= ackIdCurrent) then
|
1048 |
|
|
-- There are packets that has not been acknowledged.
|
1049 |
|
|
|
1050 |
|
|
-- Send idle-sequence.
|
1051 |
|
|
symbolWrite <= '1';
|
1052 |
|
|
symbolType <= SYMBOL_IDLE;
|
1053 |
|
|
|
1054 |
|
|
-- A symbol not containing the buffer status has been sent.
|
1055 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
1056 |
|
|
else
|
1057 |
|
|
-- No unacknowledged packets.
|
1058 |
|
|
-- It is now safe to remove the unallowed frame.
|
1059 |
|
|
readFrame_o <= '1';
|
1060 |
|
|
|
1061 |
|
|
-- Go back and send a new frame.
|
1062 |
|
|
frameStateNext <= FRAME_START;
|
1063 |
|
|
end if;
|
1064 |
|
|
end if;
|
1065 |
|
|
|
1066 |
|
|
when FRAME_ACKID =>
|
1067 |
|
|
---------------------------------------------------------------
|
1068 |
|
|
-- Send the first packet content containing our current
|
1069 |
|
|
-- ackId.
|
1070 |
|
|
---------------------------------------------------------------
|
1071 |
|
|
|
1072 |
|
|
-- Write a new data symbol and fill in our ackId on the
|
1073 |
|
|
-- packet.
|
1074 |
|
|
symbolWrite <= '1';
|
1075 |
|
|
symbolType <= SYMBOL_DATA;
|
1076 |
|
|
symbolData <= std_logic_vector(ackIdWindowCurrent) & "0" & readContentData_i(25 downto 0);
|
1077 |
|
|
|
1078 |
|
|
-- Continue to send the rest of the body of the packet.
|
1079 |
|
|
readContent_o <= '1';
|
1080 |
|
|
frameStateNext <= FRAME_BODY;
|
1081 |
|
|
|
1082 |
|
|
-- A symbol not containing the buffer status has been sent.
|
1083 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
1084 |
|
|
|
1085 |
|
|
when FRAME_BODY =>
|
1086 |
|
|
---------------------------------------------------------------
|
1087 |
|
|
-- The frame has not been fully sent.
|
1088 |
|
|
-- Send a data symbol.
|
1089 |
|
|
---------------------------------------------------------------
|
1090 |
|
|
-- REMARK: Add support for partial frames...
|
1091 |
|
|
|
1092 |
|
|
-- Check if the frame is ending.
|
1093 |
|
|
if (readContentEnd_i = '0') then
|
1094 |
|
|
-- The frame is not ending.
|
1095 |
|
|
|
1096 |
|
|
-- Write a new data symbol.
|
1097 |
|
|
symbolWrite <= '1';
|
1098 |
|
|
symbolType <= SYMBOL_DATA;
|
1099 |
|
|
symbolData <= readContentData_i;
|
1100 |
|
|
|
1101 |
|
|
-- Continue to send the rest of the body of the packet.
|
1102 |
|
|
readContent_o <= '1';
|
1103 |
|
|
|
1104 |
|
|
-- A symbol not containing the buffer status has been sent.
|
1105 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
1106 |
|
|
else
|
1107 |
|
|
-- The frame is ending.
|
1108 |
|
|
|
1109 |
|
|
-- Update the window to the next frame.
|
1110 |
|
|
-- It takes one tick for the output from the frame
|
1111 |
|
|
-- buffer to get updated.
|
1112 |
|
|
readWindowNext_o <= '1';
|
1113 |
|
|
|
1114 |
|
|
-- Proceed to check if there is another frame to start
|
1115 |
|
|
-- with directly.
|
1116 |
|
|
frameStateNext <= FRAME_END;
|
1117 |
|
|
end if;
|
1118 |
|
|
|
1119 |
|
|
when FRAME_END =>
|
1120 |
|
|
---------------------------------------------------------------
|
1121 |
|
|
-- A frame has ended and the window has been updated.
|
1122 |
|
|
-- Check if the next symbol should end the frame or if a
|
1123 |
|
|
-- new one should be started.
|
1124 |
|
|
---------------------------------------------------------------
|
1125 |
|
|
|
1126 |
|
|
-- Check if there is a new frame pending.
|
1127 |
|
|
if (readWindowEmpty_i = '1') then
|
1128 |
|
|
-- No new frame is pending.
|
1129 |
|
|
|
1130 |
|
|
-- Send a control symbol to end the packet.
|
1131 |
|
|
symbolWrite <= '1';
|
1132 |
|
|
symbolType <= SYMBOL_CONTROL;
|
1133 |
|
|
stype0 <= STYPE0_STATUS;
|
1134 |
|
|
parameter0 <= ackIdStatus_i;
|
1135 |
|
|
parameter1 <= "11111";
|
1136 |
|
|
stype1 <= STYPE1_END_OF_PACKET;
|
1137 |
|
|
cmd <= "000";
|
1138 |
|
|
|
1139 |
|
|
-- A symbol containing the bufferStatus has been sent.
|
1140 |
|
|
symbolsTransmittedNext <= 0;
|
1141 |
|
|
end if;
|
1142 |
|
|
|
1143 |
|
|
-- Update the window ackId.
|
1144 |
|
|
ackIdWindowNext <= ackIdWindowCurrent + 1;
|
1145 |
|
|
|
1146 |
|
|
-- Start timeout supervision for transmitted frame.
|
1147 |
|
|
timeoutWrite <= '1';
|
1148 |
|
|
timeoutAddress <= std_logic_vector(ackIdWindowCurrent);
|
1149 |
|
|
|
1150 |
|
|
-- Start a new frame the next time.
|
1151 |
|
|
frameStateNext <= FRAME_START;
|
1152 |
|
|
|
1153 |
|
|
when others =>
|
1154 |
|
|
---------------------------------------------------------------
|
1155 |
|
|
--
|
1156 |
|
|
---------------------------------------------------------------
|
1157 |
|
|
null;
|
1158 |
|
|
|
1159 |
|
|
end case;
|
1160 |
|
|
end if;
|
1161 |
|
|
end if;
|
1162 |
|
|
else
|
1163 |
|
|
-- Wait for new storage in the transmission FIFO to become
|
1164 |
|
|
-- available.
|
1165 |
|
|
-- Dont do anything.
|
1166 |
|
|
end if;
|
1167 |
|
|
end if;
|
1168 |
|
|
end if;
|
1169 |
|
|
else
|
1170 |
|
|
-- The port or the link has become uninitialized.
|
1171 |
|
|
-- Go back to the uninitialized state.
|
1172 |
|
|
stateNext <= STATE_UNINITIALIZED;
|
1173 |
|
|
end if;
|
1174 |
|
|
|
1175 |
|
|
when STATE_OUTPUT_RETRY_STOPPED =>
|
1176 |
|
|
-----------------------------------------------------------------------
|
1177 |
|
|
-- This is the output-retry-stopped state described in 5.9.1.5.
|
1178 |
|
|
-----------------------------------------------------------------------
|
1179 |
|
|
|
1180 |
|
|
-- Check if the outbound fifo needs new data.
|
1181 |
|
|
if (txFull_i = '0') then
|
1182 |
|
|
-- There is room available in the outbound FIFO.
|
1183 |
|
|
|
1184 |
|
|
-- Send a restart-from-retry control symbol to acknowledge the restart
|
1185 |
|
|
-- of the frame.
|
1186 |
|
|
symbolWrite <= '1';
|
1187 |
|
|
symbolType <= SYMBOL_CONTROL;
|
1188 |
|
|
stype0 <= STYPE0_STATUS;
|
1189 |
|
|
parameter0 <= ackIdStatus_i;
|
1190 |
|
|
parameter1 <= "11111";
|
1191 |
|
|
stype1 <= STYPE1_RESTART_FROM_RETRY;
|
1192 |
|
|
cmd <= "000";
|
1193 |
|
|
|
1194 |
|
|
-- Make sure there wont be any timeout before the frame is
|
1195 |
|
|
-- starting to be retransmitted.
|
1196 |
|
|
timeoutWrite <= '1';
|
1197 |
|
|
timeoutAddress <= std_logic_vector(ackIdCurrent);
|
1198 |
|
|
|
1199 |
|
|
-- Restart the frame transmission.
|
1200 |
|
|
ackIdWindowNext <= ackIdCurrent;
|
1201 |
|
|
frameStateNext <= FRAME_START;
|
1202 |
|
|
readWindowReset_o <= '1';
|
1203 |
|
|
|
1204 |
|
|
-- Proceed back to the normal state.
|
1205 |
|
|
stateNext <= STATE_NORMAL;
|
1206 |
|
|
|
1207 |
|
|
-- A symbol containing the bufferStatus has been sent.
|
1208 |
|
|
symbolsTransmittedNext <= 0;
|
1209 |
|
|
end if;
|
1210 |
|
|
|
1211 |
|
|
when STATE_SEND_LINK_REQUEST =>
|
1212 |
|
|
-----------------------------------------------------------------------
|
1213 |
|
|
-- Send a link-request symbol when the transmission fifo is ready. Then
|
1214 |
|
|
-- always proceed to the output-error-state.
|
1215 |
|
|
-----------------------------------------------------------------------
|
1216 |
|
|
|
1217 |
|
|
-- Check if the outbound fifo needs new data.
|
1218 |
|
|
if (txFull_i = '0') then
|
1219 |
|
|
-- There is room available in the outbound FIFO.
|
1220 |
|
|
|
1221 |
|
|
-- Send a link-request symbol.
|
1222 |
|
|
symbolWrite <= '1';
|
1223 |
|
|
symbolType <= SYMBOL_CONTROL;
|
1224 |
|
|
stype0 <= STYPE0_STATUS;
|
1225 |
|
|
parameter0 <= ackIdStatus_i;
|
1226 |
|
|
parameter1 <= "11111";
|
1227 |
|
|
stype1 <= STYPE1_LINK_REQUEST;
|
1228 |
|
|
cmd <= LINK_REQUEST_CMD_INPUT_STATUS;
|
1229 |
|
|
|
1230 |
|
|
-- Write the current timer value.
|
1231 |
|
|
timeoutWrite <= '1';
|
1232 |
|
|
timeoutAddress <= std_logic_vector(ackIdCurrent);
|
1233 |
|
|
|
1234 |
|
|
-- Proceed to the output-error-stopped state.
|
1235 |
|
|
stateNext <= STATE_OUTPUT_ERROR_STOPPED;
|
1236 |
|
|
|
1237 |
|
|
-- A symbol containing the bufferStatus has been sent.
|
1238 |
|
|
symbolsTransmittedNext <= 0;
|
1239 |
|
|
end if;
|
1240 |
|
|
|
1241 |
|
|
when STATE_OUTPUT_ERROR_STOPPED =>
|
1242 |
|
|
-------------------------------------------------------------------
|
1243 |
|
|
-- This state is the error stopped state described in 5.13.2.7.
|
1244 |
|
|
-------------------------------------------------------------------
|
1245 |
|
|
|
1246 |
|
|
-- Check that both the port and link is initialized.
|
1247 |
|
|
if (portInitialized_i = '1') and (linkInitialized_i = '1') then
|
1248 |
|
|
-- The port and link is initialized.
|
1249 |
|
|
|
1250 |
|
|
-- Check if any control symbol has been received from the link
|
1251 |
|
|
-- partner.
|
1252 |
|
|
if (txControlEmpty_i = '0') then
|
1253 |
|
|
-- A control symbol has been received.
|
1254 |
|
|
|
1255 |
|
|
-- Check the received control symbol.
|
1256 |
|
|
case txControlStype0 is
|
1257 |
|
|
|
1258 |
|
|
when STYPE0_PACKET_ACCEPTED =>
|
1259 |
|
|
-- Wait for a link-response.
|
1260 |
|
|
-- Discard these.
|
1261 |
|
|
|
1262 |
|
|
when STYPE0_PACKET_RETRY =>
|
1263 |
|
|
-- Wait for a link-response.
|
1264 |
|
|
-- Discard these.
|
1265 |
|
|
|
1266 |
|
|
when STYPE0_PACKET_NOT_ACCEPTED =>
|
1267 |
|
|
-- Wait for a link-response.
|
1268 |
|
|
-- Discard these.
|
1269 |
|
|
|
1270 |
|
|
when STYPE0_STATUS =>
|
1271 |
|
|
-- Wait for a link-response.
|
1272 |
|
|
-- Discard these.
|
1273 |
|
|
|
1274 |
|
|
when STYPE0_LINK_RESPONSE =>
|
1275 |
|
|
-- Check if the link partner return value is acceptable.
|
1276 |
|
|
if ((unsigned(txControlParameter0) - ackIdCurrent) <=
|
1277 |
|
|
(ackIdWindowCurrent - ackIdCurrent)) then
|
1278 |
|
|
-- Recoverable error.
|
1279 |
|
|
-- Use the received ackId and recover by removing packets
|
1280 |
|
|
-- that were received by the link-partner.
|
1281 |
|
|
ackIdWindowNext <= unsigned(txControlParameter0);
|
1282 |
|
|
stateNext <= STATE_RECOVER;
|
1283 |
|
|
else
|
1284 |
|
|
-- Totally out of sync.
|
1285 |
|
|
stateNext <= STATE_FATAL_ERROR;
|
1286 |
|
|
end if;
|
1287 |
|
|
|
1288 |
|
|
when STYPE0_VC_STATUS =>
|
1289 |
|
|
-- Not supported.
|
1290 |
|
|
|
1291 |
|
|
when STYPE0_RESERVED =>
|
1292 |
|
|
-- Not supported.
|
1293 |
|
|
|
1294 |
|
|
when STYPE0_IMPLEMENTATION_DEFINED =>
|
1295 |
|
|
-- Not supported.
|
1296 |
|
|
|
1297 |
|
|
when others =>
|
1298 |
|
|
null;
|
1299 |
|
|
end case;
|
1300 |
|
|
|
1301 |
|
|
-- Indicate the control symbol has been processed.
|
1302 |
|
|
txControlUpdate_o <= '1';
|
1303 |
|
|
else
|
1304 |
|
|
-- No control symbol has been received.
|
1305 |
|
|
|
1306 |
|
|
-- Check if the timeout for a link-response has expired.
|
1307 |
|
|
if (timeoutExpired = '1') then
|
1308 |
|
|
-- There was no reply on the link-request.
|
1309 |
|
|
|
1310 |
|
|
-- Count the number of retransmissions and abort if
|
1311 |
|
|
-- no reply has been received for too many times.
|
1312 |
|
|
if (counterCurrent /= 0) then
|
1313 |
|
|
-- Not sent link-request too many times.
|
1314 |
|
|
|
1315 |
|
|
-- Send another link-request.
|
1316 |
|
|
counterNext <= counterCurrent - 1;
|
1317 |
|
|
stateNext <= STATE_SEND_LINK_REQUEST;
|
1318 |
|
|
else
|
1319 |
|
|
-- No response for too many times.
|
1320 |
|
|
stateNext <= STATE_FATAL_ERROR;
|
1321 |
|
|
end if;
|
1322 |
|
|
else
|
1323 |
|
|
-- There has been no timeout.
|
1324 |
|
|
|
1325 |
|
|
-- Check if the outbound fifo needs new data.
|
1326 |
|
|
if (txFull_i = '0') then
|
1327 |
|
|
-- There is room available in the outbound FIFO.
|
1328 |
|
|
|
1329 |
|
|
-- Check if there are any events from the receiver.
|
1330 |
|
|
if (rxControlEmpty_i = '0') then
|
1331 |
|
|
-- A symbol from the receiver should be transmitted.
|
1332 |
|
|
|
1333 |
|
|
-- Send the receiver symbol and a NOP.
|
1334 |
|
|
symbolWrite <= '1';
|
1335 |
|
|
symbolType <= SYMBOL_CONTROL;
|
1336 |
|
|
stype0 <= rxControlStype0;
|
1337 |
|
|
parameter0 <= rxControlParameter0;
|
1338 |
|
|
parameter1 <= rxControlParameter1;
|
1339 |
|
|
stype1 <= STYPE1_NOP;
|
1340 |
|
|
cmd <= "000";
|
1341 |
|
|
|
1342 |
|
|
-- Remove the symbol from the fifo.
|
1343 |
|
|
rxControlUpdate_o <= '1';
|
1344 |
|
|
|
1345 |
|
|
-- Check if the transmitted symbol contains status about
|
1346 |
|
|
-- available buffers.
|
1347 |
|
|
-- The receiver never send any status so that does not have
|
1348 |
|
|
-- to be checked.
|
1349 |
|
|
if ((rxControlStype0 = STYPE0_PACKET_ACCEPTED) or
|
1350 |
|
|
(rxControlStype0 = STYPE0_PACKET_RETRY)) then
|
1351 |
|
|
-- A symbol containing the bufferStatus has been sent.
|
1352 |
|
|
symbolsTransmittedNext <= 0;
|
1353 |
|
|
else
|
1354 |
|
|
-- A symbol not containing the buffer status has been sent.
|
1355 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
1356 |
|
|
end if;
|
1357 |
|
|
else
|
1358 |
|
|
-- No events from the receiver.
|
1359 |
|
|
-- There are no frame data to send or the link partner has
|
1360 |
|
|
-- no available buffers.
|
1361 |
|
|
|
1362 |
|
|
-- Check if a status symbol must be sent.
|
1363 |
|
|
if (symbolsTransmittedCurrent = 255) then
|
1364 |
|
|
-- A status symbol must be sent.
|
1365 |
|
|
|
1366 |
|
|
-- Reset the number of transmitted symbols between statuses.
|
1367 |
|
|
symbolsTransmittedNext <= 0;
|
1368 |
|
|
|
1369 |
|
|
-- Send status.
|
1370 |
|
|
symbolWrite <= '1';
|
1371 |
|
|
symbolType <= SYMBOL_CONTROL;
|
1372 |
|
|
stype0 <= STYPE0_STATUS;
|
1373 |
|
|
parameter0 <= ackIdStatus_i;
|
1374 |
|
|
parameter1 <= "11111";
|
1375 |
|
|
stype1 <= STYPE1_NOP;
|
1376 |
|
|
cmd <= "000";
|
1377 |
|
|
else
|
1378 |
|
|
-- A status symbol does not have to be sent.
|
1379 |
|
|
|
1380 |
|
|
-- Send idle-sequence.
|
1381 |
|
|
symbolWrite <= '1';
|
1382 |
|
|
symbolType <= SYMBOL_IDLE;
|
1383 |
|
|
|
1384 |
|
|
-- A symbol not containing the buffer status has been sent.
|
1385 |
|
|
symbolsTransmittedNext <= symbolsTransmittedCurrent + 1;
|
1386 |
|
|
end if;
|
1387 |
|
|
end if;
|
1388 |
|
|
else
|
1389 |
|
|
-- Wait for new storage in the transmission FIFO to become
|
1390 |
|
|
-- available.
|
1391 |
|
|
-- Dont do anything.
|
1392 |
|
|
end if;
|
1393 |
|
|
end if;
|
1394 |
|
|
end if;
|
1395 |
|
|
else
|
1396 |
|
|
-- The port or the link has become uninitialized.
|
1397 |
|
|
-- Go back to the uninitialized state.
|
1398 |
|
|
stateNext <= STATE_UNINITIALIZED;
|
1399 |
|
|
end if;
|
1400 |
|
|
|
1401 |
|
|
when STATE_RECOVER =>
|
1402 |
|
|
-----------------------------------------------------------------------
|
1403 |
|
|
-- A recoverable error condition has occurred.
|
1404 |
|
|
-- When this state is entered, ackIdWindow should contain the ackId to
|
1405 |
|
|
-- proceed with.
|
1406 |
|
|
-----------------------------------------------------------------------
|
1407 |
|
|
|
1408 |
|
|
-- Check if the expected ackId has incremented enough.
|
1409 |
|
|
if (ackIdCurrent /= ackIdWindowCurrent) then
|
1410 |
|
|
-- Remove this frame. It has been received by the link-partner.
|
1411 |
|
|
readFrame_o <= '1';
|
1412 |
|
|
ackIdNext <= ackIdCurrent + 1;
|
1413 |
|
|
else
|
1414 |
|
|
-- Keep this frame.
|
1415 |
|
|
-- Restart the window and the frame transmission.
|
1416 |
|
|
frameStateNext <= FRAME_START;
|
1417 |
|
|
readWindowReset_o <= '1';
|
1418 |
|
|
stateNext <= STATE_NORMAL;
|
1419 |
|
|
end if;
|
1420 |
|
|
|
1421 |
|
|
when STATE_FATAL_ERROR =>
|
1422 |
|
|
-----------------------------------------------------------------------
|
1423 |
|
|
-- A fatal error condition has occurred.
|
1424 |
|
|
-----------------------------------------------------------------------
|
1425 |
|
|
|
1426 |
|
|
-- Reset the window and resynchronize the link.
|
1427 |
|
|
-- REMARK: Count these situations...
|
1428 |
|
|
-- REMARK: Do something else here???
|
1429 |
|
|
readWindowReset_o <= '1';
|
1430 |
|
|
stateNext <= STATE_UNINITIALIZED;
|
1431 |
|
|
|
1432 |
|
|
when others =>
|
1433 |
|
|
-------------------------------------------------------------------
|
1434 |
|
|
--
|
1435 |
|
|
-------------------------------------------------------------------
|
1436 |
|
|
null;
|
1437 |
|
|
end case;
|
1438 |
|
|
end if;
|
1439 |
|
|
end process;
|
1440 |
|
|
|
1441 |
|
|
end architecture;
|
1442 |
|
|
|
1443 |
|
|
|
1444 |
|
|
|
1445 |
|
|
-------------------------------------------------------------------------------
|
1446 |
|
|
--
|
1447 |
|
|
-------------------------------------------------------------------------------
|
1448 |
|
|
library ieee;
|
1449 |
|
|
use ieee.std_logic_1164.all;
|
1450 |
|
|
use ieee.numeric_std.all;
|
1451 |
|
|
use work.rio_common.all;
|
1452 |
|
|
|
1453 |
|
|
|
1454 |
|
|
-------------------------------------------------------------------------------
|
1455 |
|
|
--
|
1456 |
|
|
-------------------------------------------------------------------------------
|
1457 |
|
|
entity RioReceiver is
|
1458 |
|
|
port(
|
1459 |
|
|
clk : in std_logic;
|
1460 |
|
|
areset_n : in std_logic;
|
1461 |
|
|
|
1462 |
|
|
-- Status signals used for maintenance.
|
1463 |
|
|
portEnable_i : in std_logic;
|
1464 |
|
|
|
1465 |
|
|
-- Support for localAckIdCSR.
|
1466 |
|
|
localAckIdWrite_i : in std_logic;
|
1467 |
|
|
inboundAckId_i : in std_logic_vector(4 downto 0);
|
1468 |
|
|
inboundAckId_o : out std_logic_vector(4 downto 0);
|
1469 |
|
|
|
1470 |
|
|
-- Port input interface.
|
1471 |
|
|
portInitialized_i : in std_logic;
|
1472 |
|
|
rxEmpty_i : in std_logic;
|
1473 |
|
|
rxRead_o : out std_logic;
|
1474 |
|
|
rxControl_i : in std_logic_vector(1 downto 0);
|
1475 |
|
|
rxData_i : in std_logic_vector(31 downto 0);
|
1476 |
|
|
|
1477 |
|
|
-- Receiver has received a control symbol containing:
|
1478 |
|
|
-- packet-accepted, packet-retry, packet-not-accepted,
|
1479 |
|
|
-- status, VC_status, link-response
|
1480 |
|
|
txControlWrite_o : out std_logic;
|
1481 |
|
|
txControlSymbol_o : out std_logic_vector(12 downto 0);
|
1482 |
|
|
|
1483 |
|
|
-- Reciever wants to signal the link partner:
|
1484 |
|
|
-- a new frame has been accepted => packet-accepted(rxAckId, bufferStatus)
|
1485 |
|
|
-- a frame needs to be retransmitted due to buffering =>
|
1486 |
|
|
-- packet-retry(rxAckId, bufferStatus)
|
1487 |
|
|
-- a frame is rejected due to errors => packet-not-accepted
|
1488 |
|
|
-- a link-request should be answered => link-response
|
1489 |
|
|
rxControlWrite_o : out std_logic;
|
1490 |
|
|
rxControlSymbol_o : out std_logic_vector(12 downto 0);
|
1491 |
|
|
|
1492 |
|
|
-- Status signals used internally.
|
1493 |
|
|
ackIdStatus_o : out std_logic_vector(4 downto 0);
|
1494 |
|
|
linkInitialized_o : out std_logic;
|
1495 |
|
|
|
1496 |
|
|
-- Frame buffering interface.
|
1497 |
|
|
writeFrameFull_i : in std_logic;
|
1498 |
|
|
writeFrame_o : out std_logic;
|
1499 |
|
|
writeFrameAbort_o : out std_logic;
|
1500 |
|
|
writeContent_o : out std_logic;
|
1501 |
|
|
writeContentData_o : out std_logic_vector(31 downto 0));
|
1502 |
|
|
end entity;
|
1503 |
|
|
|
1504 |
|
|
|
1505 |
|
|
-------------------------------------------------------------------------------
|
1506 |
|
|
--
|
1507 |
|
|
-------------------------------------------------------------------------------
|
1508 |
|
|
architecture RioReceiverImpl of RioReceiver is
|
1509 |
|
|
|
1510 |
|
|
component Crc5ITU is
|
1511 |
|
|
port(
|
1512 |
|
|
d_i : in std_logic_vector(18 downto 0);
|
1513 |
|
|
crc_o : out std_logic_vector(4 downto 0));
|
1514 |
|
|
end component;
|
1515 |
|
|
|
1516 |
|
|
component Crc16CITT is
|
1517 |
|
|
port(
|
1518 |
|
|
d_i : in std_logic_vector(15 downto 0);
|
1519 |
|
|
crc_i : in std_logic_vector(15 downto 0);
|
1520 |
|
|
crc_o : out std_logic_vector(15 downto 0));
|
1521 |
|
|
end component;
|
1522 |
|
|
|
1523 |
|
|
type StateType is (STATE_UNINITIALIZED, STATE_PORT_INITIALIZED,
|
1524 |
|
|
STATE_NORMAL,
|
1525 |
|
|
STATE_INPUT_RETRY_STOPPED, STATE_INPUT_ERROR_STOPPED);
|
1526 |
|
|
signal state : StateType;
|
1527 |
|
|
|
1528 |
|
|
signal statusCounter : natural range 0 to 8;
|
1529 |
|
|
|
1530 |
|
|
signal ackId : unsigned(4 downto 0);
|
1531 |
|
|
signal frameIndex : natural range 0 to 70;
|
1532 |
|
|
|
1533 |
|
|
signal stype0 : std_logic_vector(2 downto 0);
|
1534 |
|
|
signal parameter0 : std_logic_vector(4 downto 0);
|
1535 |
|
|
signal parameter1 : std_logic_vector(4 downto 0);
|
1536 |
|
|
signal stype1 : std_logic_vector(2 downto 0);
|
1537 |
|
|
signal cmd : std_logic_vector(2 downto 0);
|
1538 |
|
|
|
1539 |
|
|
signal crc5 : std_logic_vector(4 downto 0);
|
1540 |
|
|
signal crc5Calculated : std_logic_vector(4 downto 0);
|
1541 |
|
|
|
1542 |
|
|
signal crc16Valid : std_logic;
|
1543 |
|
|
signal crc16Data : std_logic_vector(31 downto 0);
|
1544 |
|
|
signal crc16Current : std_logic_vector(15 downto 0);
|
1545 |
|
|
signal crc16Temp : std_logic_vector(15 downto 0);
|
1546 |
|
|
signal crc16Next : std_logic_vector(15 downto 0);
|
1547 |
|
|
|
1548 |
|
|
signal rxRead : std_logic;
|
1549 |
|
|
|
1550 |
|
|
begin
|
1551 |
|
|
|
1552 |
|
|
linkInitialized_o <= '0' when ((state = STATE_UNINITIALIZED) or
|
1553 |
|
|
(state = STATE_PORT_INITIALIZED)) else '1';
|
1554 |
|
|
ackIdStatus_o <= std_logic_vector(ackId);
|
1555 |
|
|
|
1556 |
|
|
-----------------------------------------------------------------------------
|
1557 |
|
|
-- Get the entries in a control symbol.
|
1558 |
|
|
-----------------------------------------------------------------------------
|
1559 |
|
|
|
1560 |
|
|
stype0 <= rxData_i(31 downto 29);
|
1561 |
|
|
parameter0 <= rxData_i(28 downto 24);
|
1562 |
|
|
parameter1 <= rxData_i(23 downto 19);
|
1563 |
|
|
stype1 <= rxData_i(18 downto 16);
|
1564 |
|
|
cmd <= rxData_i(15 downto 13);
|
1565 |
|
|
crc5 <= rxData_i(12 downto 8);
|
1566 |
|
|
|
1567 |
|
|
-----------------------------------------------------------------------------
|
1568 |
|
|
-- Entity for CRC-5 calculation on control symbols according to the standard.
|
1569 |
|
|
-----------------------------------------------------------------------------
|
1570 |
|
|
|
1571 |
|
|
Crc5Calculator: Crc5ITU
|
1572 |
|
|
port map(
|
1573 |
|
|
d_i=>rxData_i(31 downto 13), crc_o=>crc5Calculated);
|
1574 |
|
|
|
1575 |
|
|
-----------------------------------------------------------------------------
|
1576 |
|
|
-- Entities for CRC-16 calculation on 32-bit data in frames according to the
|
1577 |
|
|
-- standard.
|
1578 |
|
|
-----------------------------------------------------------------------------
|
1579 |
|
|
|
1580 |
|
|
-- If the CRC is correct, there is either zero in crc16Next if no pad exists
|
1581 |
|
|
-- or zero in crc16Temp and crc16Data(15 downto 0). This means that crc16Next
|
1582 |
|
|
-- will always be zero here if the CRC is correct.
|
1583 |
|
|
crc16Valid <= '1' when (crc16Next = x"0000") else '0';
|
1584 |
|
|
|
1585 |
|
|
Crc16High: Crc16CITT
|
1586 |
|
|
port map(
|
1587 |
|
|
d_i=>crc16Data(31 downto 16), crc_i=>crc16Current, crc_o=>crc16Temp);
|
1588 |
|
|
Crc16Low: Crc16CITT
|
1589 |
|
|
port map(
|
1590 |
|
|
d_i=>crc16Data(15 downto 0), crc_i=>crc16Temp, crc_o=>crc16Next);
|
1591 |
|
|
|
1592 |
|
|
-----------------------------------------------------------------------------
|
1593 |
|
|
-- Main inbound symbol handler.
|
1594 |
|
|
-----------------------------------------------------------------------------
|
1595 |
|
|
rxRead_o <= rxRead;
|
1596 |
|
|
inboundAckId_o <= std_logic_vector(ackId);
|
1597 |
|
|
process(areset_n, clk)
|
1598 |
|
|
begin
|
1599 |
|
|
if (areset_n = '0') then
|
1600 |
|
|
state <= STATE_UNINITIALIZED;
|
1601 |
|
|
|
1602 |
|
|
rxRead <= '0';
|
1603 |
|
|
txControlWrite_o <= '0';
|
1604 |
|
|
txControlSymbol_o <= (others => '0');
|
1605 |
|
|
rxControlWrite_o <= '0';
|
1606 |
|
|
rxControlSymbol_o <= (others => '0');
|
1607 |
|
|
|
1608 |
|
|
writeFrame_o <= '0';
|
1609 |
|
|
writeFrameAbort_o <= '0';
|
1610 |
|
|
writeContent_o <= '0';
|
1611 |
|
|
writeContentData_o <= (others => '0');
|
1612 |
|
|
|
1613 |
|
|
-- REMARK: Use frameIndex instead of this...
|
1614 |
|
|
statusCounter <= 0;
|
1615 |
|
|
|
1616 |
|
|
frameIndex <= 0;
|
1617 |
|
|
ackId <= (others => '0');
|
1618 |
|
|
|
1619 |
|
|
crc16Current <= (others => '0');
|
1620 |
|
|
crc16Data <= (others => '0');
|
1621 |
|
|
elsif (clk'event and clk = '1') then
|
1622 |
|
|
rxRead <= '0';
|
1623 |
|
|
|
1624 |
|
|
txControlWrite_o <= '0';
|
1625 |
|
|
rxControlWrite_o <= '0';
|
1626 |
|
|
|
1627 |
|
|
writeFrame_o <= '0';
|
1628 |
|
|
writeFrameAbort_o <= '0';
|
1629 |
|
|
writeContent_o <= '0';
|
1630 |
|
|
|
1631 |
|
|
-- Check if a locakAckIdWrite is active.
|
1632 |
|
|
if (localAckIdWrite_i = '1') then
|
1633 |
|
|
-- A localAckIdWrite is active.
|
1634 |
|
|
-- Set ackId.
|
1635 |
|
|
ackId <= unsigned(inboundAckId_i);
|
1636 |
|
|
else
|
1637 |
|
|
-- A localAckIdWrite is not active.
|
1638 |
|
|
|
1639 |
|
|
-- Act on the current state.
|
1640 |
|
|
case state is
|
1641 |
|
|
|
1642 |
|
|
when STATE_UNINITIALIZED =>
|
1643 |
|
|
-----------------------------------------------------------------------
|
1644 |
|
|
-- This state is entered at startup. A port that is not initialized
|
1645 |
|
|
-- should discard all received symbols.
|
1646 |
|
|
-----------------------------------------------------------------------
|
1647 |
|
|
|
1648 |
|
|
-- Check if the port is initialized.
|
1649 |
|
|
if (portInitialized_i = '0') then
|
1650 |
|
|
-- Port not initialized.
|
1651 |
|
|
|
1652 |
|
|
-- Check if a new symbol is ready to be read.
|
1653 |
|
|
if (rxRead = '0') and (rxEmpty_i = '0') then
|
1654 |
|
|
-- New symbol ready.
|
1655 |
|
|
-- Discard all received symbols in this state.
|
1656 |
|
|
rxRead <= '1';
|
1657 |
|
|
else
|
1658 |
|
|
-- No new symbol ready to be read.
|
1659 |
|
|
-- Dont do anything.
|
1660 |
|
|
end if;
|
1661 |
|
|
else
|
1662 |
|
|
-- Port is initialized.
|
1663 |
|
|
|
1664 |
|
|
-- Go to the initialized state and reset the counters.
|
1665 |
|
|
state <= STATE_PORT_INITIALIZED;
|
1666 |
|
|
statusCounter <= 0;
|
1667 |
|
|
end if;
|
1668 |
|
|
|
1669 |
|
|
when STATE_PORT_INITIALIZED =>
|
1670 |
|
|
---------------------------------------------------------------------
|
1671 |
|
|
-- The port has been initialized and status control symbols are being
|
1672 |
|
|
-- received on the link to check if it is working. Count the number
|
1673 |
|
|
-- of error-free status symbols and considder the link initialized
|
1674 |
|
|
-- when enough of them has been received. Frames are not allowed
|
1675 |
|
|
-- here.
|
1676 |
|
|
---------------------------------------------------------------------
|
1677 |
|
|
|
1678 |
|
|
-- Check if the port is initialized.
|
1679 |
|
|
if (portInitialized_i = '1') then
|
1680 |
|
|
-- Port is initialized.
|
1681 |
|
|
|
1682 |
|
|
-- Check if a new symbol is ready to be read.
|
1683 |
|
|
if (rxRead = '0') and (rxEmpty_i = '0') then
|
1684 |
|
|
-- There is a new symbol to read.
|
1685 |
|
|
|
1686 |
|
|
-- Check the type of symbol.
|
1687 |
|
|
if (rxControl_i = SYMBOL_CONTROL) then
|
1688 |
|
|
-- This is a control symbol that is not a packet delimiter.
|
1689 |
|
|
|
1690 |
|
|
-- Check if the control symbol has a valid checksum.
|
1691 |
|
|
if (crc5Calculated = crc5) then
|
1692 |
|
|
-- The control symbol has a valid checksum.
|
1693 |
|
|
|
1694 |
|
|
-- Forward the stype0 part of the symbol to the transmitter.
|
1695 |
|
|
txControlWrite_o <= '1';
|
1696 |
|
|
txControlSymbol_o <= stype0 & parameter0 & parameter1;
|
1697 |
|
|
|
1698 |
|
|
-- Check the stype0 part if we should count the number of
|
1699 |
|
|
-- error-free status symbols.
|
1700 |
|
|
if (stype0 = STYPE0_STATUS) then
|
1701 |
|
|
-- The symbol is a status.
|
1702 |
|
|
|
1703 |
|
|
-- Check if enough status symbols have been received.
|
1704 |
|
|
if (statusCounter = 7) then
|
1705 |
|
|
-- Enough status symbols have been received.
|
1706 |
|
|
|
1707 |
|
|
-- Reset all packets.
|
1708 |
|
|
frameIndex <= 0;
|
1709 |
|
|
writeFrameAbort_o <= '1';
|
1710 |
|
|
|
1711 |
|
|
-- Set the link as initialized.
|
1712 |
|
|
state <= STATE_NORMAL;
|
1713 |
|
|
else
|
1714 |
|
|
-- Increase the number of error-free status symbols that
|
1715 |
|
|
-- has been received.
|
1716 |
|
|
statusCounter <= statusCounter + 1;
|
1717 |
|
|
end if;
|
1718 |
|
|
else
|
1719 |
|
|
-- The symbol is not a status.
|
1720 |
|
|
-- Dont do anything.
|
1721 |
|
|
end if;
|
1722 |
|
|
else
|
1723 |
|
|
-- A control symbol with CRC5 error was recevied.
|
1724 |
|
|
statusCounter <= 0;
|
1725 |
|
|
end if;
|
1726 |
|
|
else
|
1727 |
|
|
-- Symbol that is not allowed in this state have been received.
|
1728 |
|
|
-- Discard it.
|
1729 |
|
|
end if;
|
1730 |
|
|
|
1731 |
|
|
-- Update to the next symbol.
|
1732 |
|
|
rxRead <= '1';
|
1733 |
|
|
else
|
1734 |
|
|
-- No new symbol ready to be read.
|
1735 |
|
|
-- Dont do anything.
|
1736 |
|
|
end if;
|
1737 |
|
|
else
|
1738 |
|
|
-- Go back to the uninitialized state.
|
1739 |
|
|
state <= STATE_UNINITIALIZED;
|
1740 |
|
|
end if;
|
1741 |
|
|
|
1742 |
|
|
when STATE_NORMAL =>
|
1743 |
|
|
---------------------------------------------------------------------
|
1744 |
|
|
-- The port has been initialized and enough error free status symbols
|
1745 |
|
|
-- have been received. Forward data frames to the frame buffer
|
1746 |
|
|
-- interface. This is the normal operational state.
|
1747 |
|
|
---------------------------------------------------------------------
|
1748 |
|
|
|
1749 |
|
|
-- Check that the port is initialized.
|
1750 |
|
|
if (portInitialized_i = '1') then
|
1751 |
|
|
-- The port and link is initialized.
|
1752 |
|
|
|
1753 |
|
|
-- Check if a new symbol is ready to be read.
|
1754 |
|
|
if (rxRead = '0') and (rxEmpty_i = '0') then
|
1755 |
|
|
-- There is a new symbol to read.
|
1756 |
|
|
|
1757 |
|
|
-- Check the type of symbol.
|
1758 |
|
|
if (rxControl_i = SYMBOL_CONTROL) then
|
1759 |
|
|
-- This is a control symbol with or without a packet delimiter.
|
1760 |
|
|
|
1761 |
|
|
-- Check if the control symbol has a valid CRC-5.
|
1762 |
|
|
if (crc5Calculated = crc5) then
|
1763 |
|
|
-- The control symbol is correct.
|
1764 |
|
|
|
1765 |
|
|
-- Forward the stype0 part of the symbol to the transmitter.
|
1766 |
|
|
txControlWrite_o <= '1';
|
1767 |
|
|
txControlSymbol_o <= stype0 & parameter0 & parameter1;
|
1768 |
|
|
|
1769 |
|
|
-- Check the stype1 part.
|
1770 |
|
|
case stype1 is
|
1771 |
|
|
|
1772 |
|
|
when STYPE1_START_OF_PACKET =>
|
1773 |
|
|
-------------------------------------------------------------
|
1774 |
|
|
-- Start the reception of a new frame or end a currently
|
1775 |
|
|
-- ongoing frame.
|
1776 |
|
|
-------------------------------------------------------------
|
1777 |
|
|
|
1778 |
|
|
-- Check if a frame has already been started.
|
1779 |
|
|
if (frameIndex /= 0) then
|
1780 |
|
|
-- A frame is already started.
|
1781 |
|
|
-- Complete the last frame and start to ackumulate a new one
|
1782 |
|
|
-- and update the ackId.
|
1783 |
|
|
|
1784 |
|
|
-- Check the CRC-16 and the length of the received frame.
|
1785 |
|
|
if (crc16Valid = '1') and (frameIndex > 3) then
|
1786 |
|
|
-- The CRC-16 is ok.
|
1787 |
|
|
|
1788 |
|
|
-- Reset the frame index to indicate the frame is started.
|
1789 |
|
|
frameIndex <= 1;
|
1790 |
|
|
|
1791 |
|
|
-- Update the frame buffer to indicate that the frame has
|
1792 |
|
|
-- been completly received.
|
1793 |
|
|
writeFrame_o <= '1';
|
1794 |
|
|
|
1795 |
|
|
-- Update ackId.
|
1796 |
|
|
ackId <= ackId + 1;
|
1797 |
|
|
|
1798 |
|
|
-- Send packet-accepted.
|
1799 |
|
|
-- The buffer status is appended by the transmitter
|
1800 |
|
|
-- when sent to get the latest number.
|
1801 |
|
|
rxControlWrite_o <= '1';
|
1802 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_ACCEPTED & std_logic_vector(ackId) & "11111";
|
1803 |
|
|
else
|
1804 |
|
|
-- The CRC-16 is not ok.
|
1805 |
|
|
|
1806 |
|
|
-- Make the transmitter send a packet-not-accepted to indicate
|
1807 |
|
|
-- that the received packet contained a CRC error.
|
1808 |
|
|
rxControlWrite_o <= '1';
|
1809 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_NOT_ACCEPTED &
|
1810 |
|
|
"00000" &
|
1811 |
|
|
PACKET_NOT_ACCEPTED_CAUSE_PACKET_CRC;
|
1812 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
1813 |
|
|
end if;
|
1814 |
|
|
else
|
1815 |
|
|
-- No frame has been started.
|
1816 |
|
|
|
1817 |
|
|
-- Reset the frame index to indicate the frame is started.
|
1818 |
|
|
frameIndex <= 1;
|
1819 |
|
|
end if;
|
1820 |
|
|
|
1821 |
|
|
when STYPE1_END_OF_PACKET =>
|
1822 |
|
|
-------------------------------------------------------------
|
1823 |
|
|
-- End the reception of an old frame.
|
1824 |
|
|
-------------------------------------------------------------
|
1825 |
|
|
|
1826 |
|
|
-- Check the CRC-16 and the length of the received frame.
|
1827 |
|
|
if (crc16Valid = '1') and (frameIndex > 3) then
|
1828 |
|
|
-- The CRC-16 is ok.
|
1829 |
|
|
|
1830 |
|
|
-- Reset frame reception to indicate that no frame is ongoing.
|
1831 |
|
|
frameIndex <= 0;
|
1832 |
|
|
|
1833 |
|
|
-- Update the frame buffer to indicate that the frame has
|
1834 |
|
|
-- been completly received.
|
1835 |
|
|
writeFrame_o <= '1';
|
1836 |
|
|
|
1837 |
|
|
-- Update ackId.
|
1838 |
|
|
ackId <= ackId + 1;
|
1839 |
|
|
|
1840 |
|
|
-- Send packet-accepted.
|
1841 |
|
|
-- The buffer status is appended by the transmitter
|
1842 |
|
|
-- when sent to get the latest number.
|
1843 |
|
|
rxControlWrite_o <= '1';
|
1844 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_ACCEPTED & std_logic_vector(ackId) & "11111";
|
1845 |
|
|
else
|
1846 |
|
|
-- The CRC-16 is not ok.
|
1847 |
|
|
|
1848 |
|
|
-- Make the transmitter send a packet-not-accepted to indicate
|
1849 |
|
|
-- that the received packet contained a CRC error.
|
1850 |
|
|
rxControlWrite_o <= '1';
|
1851 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_NOT_ACCEPTED &
|
1852 |
|
|
"00000" &
|
1853 |
|
|
PACKET_NOT_ACCEPTED_CAUSE_PACKET_CRC;
|
1854 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
1855 |
|
|
end if;
|
1856 |
|
|
|
1857 |
|
|
when STYPE1_STOMP =>
|
1858 |
|
|
-------------------------------------------------------------
|
1859 |
|
|
-- Restart the reception of an old frame.
|
1860 |
|
|
-------------------------------------------------------------
|
1861 |
|
|
-- See 5.10 in the standard.
|
1862 |
|
|
|
1863 |
|
|
-- Make the transmitter send a packet-retry to indicate
|
1864 |
|
|
-- that the packet cannot be accepted.
|
1865 |
|
|
rxControlWrite_o <= '1';
|
1866 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_RETRY & std_logic_vector(ackId) & "11111";
|
1867 |
|
|
|
1868 |
|
|
-- Enter the input retry-stopped state.
|
1869 |
|
|
state <= STATE_INPUT_RETRY_STOPPED;
|
1870 |
|
|
|
1871 |
|
|
when STYPE1_RESTART_FROM_RETRY =>
|
1872 |
|
|
-------------------------------------------------------------
|
1873 |
|
|
-- The receiver indicates a restart from a retry sent
|
1874 |
|
|
-- from us.
|
1875 |
|
|
-------------------------------------------------------------
|
1876 |
|
|
-- See 5.10 in the standard.
|
1877 |
|
|
-- Protocol error, this symbol should not be received here since
|
1878 |
|
|
-- we should have been in input-retry-stopped.
|
1879 |
|
|
|
1880 |
|
|
-- Send a packet-not-accepted to indicate that a protocol
|
1881 |
|
|
-- error has occurred.
|
1882 |
|
|
rxControlWrite_o <= '1';
|
1883 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_NOT_ACCEPTED &
|
1884 |
|
|
"00000" &
|
1885 |
|
|
PACKET_NOT_ACCEPTED_CAUSE_GENERAL_ERROR;
|
1886 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
1887 |
|
|
|
1888 |
|
|
when STYPE1_LINK_REQUEST =>
|
1889 |
|
|
-------------------------------------------------------------
|
1890 |
|
|
-- Reply to a LINK-REQUEST.
|
1891 |
|
|
-------------------------------------------------------------
|
1892 |
|
|
|
1893 |
|
|
-- Check the command part.
|
1894 |
|
|
if (cmd = "100") then
|
1895 |
|
|
-- Return input port status command.
|
1896 |
|
|
-- This functions as a link-request(restart-from-error)
|
1897 |
|
|
-- control symbol under error situations.
|
1898 |
|
|
|
1899 |
|
|
-- Send a link response containing an ok reply.
|
1900 |
|
|
rxControlWrite_o <= '1';
|
1901 |
|
|
rxControlSymbol_o <= STYPE0_LINK_RESPONSE & std_logic_vector(ackId) & "10000";
|
1902 |
|
|
elsif (cmd = "011") then
|
1903 |
|
|
-- Reset device command.
|
1904 |
|
|
-- Discard this.
|
1905 |
|
|
else
|
1906 |
|
|
-- Unsupported command.
|
1907 |
|
|
-- Discard this.
|
1908 |
|
|
end if;
|
1909 |
|
|
|
1910 |
|
|
-- Abort the frame and reset frame reception.
|
1911 |
|
|
frameIndex <= 0;
|
1912 |
|
|
writeFrameAbort_o <= '1';
|
1913 |
|
|
|
1914 |
|
|
when STYPE1_MULTICAST_EVENT =>
|
1915 |
|
|
-------------------------------------------------------------
|
1916 |
|
|
-- Multicast symbol.
|
1917 |
|
|
-------------------------------------------------------------
|
1918 |
|
|
-- Discard the symbol.
|
1919 |
|
|
|
1920 |
|
|
when STYPE1_RESERVED =>
|
1921 |
|
|
-------------------------------------------------------------
|
1922 |
|
|
-- Reserved.
|
1923 |
|
|
-------------------------------------------------------------
|
1924 |
|
|
-- Not supported, dont do anything.
|
1925 |
|
|
|
1926 |
|
|
when STYPE1_NOP =>
|
1927 |
|
|
-------------------------------------------------------------
|
1928 |
|
|
-- NOP, no operation.
|
1929 |
|
|
-------------------------------------------------------------
|
1930 |
|
|
-- Dont do anything.
|
1931 |
|
|
|
1932 |
|
|
when others =>
|
1933 |
|
|
-------------------------------------------------------------
|
1934 |
|
|
--
|
1935 |
|
|
-------------------------------------------------------------
|
1936 |
|
|
-- NOP, no operation, dont do anything.
|
1937 |
|
|
null;
|
1938 |
|
|
|
1939 |
|
|
end case;
|
1940 |
|
|
else
|
1941 |
|
|
-- The control symbol contains a crc error.
|
1942 |
|
|
|
1943 |
|
|
-- Send a packet-not-accepted to indicate that a corrupted
|
1944 |
|
|
-- control-symbol has been received and change state.
|
1945 |
|
|
rxControlWrite_o <= '1';
|
1946 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_NOT_ACCEPTED &
|
1947 |
|
|
"00000" &
|
1948 |
|
|
PACKET_NOT_ACCEPTED_CAUSE_CONTROL_CRC;
|
1949 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
1950 |
|
|
end if;
|
1951 |
|
|
elsif (rxControl_i = SYMBOL_DATA) then
|
1952 |
|
|
-- This is a data symbol.
|
1953 |
|
|
-- REMARK: Add check for in-the-middle-crc here...
|
1954 |
|
|
|
1955 |
|
|
-- Check if a frame has been started.
|
1956 |
|
|
-- Index=0 not started
|
1957 |
|
|
-- index=1 started and expecting to receive the first data.
|
1958 |
|
|
-- index=others, the index of the received data.
|
1959 |
|
|
if (frameIndex /= 0) and (frameIndex /= 70) then
|
1960 |
|
|
-- A frame has been started and is not too long.
|
1961 |
|
|
|
1962 |
|
|
-- Check if the ackId is correct.
|
1963 |
|
|
if (((frameIndex = 1) and (unsigned(rxData_i(31 downto 27)) = ackId)) or
|
1964 |
|
|
(frameIndex /= 1)) then
|
1965 |
|
|
-- This is the first data symbol containing the ackId which
|
1966 |
|
|
-- is matching or receiving the rest of the frame.
|
1967 |
|
|
|
1968 |
|
|
-- Check if the packet ftype is allowed.
|
1969 |
|
|
-- If the portEnable is deasserted only maintenance
|
1970 |
|
|
-- packets are allowed.
|
1971 |
|
|
if (((frameIndex = 1) and
|
1972 |
|
|
((portEnable_i = '1') or (rxData_i(19 downto 16) = FTYPE_MAINTENANCE_CLASS))) or
|
1973 |
|
|
(frameIndex /= 1)) then
|
1974 |
|
|
-- The packet is allowed.
|
1975 |
|
|
|
1976 |
|
|
-- Check if there is buffers available to store the new packet.
|
1977 |
|
|
if(writeFrameFull_i = '0') then
|
1978 |
|
|
-- There is buffering space available to store the new data.
|
1979 |
|
|
|
1980 |
|
|
-- Write the data to the frame FIFO.
|
1981 |
|
|
writeContent_o <= '1';
|
1982 |
|
|
writeContentData_o <= rxData_i;
|
1983 |
|
|
|
1984 |
|
|
-- Increment the number of received data symbols.
|
1985 |
|
|
frameIndex <= frameIndex + 1;
|
1986 |
|
|
|
1987 |
|
|
-- Update the saved crc result with the output from the CRC calculation.
|
1988 |
|
|
if (frameIndex = 1) then
|
1989 |
|
|
-- Note that the ackId should not be included when the CRC
|
1990 |
|
|
-- is calculated.
|
1991 |
|
|
crc16Data <= "000000" & rxData_i(25 downto 0);
|
1992 |
|
|
crc16Current <= (others => '1');
|
1993 |
|
|
else
|
1994 |
|
|
crc16Data <= rxData_i;
|
1995 |
|
|
crc16Current <= crc16Next;
|
1996 |
|
|
end if;
|
1997 |
|
|
else
|
1998 |
|
|
-- The packet buffer is full.
|
1999 |
|
|
-- Let the link-partner resend the packet.
|
2000 |
|
|
rxControlWrite_o <= '1';
|
2001 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_RETRY & std_logic_vector(ackId) & "11111";
|
2002 |
|
|
state <= STATE_INPUT_RETRY_STOPPED;
|
2003 |
|
|
end if;
|
2004 |
|
|
else
|
2005 |
|
|
-- The non-maintenance packets are not allowed.
|
2006 |
|
|
-- Send packet-not-accepted.
|
2007 |
|
|
rxControlWrite_o <= '1';
|
2008 |
|
|
rxControlSymbol_o <=
|
2009 |
|
|
STYPE0_PACKET_NOT_ACCEPTED & "00000" & PACKET_NOT_ACCEPTED_CAUSE_NON_MAINTENANCE_STOPPED;
|
2010 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
2011 |
|
|
end if;
|
2012 |
|
|
else
|
2013 |
|
|
-- The ackId is unexpected.
|
2014 |
|
|
-- Send packet-not-accepted.
|
2015 |
|
|
rxControlWrite_o <= '1';
|
2016 |
|
|
rxControlSymbol_o <=
|
2017 |
|
|
STYPE0_PACKET_NOT_ACCEPTED & "00000" & PACKET_NOT_ACCEPTED_CAUSE_UNEXPECTED_ACKID;
|
2018 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
2019 |
|
|
end if;
|
2020 |
|
|
else
|
2021 |
|
|
-- A frame has not been started or is too long.
|
2022 |
|
|
-- Send packet-not-accepted.
|
2023 |
|
|
rxControlWrite_o <= '1';
|
2024 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_NOT_ACCEPTED & "00000" & PACKET_NOT_ACCEPTED_CAUSE_GENERAL_ERROR;
|
2025 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
2026 |
|
|
end if;
|
2027 |
|
|
else
|
2028 |
|
|
-- Idle sequence received.
|
2029 |
|
|
-- Discard these.
|
2030 |
|
|
end if;
|
2031 |
|
|
|
2032 |
|
|
-- Update to the next symbol.
|
2033 |
|
|
rxRead <= '1';
|
2034 |
|
|
else
|
2035 |
|
|
-- No new symbol received.
|
2036 |
|
|
-- Dont do anything.
|
2037 |
|
|
end if;
|
2038 |
|
|
else
|
2039 |
|
|
-- The port has become uninitialized.
|
2040 |
|
|
-- Go back to the uninitialized state.
|
2041 |
|
|
state <= STATE_UNINITIALIZED;
|
2042 |
|
|
end if;
|
2043 |
|
|
|
2044 |
|
|
when STATE_INPUT_RETRY_STOPPED =>
|
2045 |
|
|
---------------------------------------------------------------------
|
2046 |
|
|
-- This state is entered when a frame could not be accepted. All
|
2047 |
|
|
-- symbols except restart-from-retry and link-request are discarded.
|
2048 |
|
|
-- A restart-from-retry triggers a state change into the normal
|
2049 |
|
|
-- link-initialized state.
|
2050 |
|
|
---------------------------------------------------------------------
|
2051 |
|
|
|
2052 |
|
|
-- Check that the port is initialized.
|
2053 |
|
|
if (portInitialized_i = '1') then
|
2054 |
|
|
-- The port and link is initialized.
|
2055 |
|
|
|
2056 |
|
|
-- Check if a new symbol is ready to be read.
|
2057 |
|
|
if (rxRead = '0') and (rxEmpty_i = '0') then
|
2058 |
|
|
-- There is a new symbol to read.
|
2059 |
|
|
|
2060 |
|
|
-- Check the type of symbol.
|
2061 |
|
|
if (rxControl_i = SYMBOL_CONTROL) then
|
2062 |
|
|
-- This is a control symbol with or without a packet delimiter.
|
2063 |
|
|
|
2064 |
|
|
-- Check if the control symbol has a valid CRC-5.
|
2065 |
|
|
if (crc5Calculated = crc5) then
|
2066 |
|
|
-- The control symbol is correct.
|
2067 |
|
|
|
2068 |
|
|
-- Forward the stype0 part of the symbol to the transmitter.
|
2069 |
|
|
txControlWrite_o <= '1';
|
2070 |
|
|
txControlSymbol_o <= stype0 & parameter0 & parameter1;
|
2071 |
|
|
|
2072 |
|
|
-- Check the stype1 part.
|
2073 |
|
|
case stype1 is
|
2074 |
|
|
|
2075 |
|
|
when STYPE1_RESTART_FROM_RETRY =>
|
2076 |
|
|
-------------------------------------------------------------
|
2077 |
|
|
-- The receiver indicates a restart from a retry sent
|
2078 |
|
|
-- from us.
|
2079 |
|
|
-------------------------------------------------------------
|
2080 |
|
|
|
2081 |
|
|
-- Abort the frame and reset frame reception.
|
2082 |
|
|
frameIndex <= 0;
|
2083 |
|
|
writeFrameAbort_o <= '1';
|
2084 |
|
|
|
2085 |
|
|
-- Go back to the normal operational state.
|
2086 |
|
|
state <= STATE_NORMAL;
|
2087 |
|
|
|
2088 |
|
|
when STYPE1_LINK_REQUEST =>
|
2089 |
|
|
-------------------------------------------------------------
|
2090 |
|
|
-- Received a link-request.
|
2091 |
|
|
-------------------------------------------------------------
|
2092 |
|
|
|
2093 |
|
|
-- Check the command part.
|
2094 |
|
|
if (cmd = "100") then
|
2095 |
|
|
-- Return input port status command.
|
2096 |
|
|
-- This functions as a link-request(restart-from-error)
|
2097 |
|
|
-- control symbol under error situations.
|
2098 |
|
|
|
2099 |
|
|
-- Send a link response containing an ok reply.
|
2100 |
|
|
rxControlWrite_o <= '1';
|
2101 |
|
|
rxControlSymbol_o <= STYPE0_LINK_RESPONSE & std_logic_vector(ackId) & "00100";
|
2102 |
|
|
elsif (cmd = "011") then
|
2103 |
|
|
-- Reset device command.
|
2104 |
|
|
-- Discard this.
|
2105 |
|
|
else
|
2106 |
|
|
-- Unsupported command.
|
2107 |
|
|
-- Discard this.
|
2108 |
|
|
end if;
|
2109 |
|
|
|
2110 |
|
|
-- Abort the frame and reset frame reception.
|
2111 |
|
|
frameIndex <= 0;
|
2112 |
|
|
writeFrameAbort_o <= '1';
|
2113 |
|
|
|
2114 |
|
|
-- Go back to the normal operational state.
|
2115 |
|
|
state <= STATE_NORMAL;
|
2116 |
|
|
|
2117 |
|
|
when others =>
|
2118 |
|
|
-------------------------------------------------------------
|
2119 |
|
|
--
|
2120 |
|
|
-------------------------------------------------------------
|
2121 |
|
|
-- Discard other control symbols.
|
2122 |
|
|
null;
|
2123 |
|
|
|
2124 |
|
|
end case;
|
2125 |
|
|
else
|
2126 |
|
|
-- The control symbol contains a crc error.
|
2127 |
|
|
|
2128 |
|
|
-- Send a packet-not-accepted to indicate that a corrupted
|
2129 |
|
|
-- control-symbol has been received and change state.
|
2130 |
|
|
rxControlWrite_o <= '1';
|
2131 |
|
|
rxControlSymbol_o <= STYPE0_PACKET_NOT_ACCEPTED &
|
2132 |
|
|
"00000" &
|
2133 |
|
|
PACKET_NOT_ACCEPTED_CAUSE_CONTROL_CRC;
|
2134 |
|
|
state <= STATE_INPUT_ERROR_STOPPED;
|
2135 |
|
|
end if;
|
2136 |
|
|
elsif (rxControl_i = SYMBOL_DATA) then
|
2137 |
|
|
-- This is a data symbol.
|
2138 |
|
|
-- Discard all data symbols in this state.
|
2139 |
|
|
else
|
2140 |
|
|
-- Idle sequence received.
|
2141 |
|
|
-- Discard other symbols.
|
2142 |
|
|
end if;
|
2143 |
|
|
|
2144 |
|
|
-- Update to the next symbol.
|
2145 |
|
|
rxRead <= '1';
|
2146 |
|
|
else
|
2147 |
|
|
-- No new symbol received.
|
2148 |
|
|
-- Dont do anything.
|
2149 |
|
|
end if;
|
2150 |
|
|
else
|
2151 |
|
|
-- The port has become uninitialized.
|
2152 |
|
|
-- Go back to the uninitialized state.
|
2153 |
|
|
state <= STATE_UNINITIALIZED;
|
2154 |
|
|
end if;
|
2155 |
|
|
|
2156 |
|
|
when STATE_INPUT_ERROR_STOPPED =>
|
2157 |
|
|
---------------------------------------------------------------------
|
2158 |
|
|
-- This state is entered when an error situation has occurred. When in this
|
2159 |
|
|
-- state, all symbols should be discarded until a link-request-symbols has
|
2160 |
|
|
-- been received. See section 5.13.2.6 in part 6 of the standard.
|
2161 |
|
|
-- Note that it is only the input side of the port that are affected, not the
|
2162 |
|
|
-- output side. Packets may still be transmitted and acknowledges should be
|
2163 |
|
|
-- accepted.
|
2164 |
|
|
---------------------------------------------------------------------
|
2165 |
|
|
|
2166 |
|
|
-- Check that the port is initialized.
|
2167 |
|
|
if (portInitialized_i = '1') then
|
2168 |
|
|
-- The port and link is initialized.
|
2169 |
|
|
|
2170 |
|
|
-- Check if a new symbol is ready to be read.
|
2171 |
|
|
if (rxRead = '0') and (rxEmpty_i = '0') then
|
2172 |
|
|
-- There is a new symbol to read.
|
2173 |
|
|
|
2174 |
|
|
-- Check the type of symbol.
|
2175 |
|
|
if (rxControl_i = SYMBOL_CONTROL) then
|
2176 |
|
|
-- This is a control symbol with or without a packet delimiter.
|
2177 |
|
|
|
2178 |
|
|
-- Check if the control symbol has a valid CRC-5.
|
2179 |
|
|
if (crc5Calculated = crc5) then
|
2180 |
|
|
-- The control symbol is correct.
|
2181 |
|
|
|
2182 |
|
|
-- Forward the stype0 part of the symbol to the transmitter.
|
2183 |
|
|
txControlWrite_o <= '1';
|
2184 |
|
|
txControlSymbol_o <= stype0 & parameter0 & parameter1;
|
2185 |
|
|
|
2186 |
|
|
-- Check the stype1 part.
|
2187 |
|
|
case stype1 is
|
2188 |
|
|
|
2189 |
|
|
when STYPE1_LINK_REQUEST =>
|
2190 |
|
|
-------------------------------------------------------------
|
2191 |
|
|
-- Received a link-request.
|
2192 |
|
|
-------------------------------------------------------------
|
2193 |
|
|
|
2194 |
|
|
-- Check the command part.
|
2195 |
|
|
-- REMARK: Should also send a status-control-symbol
|
2196 |
|
|
-- directly following this symbol...
|
2197 |
|
|
if (cmd = "100") then
|
2198 |
|
|
-- Return input port status command.
|
2199 |
|
|
-- This functions as a link-request(restart-from-error)
|
2200 |
|
|
-- control symbol under error situations.
|
2201 |
|
|
|
2202 |
|
|
-- Send a link response containing an ok reply.
|
2203 |
|
|
rxControlWrite_o <= '1';
|
2204 |
|
|
rxControlSymbol_o <= STYPE0_LINK_RESPONSE & std_logic_vector(ackId) & "00101";
|
2205 |
|
|
elsif (cmd = "011") then
|
2206 |
|
|
-- Reset device command.
|
2207 |
|
|
-- Discard this.
|
2208 |
|
|
else
|
2209 |
|
|
-- Unsupported command.
|
2210 |
|
|
-- Discard this.
|
2211 |
|
|
end if;
|
2212 |
|
|
|
2213 |
|
|
-- Abort the frame and reset frame reception.
|
2214 |
|
|
frameIndex <= 0;
|
2215 |
|
|
writeFrameAbort_o <= '1';
|
2216 |
|
|
|
2217 |
|
|
-- Go back to the normal operational state.
|
2218 |
|
|
state <= STATE_NORMAL;
|
2219 |
|
|
|
2220 |
|
|
when others =>
|
2221 |
|
|
-------------------------------------------------------------
|
2222 |
|
|
--
|
2223 |
|
|
-------------------------------------------------------------
|
2224 |
|
|
-- Discard other control symbols.
|
2225 |
|
|
null;
|
2226 |
|
|
|
2227 |
|
|
end case;
|
2228 |
|
|
else
|
2229 |
|
|
-- The control symbol contains a crc error.
|
2230 |
|
|
-- Error is ignored in this state.
|
2231 |
|
|
end if;
|
2232 |
|
|
else
|
2233 |
|
|
-- Other symbol received.
|
2234 |
|
|
-- All other symbols are discarded in this state.
|
2235 |
|
|
end if;
|
2236 |
|
|
|
2237 |
|
|
-- Update to the next symbol.
|
2238 |
|
|
rxRead <= '1';
|
2239 |
|
|
else
|
2240 |
|
|
-- No new symbol received.
|
2241 |
|
|
-- Dont do anything.
|
2242 |
|
|
end if;
|
2243 |
|
|
else
|
2244 |
|
|
-- The port has become uninitialized.
|
2245 |
|
|
-- Go back to the uninitialized state.
|
2246 |
|
|
state <= STATE_UNINITIALIZED;
|
2247 |
|
|
end if;
|
2248 |
|
|
|
2249 |
|
|
when others =>
|
2250 |
|
|
---------------------------------------------------------------------
|
2251 |
|
|
--
|
2252 |
|
|
---------------------------------------------------------------------
|
2253 |
|
|
null;
|
2254 |
|
|
end case;
|
2255 |
|
|
end if;
|
2256 |
|
|
end if;
|
2257 |
|
|
end process;
|
2258 |
|
|
|
2259 |
|
|
end architecture;
|
2260 |
|
|
|
2261 |
|
|
|
2262 |
|
|
|
2263 |
|
|
-------------------------------------------------------------------------------
|
2264 |
|
|
--
|
2265 |
|
|
---------------------------------------------------------------------------------
|
2266 |
|
|
library ieee;
|
2267 |
|
|
use ieee.std_logic_1164.all;
|
2268 |
|
|
|
2269 |
|
|
|
2270 |
|
|
-------------------------------------------------------------------------------
|
2271 |
|
|
--
|
2272 |
|
|
-------------------------------------------------------------------------------
|
2273 |
|
|
entity RioFifo1 is
|
2274 |
|
|
generic(
|
2275 |
|
|
WIDTH : natural);
|
2276 |
|
|
port(
|
2277 |
|
|
clk : in std_logic;
|
2278 |
|
|
areset_n : in std_logic;
|
2279 |
|
|
|
2280 |
|
|
empty_o : out std_logic;
|
2281 |
|
|
read_i : in std_logic;
|
2282 |
|
|
data_o : out std_logic_vector(WIDTH-1 downto 0);
|
2283 |
|
|
|
2284 |
|
|
full_o : out std_logic;
|
2285 |
|
|
write_i : in std_logic;
|
2286 |
|
|
data_i : in std_logic_vector(WIDTH-1 downto 0));
|
2287 |
|
|
end entity;
|
2288 |
|
|
|
2289 |
|
|
|
2290 |
|
|
-------------------------------------------------------------------------------
|
2291 |
|
|
--
|
2292 |
|
|
-------------------------------------------------------------------------------
|
2293 |
|
|
architecture RioFifo1Impl of RioFifo1 is
|
2294 |
|
|
signal empty : std_logic;
|
2295 |
|
|
signal full : std_logic;
|
2296 |
|
|
begin
|
2297 |
|
|
|
2298 |
|
|
empty_o <= empty;
|
2299 |
|
|
full_o <= full;
|
2300 |
|
|
|
2301 |
|
|
process(areset_n, clk)
|
2302 |
|
|
begin
|
2303 |
|
|
if (areset_n = '0') then
|
2304 |
|
|
empty <= '1';
|
2305 |
|
|
full <= '0';
|
2306 |
|
|
data_o <= (others => '0');
|
2307 |
|
|
elsif (clk'event and clk = '1') then
|
2308 |
|
|
if (empty = '1') then
|
2309 |
|
|
if (write_i = '1') then
|
2310 |
|
|
empty <= '0';
|
2311 |
|
|
full <= '1';
|
2312 |
|
|
data_o <= data_i;
|
2313 |
|
|
end if;
|
2314 |
|
|
else
|
2315 |
|
|
if (read_i = '1') then
|
2316 |
|
|
empty <= '1';
|
2317 |
|
|
full <= '0';
|
2318 |
|
|
end if;
|
2319 |
|
|
end if;
|
2320 |
|
|
end if;
|
2321 |
|
|
end process;
|
2322 |
|
|
|
2323 |
|
|
end architecture;
|
2324 |
|
|
|
2325 |
|
|
|
2326 |
|
|
|
2327 |
|
|
-------------------------------------------------------------------------------
|
2328 |
|
|
-- A CRC-5 calculator following the implementation proposed in the 2.2
|
2329 |
|
|
-- standard.
|
2330 |
|
|
-------------------------------------------------------------------------------
|
2331 |
|
|
library ieee;
|
2332 |
|
|
use ieee.std_logic_1164.all;
|
2333 |
|
|
|
2334 |
|
|
|
2335 |
|
|
-------------------------------------------------------------------------------
|
2336 |
|
|
--
|
2337 |
|
|
-------------------------------------------------------------------------------
|
2338 |
|
|
entity Crc5ITU is
|
2339 |
|
|
port(
|
2340 |
|
|
d_i : in std_logic_vector(18 downto 0);
|
2341 |
|
|
crc_o : out std_logic_vector(4 downto 0));
|
2342 |
|
|
end entity;
|
2343 |
|
|
|
2344 |
|
|
|
2345 |
|
|
-------------------------------------------------------------------------------
|
2346 |
|
|
--
|
2347 |
|
|
-------------------------------------------------------------------------------
|
2348 |
|
|
architecture Crc5Impl of Crc5ITU is
|
2349 |
|
|
signal d : std_logic_vector(0 to 18);
|
2350 |
|
|
signal c : std_logic_vector(0 to 4);
|
2351 |
|
|
|
2352 |
|
|
begin
|
2353 |
|
|
-- Reverse the bit vector indexes to make them the same as in the standard.
|
2354 |
|
|
d(18) <= d_i(0); d(17) <= d_i(1); d(16) <= d_i(2); d(15) <= d_i(3);
|
2355 |
|
|
d(14) <= d_i(4); d(13) <= d_i(5); d(12) <= d_i(6); d(11) <= d_i(7);
|
2356 |
|
|
d(10) <= d_i(8); d(9) <= d_i(9); d(8) <= d_i(10); d(7) <= d_i(11);
|
2357 |
|
|
d(6) <= d_i(12); d(5) <= d_i(13); d(4) <= d_i(14); d(3) <= d_i(15);
|
2358 |
|
|
d(2) <= d_i(16); d(1) <= d_i(17); d(0) <= d_i(18);
|
2359 |
|
|
|
2360 |
|
|
-- Calculate the resulting crc.
|
2361 |
|
|
c(0) <= d(18) xor d(16) xor d(15) xor d(12) xor
|
2362 |
|
|
d(10) xor d(5) xor d(4) xor d(3) xor
|
2363 |
|
|
d(1) xor d(0);
|
2364 |
|
|
c(1) <= (not d(18)) xor d(17) xor d(15) xor d(13) xor
|
2365 |
|
|
d(12) xor d(11) xor d(10) xor d(6) xor
|
2366 |
|
|
d(3) xor d(2) xor d(0);
|
2367 |
|
|
c(2) <= (not d(18)) xor d(16) xor d(14) xor d(13) xor
|
2368 |
|
|
d(12) xor d(11) xor d(7) xor d(4) xor
|
2369 |
|
|
d(3) xor d(1);
|
2370 |
|
|
c(3) <= (not d(18)) xor d(17) xor d(16) xor d(14) xor
|
2371 |
|
|
d(13) xor d(10) xor d(8) xor d(3) xor
|
2372 |
|
|
d(2) xor d(1);
|
2373 |
|
|
c(4) <= d(18) xor d(17) xor d(15) xor d(14) xor
|
2374 |
|
|
d(11) xor d(9) xor d(4) xor d(3) xor
|
2375 |
|
|
d(2) xor d(0);
|
2376 |
|
|
|
2377 |
|
|
-- Reverse the bit vector indexes to make them the same as in the standard.
|
2378 |
|
|
crc_o(4) <= c(0); crc_o(3) <= c(1); crc_o(2) <= c(2); crc_o(1) <= c(3);
|
2379 |
|
|
crc_o(0) <= c(4);
|
2380 |
|
|
end architecture;
|