AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
amc_gtx5gpd_rx_startup_fsm.vhd
1 --////////////////////////////////////////////////////////////////////////////////
2 --// ____ ____
3 --// / /\/ /
4 --// /___/ \ / Vendor: Xilinx
5 --// \ \ \/ Version : 3.6
6 --// \ \ Application : 7 Series FPGAs Transceivers Wizard
7 --// / / Filename : amc_gtx5gpd_rx_startup_fsm.vhd
8 --// /___/ /\
9 --// \ \ / \
10 --// \___\/\___\
11 --//
12 --//
13 -- Description : This module performs RX reset and initialization.
14 --
15 --
16 --
17 -- Module amc_gtx5Gpd_rx_startup_fsm
18 -- Generated by Xilinx 7 Series FPGAs Transceivers Wizard
19 --
20 --
21 -- (c) Copyright 2010-2012 Xilinx, Inc. All rights reserved.
22 --
23 -- This file contains confidential and proprietary information
24 -- of Xilinx, Inc. and is protected under U.S. and
25 -- international copyright and other intellectual property
26 -- laws.
27 --
28 -- DISCLAIMER
29 -- This disclaimer is not a license and does not grant any
30 -- rights to the materials distributed herewith. Except as
31 -- otherwise provided in a valid license issued to you by
32 -- Xilinx, and to the maximum extent permitted by applicable
33 -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
34 -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
35 -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
36 -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
37 -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
38 -- (2) Xilinx shall not be liable (whether in contract or tort,
39 -- including negligence, or under any other theory of
40 -- liability) for any loss or damage of any kind or nature
41 -- related to, arising under or in connection with these
42 -- materials, including for any direct, or any indirect,
43 -- special, incidental, or consequential loss or damage
44 -- (including loss of data, profits, goodwill, or any type of
45 -- loss or damage suffered as a result of any action brought
46 -- by a third party) even if such damage or loss was
47 -- reasonably foreseeable or Xilinx had been advised of the
48 -- possibility of the same.
49 --
50 -- CRITICAL APPLICATIONS
51 -- Xilinx products are not designed or intended to be fail-
52 -- safe, or for use in any application requiring fail-safe
53 -- performance, such as life-support or safety devices or
54 -- systems, Class III medical devices, nuclear facilities,
55 -- applications related to the deployment of airbags, or any
56 -- other applications that could lead to death, personal
57 -- injury, or severe property or environmental damage
58 -- (individually and collectively, "Critical
59 -- Applications"). Customer assumes the sole risk and
60 -- liability of any use of Xilinx products in Critical
61 -- Applications, subject only to applicable laws and
62 -- regulations governing limitations on product liability.
63 --
64 -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
65 -- PART OF THIS FILE AT ALL TIMES.
66 
67 
68 --*****************************************************************************
69 
70 library IEEE;
71 use IEEE.STD_LOGIC_1164.ALL;
72 use IEEE.NUMERIC_STD.ALL;
73 library unisim;
74 use unisim.vcomponents.all;
75 
77  Generic( EXAMPLE_SIMULATION : integer := 0;
78  EQ_MODE : string := "DFE"; --RX Equalisation Mode; set to DFE or LPM
79  STABLE_CLOCK_PERIOD : integer range 4 to 250 := 8; --Period of the stable clock driving this state-machine, unit is [ns]
80  RETRY_COUNTER_BITWIDTH : integer range 2 to 8 := 8;
81  TX_QPLL_USED : boolean := False; -- the TX and RX Reset FSMs must
82  RX_QPLL_USED : boolean := False; -- share these two generic values
83  PHASE_ALIGNMENT_MANUAL : boolean := True -- Decision if a manual phase-alignment is necessary or the automatic
84  -- is enough. For single-lane applications the automatic alignment is
85  -- sufficient
86  );
87  Port ( STABLE_CLOCK : in STD_LOGIC; --Stable Clock, either a stable clock from the PCB
88  --or reference-clock present at startup.
89  RXUSERCLK : in STD_LOGIC; --RXUSERCLK as used in the design
90  SOFT_RESET : in STD_LOGIC; --User Reset, can be pulled any time
91 
92  QPLLREFCLKLOST : in STD_LOGIC; --QPLL Reference-clock for the GT is lost
93  CPLLREFCLKLOST : in STD_LOGIC; --CPLL Reference-clock for the GT is lost
94  QPLLLOCK : in STD_LOGIC; --Lock Detect from the QPLL of the GT
95  CPLLLOCK : in STD_LOGIC; --Lock Detect from the CPLL of the GT
96  RXRESETDONE : in STD_LOGIC;
97  MMCM_LOCK : in STD_LOGIC;
98  RECCLK_STABLE : in STD_LOGIC;
99  RECCLK_MONITOR_RESTART : in STD_LOGIC:='0';
100  DATA_VALID : in STD_LOGIC;
101  TXUSERRDY : in STD_LOGIC; --TXUSERRDY from GT
102  DONT_RESET_ON_DATA_ERROR : in STD_LOGIC; --Used to control the Auto-Reset of FSM when Data Error is detected
103  GTRXRESET : out STD_LOGIC;
104  MMCM_RESET : out STD_LOGIC;
105  QPLL_RESET : out STD_LOGIC:='0'; --Reset QPLL (only if RX uses QPLL)
106  CPLL_RESET : out STD_LOGIC:='0'; --Reset CPLL (only if RX uses CPLL)
107  RX_FSM_RESET_DONE : out STD_LOGIC; --Reset-sequence has sucessfully been finished.
108  RXUSERRDY : out STD_LOGIC:='0';
109  RUN_PHALIGNMENT : out STD_LOGIC;
110  PHALIGNMENT_DONE : in STD_LOGIC;
111  RESET_PHALIGNMENT : out STD_LOGIC:='0';
112  RXDFEAGCHOLD : out STD_LOGIC;
113  RXDFELFHOLD : out STD_LOGIC;
114  RXLPMLFHOLD : out STD_LOGIC;
115  RXLPMHFHOLD : out STD_LOGIC;
116  RETRY_COUNTER : out STD_LOGIC_VECTOR (RETRY_COUNTER_BITWIDTH-1 downto 0):=(others=>'0')-- Number of
117  -- Retries it took to get the transceiver up and running
118  );
119 end amc_gtx5Gpd_RX_STARTUP_FSM;
120 
121 --Interdependencies:
122 -- * Timing depends on the frequency of the stable clock. Hence counters-sizes
123 -- are calculated at design-time based on the Generics
124 --
125 -- * if either of the PLLs is reset during TX-startup, it does not need to be reset again by RX
126 -- => signal which PLL has been reset
127 -- *
128 
129 
130 
131 architecture RTL of amc_gtx5Gpd_RX_STARTUP_FSM is
132 
133  component amc_gtx5Gpd_sync_block
134  generic (
135  INITIALISE : bit_vector(5 downto 0) := "000000"
136  );
137  port (
138  clk : in std_logic;
139  data_in : in std_logic;
140  data_out : out std_logic
141  );
142  end component;
143  type rx_rst_fsm_type is(
144  INIT, ASSERT_ALL_RESETS, WAIT_FOR_PLL_LOCK, RELEASE_PLL_RESET, VERIFY_RECCLK_STABLE,
145  RELEASE_MMCM_RESET, WAIT_FOR_RXUSRCLK, WAIT_RESET_DONE, DO_PHASE_ALIGNMENT,
146  MONITOR_DATA_VALID, FSM_DONE);
147 
148  signal rx_state : rx_rst_fsm_type := INIT;
149 
150  constant MMCM_LOCK_CNT_MAX : integer := 256;
151  constant STARTUP_DELAY : integer := 500;--AR43482: Transceiver needs to wait for 500 ns after configuration
152  constant WAIT_CYCLES : integer := STARTUP_DELAY / STABLE_CLOCK_PERIOD; -- Number of Clock-Cycles to wait after configuration
153  constant WAIT_MAX : integer := WAIT_CYCLES + 10; -- 500 ns plus some additional margin
154  constant WAIT_TIMEOUT_2ms : integer := 2000000 / STABLE_CLOCK_PERIOD;-- 2 ms time-out
155  constant WAIT_TLOCK_MAX : integer := 100000 / STABLE_CLOCK_PERIOD;--100 us time-out
156  constant WAIT_TIMEOUT_500us : integer := 500000 / STABLE_CLOCK_PERIOD;--500 us time-out
157  constant WAIT_TIMEOUT_1us : integer := 1000 / STABLE_CLOCK_PERIOD; --1 us time-out
158  constant WAIT_TIMEOUT_100us : integer := 100000 / STABLE_CLOCK_PERIOD; --100 us time-out
159  constant WAIT_TIME_ADAPT : integer := (37000000 /integer(5.0))/STABLE_CLOCK_PERIOD;
160  constant WAIT_TIME_MAX : integer := 100 ; --10 us time-out
161 
162  signal init_wait_count : integer range 0 to WAIT_MAX:=0;
163  signal init_wait_done : std_logic := '0';
164  signal pll_reset_asserted : std_logic := '0';
165 
166 
167  signal rx_fsm_reset_done_int : std_logic := '0';
168  signal rx_fsm_reset_done_int_s2 : std_logic := '0';
169  signal rx_fsm_reset_done_int_s3 : std_logic := '0';
170 
171  signal rxresetdone_s2 : std_logic := '0';
172  signal rxresetdone_s3 : std_logic := '0';
173 
174  constant MAX_RETRIES : integer := 2**RETRY_COUNTER_BITWIDTH-1;
175  signal retry_counter_int : integer range 0 to MAX_RETRIES := 0;
176  signal time_out_counter : integer range 0 to WAIT_TIMEOUT_2ms := 0;
177  signal recclk_mon_restart_count : integer range 0 to 3:= 0;
178  signal recclk_mon_count_reset : std_logic := '0';
179 
180  signal reset_time_out : std_logic := '0';
181  signal time_out_2ms : std_logic := '0';--\Flags that the various time-out points
182  signal time_tlock_max : std_logic := '0';--|have been reached.
183  signal time_out_500us : std_logic := '0';--|
184  signal time_out_1us : std_logic := '0';--/
185  signal time_out_100us : std_logic := '0';--/
186  signal check_tlock_max : std_logic := '0';
187 
188  signal mmcm_lock_count : integer range 0 to MMCM_LOCK_CNT_MAX-1:=0;
189  signal mmcm_lock_int : std_logic := '0';
190  signal mmcm_lock_i : std_logic := '0';
191  signal mmcm_lock_reclocked : std_logic := '0';
192  signal gtrxreset_i : std_logic := '0';
193  signal gtrxreset_tx_i : std_logic := '0';
194  signal gtrxreset_rx_i : std_logic := '0';
195  signal mmcm_reset_i : std_logic := '1';
196  signal rxpmaresetdone_i : std_logic := '0';
197  signal txpmaresetdone_i : std_logic := '0';
198  signal rxpmaresetdone_ss : std_logic := '0';
199  signal rxpmaresetdone_sync : std_logic ;
200  signal txpmaresetdone_sync : std_logic ;
201  signal rxpmaresetdone_s : std_logic ;
202  signal rxpmaresetdone_rx_s : std_logic ;
203  signal pmaresetdone_fallingedge_detect : std_logic ;
204  signal pmaresetdone_fallingedge_detect_s : std_logic ;
205 
206  signal run_phase_alignment_int: std_logic := '0';
207  signal run_phase_alignment_int_s2 : std_logic := '0';
208  signal run_phase_alignment_int_s3 : std_logic := '0';
209 
210  constant MAX_WAIT_BYPASS : integer := 5000;--5000 RXUSRCLK cycles is the max time for Multi lanes designs
211  signal wait_bypass_count : integer range 0 to MAX_WAIT_BYPASS-1;
212  signal time_out_wait_bypass : std_logic := '0';
213  signal time_out_wait_bypass_s2 : std_logic := '0';
214  signal time_out_wait_bypass_s3 : std_logic := '0';
215 
216  signal refclk_lost : std_logic;
217 
218  signal time_out_adapt : std_logic := '0';
219  signal adapt_count_reset : std_logic := '0';
220  signal adapt_count : integer range 0 to WAIT_TIME_ADAPT-1;
221  signal data_valid_sync: std_logic := '0';
222  signal cplllock_sync: std_logic := '0';
223  signal qplllock_sync: std_logic := '0';
224  signal cplllock_prev: std_logic := '0';
225  signal qplllock_prev: std_logic := '0';
226  signal cplllock_ris_edge: std_logic := '0';
227  signal qplllock_ris_edge: std_logic := '0';
228  signal wait_time_cnt : integer range 0 to WAIT_TIME_MAX;
229  signal wait_time_done : std_logic;
230 
231 
232  attribute shreg_extract : string;
233  attribute ASYNC_REG : string;
234  attribute KEEP : string;
235 
236  signal reset_sync_reg1_tx : std_logic;
237  signal reset_sync_reg1 : std_logic;
238  signal gtrxreset_s : std_logic;
239  signal gtrxreset_tx_s : std_logic;
240  signal txpmaresetdone_s : std_logic;
241 begin
242  --Alias section, signals used within this module mapped to output ports:
243  RETRY_COUNTER <= STD_LOGIC_VECTOR(TO_UNSIGNED(retry_counter_int,RETRY_COUNTER_BITWIDTH));
244  RUN_PHALIGNMENT <= run_phase_alignment_int;
245  RX_FSM_RESET_DONE <= rx_fsm_reset_done_int;
246  GTRXRESET <= gtrxreset_i;
247  MMCM_RESET <= mmcm_reset_i;
248  process(STABLE_CLOCK,SOFT_RESET)
249  begin
250  if (SOFT_RESET = '1') then
251  init_wait_done <= '0';
252  init_wait_count <= 0 ;
253  elsif rising_edge(STABLE_CLOCK) then
254  -- The counter starts running when configuration has finished and
255  -- the clock is stable. When its maximum count-value has been reached,
256  -- the 500 ns from Answer Record 43482 have been passed.
257  if init_wait_count = WAIT_MAX then
258  init_wait_done <= '1';
259  else
260  init_wait_count <= init_wait_count + 1;
261  end if;
262  end if;
263  end process;
264 
265 
266  adapt_wait_sim:if(EXAMPLE_SIMULATION = 1) generate
267  time_out_adapt <= '1';
268  end generate;
269 
270  adapt_wait_hw:if(EXAMPLE_SIMULATION = 0) generate
271  process(STABLE_CLOCK)
272  begin
273  if rising_edge(STABLE_CLOCK) then
274  if(adapt_count_reset = '1') then
275  adapt_count <= 0;
276  time_out_adapt <= '0';
277  elsif(adapt_count = WAIT_TIME_ADAPT -1) then
278  time_out_adapt <= '1';
279  else
280  adapt_count <= adapt_count + 1;
281  end if;
282  end if;
283  end process;
284  end generate;
285 
286  retries_recclk_monitor:process(STABLE_CLOCK)
287  begin
288  --This counter monitors, how many retries the RECCLK monitor
289  --runs. If during startup too many retries are necessary, the whole
290  --initialisation-process of the transceivers gets restarted.
291  if rising_edge(STABLE_CLOCK) then
292  if recclk_mon_count_reset = '1' then
293  recclk_mon_restart_count <= 0;
294  elsif RECCLK_MONITOR_RESTART = '1' then
295  if recclk_mon_restart_count = 3 then
296  recclk_mon_restart_count <= 0;
297  else
298  recclk_mon_restart_count <= recclk_mon_restart_count + 1;
299  end if;
300  end if;
301  end if;
302  end process;
303 
304  timeouts:process(STABLE_CLOCK)
305  begin
306  if rising_edge(STABLE_CLOCK) then
307  -- One common large counter for generating three time-out signals.
308  -- Intermediate time-outs are derived from calculated values, based
309  -- on the period of the provided clock.
310  if reset_time_out = '1' then
311  time_out_counter <= 0;
312  time_out_2ms <= '0';
313  time_tlock_max <= '0';
314  time_out_500us <= '0';
315  time_out_1us <= '0';
316  time_out_100us <= '0';
317  else
318  if time_out_counter = WAIT_TIMEOUT_2ms then
319  time_out_2ms <= '1';
320  else
321  time_out_counter <= time_out_counter + 1;
322  end if;
323 
324  if (time_out_counter > WAIT_TLOCK_MAX) and (check_tlock_max='1') then
325  time_tlock_max <= '1';
326  end if;
327 
328  if time_out_counter = WAIT_TIMEOUT_500us then
329  time_out_500us <= '1';
330  end if;
331 
332  if time_out_counter = WAIT_TIMEOUT_1us then
333  time_out_1us <= '1';
334  end if;
335 
336  if time_out_counter = WAIT_TIMEOUT_100us then
337  time_out_100us <= '1';
338  end if;
339 
340  end if;
341  end if;
342  end process;
343 
344 
345 
346  mmcm_lock_wait:process(STABLE_CLOCK)
347  begin
348  --The lock-signal from the MMCM is not immediately used but
349  --enabling a counter. Only when the counter hits its maximum,
350  --the MMCM is considered as "really" locked.
351  --The counter avoids that the FSM already starts on only a
352  --coarse lock of the MMCM (=toggling of the LOCK-signal).
353  if rising_edge(STABLE_CLOCK) then
354  if mmcm_lock_i = '0' then
355  mmcm_lock_count <= 0;
356  mmcm_lock_reclocked <= '0';
357  else
358  if mmcm_lock_count < MMCM_LOCK_CNT_MAX - 1 then
359  mmcm_lock_count <= mmcm_lock_count + 1;
360  else
361  mmcm_lock_reclocked <= '1';
362  end if;
363  end if;
364  end if;
365  end process;
366 
367 
368  -- Clock Domain Crossing
369 
370  sync_run_phase_alignment_int : amc_gtx5Gpd_sync_block
371  port map
372  (
373  clk => RXUSERCLK,
374  data_in => run_phase_alignment_int ,
375  data_out => run_phase_alignment_int_s2
376  );
377  sync_rx_fsm_reset_done_int : amc_gtx5Gpd_sync_block
378  port map
379  (
380  clk => RXUSERCLK,
381  data_in => rx_fsm_reset_done_int,
382  data_out => rx_fsm_reset_done_int_s2
383  );
384 
385  process(RXUSERCLK)
386  begin
387  if rising_edge(RXUSERCLK) then
388  run_phase_alignment_int_s3 <= run_phase_alignment_int_s2;
389 
390  rx_fsm_reset_done_int_s3 <= rx_fsm_reset_done_int_s2;
391  end if;
392  end process;
393 
394  sync_RXRESETDONE : amc_gtx5Gpd_sync_block
395  port map
396  (
397  clk => STABLE_CLOCK,
398  data_in => RXRESETDONE,
399  data_out => rxresetdone_s2
400  );
401 
402  sync_time_out_wait_bypass : amc_gtx5Gpd_sync_block
403  port map
404  (
405  clk => STABLE_CLOCK,
406  data_in => time_out_wait_bypass,
407  data_out => time_out_wait_bypass_s2
408  );
409 
410  sync_mmcm_lock_reclocked : amc_gtx5Gpd_sync_block
411  port map
412  (
413  clk => STABLE_CLOCK,
414  data_in => MMCM_LOCK,
415  data_out => mmcm_lock_i
416  );
417 
418  sync_data_valid : amc_gtx5Gpd_sync_block
419  port map
420  (
421  clk => STABLE_CLOCK,
422  data_in => DATA_VALID,
423  data_out => data_valid_sync
424  );
425 
426  process(STABLE_CLOCK)
427  begin
428  if rising_edge(STABLE_CLOCK) then
429  rxresetdone_s3 <= rxresetdone_s2;
430 
431  time_out_wait_bypass_s3 <= time_out_wait_bypass_s2;
432 
433  cplllock_prev <= cplllock_sync;
434  qplllock_prev <= qplllock_sync;
435  end if;
436  end process;
437 
438  sync_CPLLLOCK : amc_gtx5Gpd_sync_block
439  port map
440  (
441  clk => STABLE_CLOCK,
442  data_in => CPLLLOCK,
443  data_out => cplllock_sync
444  );
445 
446  sync_QPLLLOCK : amc_gtx5Gpd_sync_block
447  port map
448  (
449  clk => STABLE_CLOCK,
450  data_in => QPLLLOCK,
451  data_out => qplllock_sync
452  );
453 
454 
455 
456  process (STABLE_CLOCK)
457  begin
458  if rising_edge(STABLE_CLOCK) then
459  if(SOFT_RESET = '1' ) then
460  cplllock_ris_edge <= '0';
461  elsif((cplllock_prev = '0') and (cplllock_sync = '1')) then
462  cplllock_ris_edge <= '1';
463  elsif(rx_state = ASSERT_ALL_RESETS or rx_state = RELEASE_PLL_RESET) then
464  cplllock_ris_edge <= cplllock_ris_edge;
465  else
466  cplllock_ris_edge <= '0';
467  end if;
468  end if;
469  end process;
470 
471  process (STABLE_CLOCK)
472  begin
473  if rising_edge(STABLE_CLOCK) then
474  if(SOFT_RESET = '1' ) then
475  qplllock_ris_edge <= '0';
476  elsif((qplllock_prev = '0') and (qplllock_sync = '1')) then
477  qplllock_ris_edge <= '1';
478  elsif(rx_state = ASSERT_ALL_RESETS or rx_state = RELEASE_PLL_RESET) then
479  qplllock_ris_edge <= qplllock_ris_edge;
480  else
481  qplllock_ris_edge <= '0';
482  end if;
483  end if;
484  end process;
485 
486 
487  timeout_buffer_bypass:process(RXUSERCLK)
488  begin
489  if rising_edge(RXUSERCLK) then
490  if run_phase_alignment_int_s3 = '0' then
491  wait_bypass_count <= 0;
492  time_out_wait_bypass <= '0';
493  elsif (run_phase_alignment_int_s3 = '1') and (rx_fsm_reset_done_int_s3 = '0') then
494  if wait_bypass_count = MAX_WAIT_BYPASS - 1 then
495  time_out_wait_bypass <= '1';
496  else
497  wait_bypass_count <= wait_bypass_count + 1;
498  end if;
499  end if;
500  end if;
501  end process;
502 
503  refclk_lost <= '1' when ((RX_QPLL_USED and QPLLREFCLKLOST='1') or (not RX_QPLL_USED and CPLLREFCLKLOST='1')) else '0';
504 
505 
506  timeout_max:process(STABLE_CLOCK)
507  begin
508  if rising_edge(STABLE_CLOCK) then
509  if((rx_state = ASSERT_ALL_RESETS) or
510  (rx_state = RELEASE_MMCM_RESET)) then
511  wait_time_cnt <= WAIT_TIME_MAX;
512  elsif (wait_time_cnt > 0 ) then
513  wait_time_cnt <= wait_time_cnt - 1;
514  end if;
515  end if;
516  end process;
517 
518  wait_time_done <= '1' when (wait_time_cnt = 0) else '0';
519 
520 
521  --FSM for resetting the GTX/GTH/GTP in the 7-series.
522  --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
523  --
524  -- Following steps are performed:
525  -- 1) After configuration wait for approximately 500 ns as specified in
526  -- answer-record 43482
527  -- 2) Assert all resets on the GT and on an MMCM potentially connected.
528  -- After that wait until a reference-clock has been detected.
529  -- 3) Release the reset to the GT and wait until the GT-PLL has locked.
530  -- 4) Release the MMCM-reset and wait until the MMCM has signalled lock.
531  -- Also get info from the TX-side which PLL has been reset.
532  -- 5) Wait for the RESET_DONE-signal from the GT.
533  -- 6) Signal to start the phase-alignment procedure and wait for it to
534  -- finish.
535  -- 7) Reset-sequence has successfully run through. Signal this to the
536  -- rest of the design by asserting RX_FSM_RESET_DONE.
537 
538  reset_fsm:process(STABLE_CLOCK)
539  begin
540  if rising_edge(STABLE_CLOCK) then
541  if (SOFT_RESET = '1' ) then
542  --if (SOFT_RESET = '1' or (not(rx_state = INIT) and not(rx_state = ASSERT_ALL_RESETS) and refclk_lost = '1')) then
543  rx_state <= INIT;
544  RXUSERRDY <= '0';
545  gtrxreset_i <= '0';
546  mmcm_reset_i <= '0';
547  rx_fsm_reset_done_int <= '0';
548  QPLL_RESET <= '0';
549  CPLL_RESET <= '0';
550  pll_reset_asserted <= '0';
551  reset_time_out <= '1';
552  retry_counter_int <= 0;
553  run_phase_alignment_int <= '0';
554  check_tlock_max <= '0';
555  RESET_PHALIGNMENT <= '1';
556  recclk_mon_count_reset <= '1';
557  adapt_count_reset <= '1';
558  RXDFEAGCHOLD <= '0';
559  RXDFELFHOLD <= '0';
560  RXLPMLFHOLD <= '0';
561  RXLPMHFHOLD <= '0';
562 
563  else
564 
565  case rx_state is
566  when INIT =>
567  --Initial state after configuration. This state will be left after
568  --approx. 500 ns and not be re-entered.
569  if init_wait_done = '1' then
570  rx_state <= ASSERT_ALL_RESETS;
571  end if;
572 
573  when ASSERT_ALL_RESETS =>
574  --This is the state into which the FSM will always jump back if any
575  --time-outs will occur.
576  --The number of retries is reported on the output RETRY_COUNTER. In
577  --case the transceiver never comes up for some reason, this machine
578  --will still continue its best and rerun until the FPGA is turned off
579  --or the transceivers come up correctly.
580  if RX_QPLL_USED and not TX_QPLL_USED then
581  if (pll_reset_asserted = '0' and refclk_lost = '0') then
582  QPLL_RESET <= '1';
583  pll_reset_asserted <= '1';
584  else
585  QPLL_RESET <= '0';
586  end if;
587  elsif not RX_QPLL_USED and TX_QPLL_USED then
588  if (pll_reset_asserted = '0' and refclk_lost = '0') then
589  CPLL_RESET <= '1';
590  pll_reset_asserted <= '1';
591  else
592  CPLL_RESET <= '0';
593  end if;
594  end if;
595 
596  RXUSERRDY <= '0';
597  gtrxreset_i <= '1';
598  mmcm_reset_i <= '1';
599  run_phase_alignment_int <= '0';
600  RESET_PHALIGNMENT <= '1';
601  check_tlock_max <= '0';
602  recclk_mon_count_reset <= '1';
603  adapt_count_reset <= '1';
604 
605  if (RX_QPLL_USED and not TX_QPLL_USED and (qplllock_sync = '0') and pll_reset_asserted = '1' ) or
606  (not RX_QPLL_USED and TX_QPLL_USED and (cplllock_sync = '0') and pll_reset_asserted = '1' ) or
607  (not RX_QPLL_USED and not TX_QPLL_USED ) or
608  (RX_QPLL_USED and TX_QPLL_USED ) then
609  rx_state <= WAIT_FOR_PLL_LOCK;
610  reset_time_out <= '1';
611  end if;
612 
613  when WAIT_FOR_PLL_LOCK =>
614  if(wait_time_done = '1') then
615  rx_state <= RELEASE_PLL_RESET;
616  end if;
617 
618  when RELEASE_PLL_RESET =>
619  --PLL-Reset of the GTX gets released and the time-out counter
620  --starts running.
621  pll_reset_asserted <= '0';
622  reset_time_out <= '0';
623 
624  if (RX_QPLL_USED and not TX_QPLL_USED and (qplllock_sync = '1')) or
625  (not RX_QPLL_USED and TX_QPLL_USED and (cplllock_sync = '1')) then
626  rx_state <= VERIFY_RECCLK_STABLE;
627  reset_time_out <= '1';
628  recclk_mon_count_reset <= '0';
629  adapt_count_reset <= '0';
630  elsif (RX_QPLL_USED and (qplllock_sync = '1')) or
631  (not RX_QPLL_USED and (cplllock_sync = '1')) then
632  rx_state <= VERIFY_RECCLK_STABLE;
633  reset_time_out <= '1';
634  recclk_mon_count_reset <= '0';
635  adapt_count_reset <= '0';
636  end if;
637 
638  if time_out_2ms = '1' then
639  if retry_counter_int = MAX_RETRIES then
640  -- If too many retries are performed compared to what is specified in
641  -- the generic, the counter simply wraps around.
642  retry_counter_int <= 0;
643  else
644  retry_counter_int <= retry_counter_int + 1;
645  end if;
646  rx_state <= ASSERT_ALL_RESETS;
647  end if;
648 
649  when VERIFY_RECCLK_STABLE =>
650  --reset_time_out <= '0';
651  --Time-out counter is not released in this state as here the FSM
652  --does not wait for a certain period of time but checks on the number
653  --of retries in the RECCLK monitor
654  gtrxreset_i <= '0';
655  if RECCLK_STABLE = '1' then
656  rx_state <= RELEASE_MMCM_RESET;
657  reset_time_out <= '1';
658 
659  end if;
660 
661  if recclk_mon_restart_count = 2 then
662  --If two retries are performed in the RECCLK monitor
663  --the whole initialisation-sequence gets restarted.
664  if retry_counter_int = MAX_RETRIES then
665  -- If too many retries are performed compared to what is specified in
666  -- the generic, the counter simply wraps around.
667  retry_counter_int <= 0;
668  else
669  retry_counter_int <= retry_counter_int + 1;
670  end if;
671  rx_state <= ASSERT_ALL_RESETS;
672  end if;
673 
674  when RELEASE_MMCM_RESET =>
675  --Release of the MMCM-reset. Waiting for the MMCM to lock.
676  check_tlock_max <= '1';
677 
678  mmcm_reset_i <= '0';
679  reset_time_out <= '0';
680 
681  if mmcm_lock_reclocked = '1' then
682  rx_state <= WAIT_FOR_RXUSRCLK;
683  reset_time_out <= '1';
684  end if;
685 
686  if (time_tlock_max = '1' and reset_time_out = '0' )then
687  if retry_counter_int = MAX_RETRIES then
688  -- If too many retries are performed compared to what is specified in
689  -- the generic, the counter simply wraps around.
690  retry_counter_int <= 0;
691  else
692  retry_counter_int <= retry_counter_int + 1;
693  end if;
694  rx_state <= ASSERT_ALL_RESETS;
695  end if;
696 
697  when WAIT_FOR_RXUSRCLK =>
698  if wait_time_done = '1' then
699  rx_state <= WAIT_RESET_DONE;
700  end if;
701 
702  when WAIT_RESET_DONE =>
703  --When TXOUTCLK is the source for RXUSRCLK, RXUSERRDY depends on TXUSERRDY
704  --If RXOUTCLK is the source for RXUSRCLK, TXUSERRDY can be tied to '1'
705  if TXUSERRDY = '1' then
706  RXUSERRDY <= '1';
707  end if;
708  reset_time_out <= '0';
709  if rxresetdone_s3 = '1' then
710  rx_state <= DO_PHASE_ALIGNMENT;
711  reset_time_out <= '1';
712  end if;
713 
714  if time_out_2ms = '1' and reset_time_out = '0' then
715  if retry_counter_int = MAX_RETRIES then
716  -- If too many retries are performed compared to what is specified in
717  -- the generic, the counter simply wraps around.
718  retry_counter_int <= 0;
719  else
720  retry_counter_int <= retry_counter_int + 1;
721  end if;
722  rx_state <= ASSERT_ALL_RESETS;
723  end if;
724 
725  when DO_PHASE_ALIGNMENT =>
726  --The direct handling of the signals for the Phase Alignment is done outside
727  --this state-machine.
728  RESET_PHALIGNMENT <= '0';
729  run_phase_alignment_int <= '1';
730  reset_time_out <= '0';
731 
732  if PHALIGNMENT_DONE = '1' then
733  rx_state <= MONITOR_DATA_VALID;
734  reset_time_out <= '1';
735  end if;
736 
737  if time_out_wait_bypass_s3 = '1' then
738  if retry_counter_int = MAX_RETRIES then
739  -- If too many retries are performed compared to what is specified in
740  -- the generic, the counter simply wraps around.
741  retry_counter_int <= 0;
742  else
743  retry_counter_int <= retry_counter_int + 1;
744  end if;
745  rx_state <= ASSERT_ALL_RESETS;
746  end if;
747 
748  when MONITOR_DATA_VALID =>
749  reset_time_out <= '0';
750 
751  if(time_out_100us = '1' and data_valid_sync ='0' and DONT_RESET_ON_DATA_ERROR = '0' and reset_time_out = '0') then
752  rx_state <= ASSERT_ALL_RESETS;
753  rx_fsm_reset_done_int <= '0';
754  elsif (data_valid_sync = '1') then
755  rx_state <= FSM_DONE;
756  rx_fsm_reset_done_int <= '0';
757  reset_time_out <= '1';
758  end if;
759 
760  when FSM_DONE =>
761  reset_time_out <= '0';
762  if data_valid_sync = '0' then
763  rx_fsm_reset_done_int <= '0';
764  reset_time_out <= '1';
765  rx_state <= MONITOR_DATA_VALID;
766 
767  elsif(time_out_1us = '1' and reset_time_out = '0') then
768  rx_fsm_reset_done_int <= '1';
769  end if;
770 
771  if(time_out_adapt = '1') then
772  if(EQ_MODE = "DFE") then
773  RXDFEAGCHOLD <= '1';
774  RXDFELFHOLD <= '1';
775  RXLPMHFHOLD <= '0';
776  RXLPMLFHOLD <= '0';
777  else
778  RXDFEAGCHOLD <= '0';
779  RXDFELFHOLD <= '0';
780  RXLPMHFHOLD <= '0';
781  RXLPMLFHOLD <= '0';
782  end if;
783  end if;
784  when OTHERS =>
785  rx_state <= INIT;
786  end case;
787  end if;
788  end if;
789  end process;
790 
791 end RTL;
792