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