1 --////////////////////////////////////////////////////////////////////////////////
4 --// /___/ \ / Vendor: Xilinx
5 --// \ \ \/ Version : 2.
5
6 --// \ \ Application : 7 Series FPGAs Transceivers Wizard
7 --// / / Filename : s6link_rx_startup_fsm.vhd
13 -- Description : This module performs RX reset and initialization.
17 -- Module S6Link_rx_startup_fsm
18 -- Generated by Xilinx 7 Series FPGAs Transceivers Wizard
21 -- (c) Copyright 2010-2012 Xilinx, Inc. All rights reserved.
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
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.
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.
64 -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
65 -- PART OF THIS FILE AT ALL TIMES.
68 --*****************************************************************************
71 use IEEE.STD_LOGIC_1164.
ALL;
72 use IEEE.NUMERIC_STD.
ALL;
75 Generic( EXAMPLE_SIMULATION : := 0;
77 EQ_MODE : := "DFE";
--RX Equalisation Mode; set to DFE or LPM
78 STABLE_CLOCK_PERIOD : range 4 to 20 := 8;
--Period of the stable clock driving this state-machine, unit is [ns]
79 RETRY_COUNTER_BITWIDTH : range 2 to 8 := 8;
80 TX_QPLL_USED : := False;
-- the TX and RX Reset FSMs must
81 RX_QPLL_USED : := False;
-- share these two generic values
82 PHASE_ALIGNMENT_MANUAL : := True -- Decision if a manual phase-alignment is necessary or the automatic
83 -- is enough. For single-lane applications the automatic alignment is
86 Port ( STABLE_CLOCK : in ;
--Stable Clock, either a stable clock from the PCB
87 --or reference-clock present at startup.
88 RXUSERCLK : in ;
--RXUSERCLK as used in the design
89 SOFT_RESET : in ;
--User Reset, can be pulled any
90 QPLLREFCLKLOST : in ;
--QPLL Reference-clock for the GT is lost
91 CPLLREFCLKLOST : in ;
--CPLL Reference-clock for the GT is lost
92 QPLLLOCK : in ;
--Lock Detect from the QPLL of the GT
93 CPLLLOCK : in ;
--Lock Detect from the CPLL of the GT
97 RECCLK_MONITOR_RESTART : in :='0';
99 TXUSERRDY : in ;
--TXUSERRDY from GT
100 GTRXRESET : out :='0';
101 MMCM_RESET : out :='1';
102 QPLL_RESET : out :='0';
--Reset QPLL (only if RX uses QPLL)
103 CPLL_RESET : out :='0';
--Reset CPLL (only if RX uses CPLL)
104 RX_FSM_RESET_DONE : out ;
--Reset-sequence has sucessfully been finished.
105 RXUSERRDY : out :='0';
106 RUN_PHALIGNMENT : out ;
107 PHALIGNMENT_DONE : in ;
108 RESET_PHALIGNMENT : out :='0';
113 RETRY_COUNTER : out (RETRY_COUNTER_BITWIDTH-1 downto 0):=(others=>'0')-- Number of
114 -- Retries it took to get the transceiver up and running
116 end S6Link_RX_STARTUP_FSM;
119 -- * Timing depends on the frequency of the stable clock. Hence counters-sizes
120 -- are calculated at design-time based on the Generics
122 -- * if either of the PLLs is reset during TX-startup, it does not need to be reset again by RX
123 -- => signal which PLL has been reset
129 type rx_rst_fsm_type is(
130 INIT, ASSERT_ALL_RESETS, RELEASE_PLL_RESET, VERIFY_RECCLK_STABLE,
131 RELEASE_MMCM_RESET, WAIT_RESET_DONE, DO_PHASE_ALIGNMENT,
132 MONITOR_DATA_VALID, FSM_DONE);
134 signal rx_state : rx_rst_fsm_type := INIT;
136 constant MMCM_LOCK_CNT_MAX : := 1024;
137 constant STARTUP_DELAY : := 500;
--AR43482: Transceiver needs to wait for 500 ns
after configuration
138 constant WAIT_CYCLES : := STARTUP_DELAY / STABLE_CLOCK_PERIOD;
-- Number of Clock-Cycles to wait after configuration
139 constant WAIT_MAX : := WAIT_CYCLES + 10;
-- 500 ns plus some additional margin
141 constant WAIT_TIMEOUT_2ms : := 2000000 / STABLE_CLOCK_PERIOD;
-- 2 ms time-out
142 constant WAIT_TLOCK_MAX : := 100000 / STABLE_CLOCK_PERIOD;
--100 us time-out
143 constant WAIT_TIMEOUT_500us : := 500000 / STABLE_CLOCK_PERIOD;
--500 us time-out
144 constant WAIT_TIMEOUT_1us : := 1000 / STABLE_CLOCK_PERIOD;
--1 us time-out
145 constant WAIT_TIMEOUT_100us : := 100000 / STABLE_CLOCK_PERIOD;
--100 us time-out
146 constant WAIT_TIME_ADAPT : := (37000000 /(2.
5))/STABLE_CLOCK_PERIOD;
148 signal init_wait_count : range 0 to WAIT_MAX:=0;
149 signal init_wait_done : := '0';
150 signal pll_reset_asserted : := '0';
151 signal rx_fsm_reset_done_int : := '0';
152 signal rx_fsm_reset_done_int_s1 : := '0';
153 signal rx_fsm_reset_done_int_s2 : := '0';
154 signal rx_fsm_reset_done_int_s3 : := '0';
156 signal rxresetdone_s1 : := '0';
157 signal rxresetdone_s2 : := '0';
158 signal rxresetdone_s3 : := '0';
160 constant MAX_RETRIES : := 2**RETRY_COUNTER_BITWIDTH-1;
161 signal retry_counter_int : range 0 to MAX_RETRIES := 0;
162 signal time_out_counter : range 0 to WAIT_TIMEOUT_2ms := 0;
163 signal recclk_mon_restart_count : range 0 to 3:= 0;
164 signal recclk_mon_count_reset : := '0';
166 signal reset_time_out : := '0';
167 signal time_out_2ms : := '0';
--\Flags that the various time-out points
168 signal time_tlock_max : := '0';
--|have been reached.
169 signal time_out_500us : := '0';
--|
170 signal time_out_1us : := '0';
--/
171 signal time_out_100us : := '0';
--/
172 signal check_tlock_max : := '0';
174 signal mmcm_lock_count : range 0 to MMCM_LOCK_CNT_MAX-1:=0;
175 signal mmcm_lock_int : := '0';
176 signal mmcm_lock_reclocked : (3 downto 0) := (others=>'0');
178 signal run_phase_alignment_int: := '0';
179 signal run_phase_alignment_int_s1 : := '0';
180 signal run_phase_alignment_int_s2 : := '0';
181 signal run_phase_alignment_int_s3 : := '0';
183 constant MAX_WAIT_BYPASS : := 5000;
--5000 RXUSRCLK cycles is the max for Multi lanes designs
184 signal wait_bypass_count : range 0 to MAX_WAIT_BYPASS-1;
185 signal time_out_wait_bypass : := '0';
186 signal time_out_wait_bypass_s1 : := '0';
187 signal time_out_wait_bypass_s2 : := '0';
188 signal time_out_wait_bypass_s3 : := '0';
190 signal refclk_lost : ;
192 signal time_out_adapt : := '0';
193 signal adapt_count_reset : := '0';
194 signal adapt_count : range 0 to WAIT_TIME_ADAPT-1;
197 --Alias section, signals used within this module mapped to output ports:
198 RETRY_COUNTER <= (TO_UNSIGNED(retry_counter_int,RETRY_COUNTER_BITWIDTH));
199 RUN_PHALIGNMENT <= run_phase_alignment_int;
200 RX_FSM_RESET_DONE <= rx_fsm_reset_done_int;
202 process(STABLE_CLOCK)
204 if rising_edge(STABLE_CLOCK) then
205 -- The counter starts running when configuration has finished and
206 -- the clock is stable. When its maximum count-value has been reached,
207 -- the 500 ns from Answer
Record 43482 have been passed.
208 if init_wait_count = WAIT_MAX then
209 init_wait_done <= '1';
211 init_wait_count <= init_wait_count + 1;
217 adapt_wait_sim:if(EXAMPLE_SIMULATION = 1) generate
218 time_out_adapt <= '1';
221 adapt_wait_hw:if(EXAMPLE_SIMULATION = 0) generate
222 process(STABLE_CLOCK)
224 if rising_edge(STABLE_CLOCK) then
225 if(adapt_count_reset = '1') then
227 time_out_adapt <= '0';
228 elsif(adapt_count >= WAIT_TIME_ADAPT) then
229 time_out_adapt <= '1';
231 adapt_count <= adapt_count + 1;
237 retries_recclk_monitor:
process(STABLE_CLOCK)
239 --This counter monitors, how many retries the RECCLK monitor
240 --runs. If during startup too many retries are necessary, the whole
241 --initialisation-process of the transceivers gets restarted.
242 if rising_edge(STABLE_CLOCK) then
243 if recclk_mon_count_reset = '1' then
244 recclk_mon_restart_count <= 0;
245 elsif RECCLK_MONITOR_RESTART = '1' then
246 if recclk_mon_restart_count = 3 then
247 recclk_mon_restart_count <= 0;
249 recclk_mon_restart_count <= recclk_mon_restart_count + 1;
255 timeouts:
process(STABLE_CLOCK)
257 if rising_edge(STABLE_CLOCK) then
258 -- One common large counter for generating three time-out signals.
259 -- Intermediate time-outs are derived from calculated values, based
260 -- on the period of the provided clock.
261 if reset_time_out = '1' then
262 time_out_counter <= 0;
264 time_tlock_max <= '0';
265 time_out_500us <= '0';
267 time_out_100us <= '0';
269 if time_out_counter = WAIT_TIMEOUT_2ms then
272 time_out_counter <= time_out_counter + 1;
275 if (time_out_counter > WAIT_TLOCK_MAX) and (check_tlock_max='1') then
276 time_tlock_max <= '1';
279 if time_out_counter = WAIT_TIMEOUT_500us then
280 time_out_500us <= '1';
283 if time_out_counter = WAIT_TIMEOUT_1us then
287 if time_out_counter = WAIT_TIMEOUT_100us then
288 time_out_100us <= '1';
296 mmcm_lock_wait:
process(RXUSERCLK)
298 --The lock-signal from the MMCM is not immediately used but
299 --enabling a counter. Only when the counter hits its maximum,
300 --the MMCM is considered as "really" locked.
301 --The counter avoids that the FSM already starts on only a
302 --coarse lock of the MMCM (=toggling of the LOCK-signal).
303 if rising_edge(RXUSERCLK) then
304 if MMCM_LOCK = '0' then
305 mmcm_lock_count <= 0;
306 mmcm_lock_int <= '0';
308 if mmcm_lock_count < MMCM_LOCK_CNT_MAX - 1 then
309 mmcm_lock_count <= mmcm_lock_count + 1;
311 mmcm_lock_int <= '1';
317 reclocking:
process(STABLE_CLOCK)
318 --Reclocking onto the FSM-clock.
320 if rising_edge(STABLE_CLOCK) then
321 if MMCM_LOCK = '0' then
322 --The reset-signal is here on purpose. This avoids
323 --getting the shift-register targetted to an SRL.
324 --The reason for this is that an SRL will not help
325 --on the cross-clock domain but "real" Flip-flops will.
327 mmcm_lock_reclocked <= (others => '0');
329 mmcm_lock_reclocked(3) <= mmcm_lock_int;
330 mmcm_lock_reclocked(2 downto 0) <= mmcm_lock_reclocked(3 downto 1);
335 -- Clock Domain Crossing
338 if rising_edge(RXUSERCLK) then
339 run_phase_alignment_int_s1 <= run_phase_alignment_int;
340 run_phase_alignment_int_s2 <= run_phase_alignment_int_s1;
341 run_phase_alignment_int_s3 <= run_phase_alignment_int_s2;
343 rx_fsm_reset_done_int_s1 <= rx_fsm_reset_done_int;
344 rx_fsm_reset_done_int_s2 <= rx_fsm_reset_done_int_s1;
345 rx_fsm_reset_done_int_s3 <= rx_fsm_reset_done_int_s2;
349 process(STABLE_CLOCK)
351 if rising_edge(STABLE_CLOCK) then
352 rxresetdone_s1 <= RXRESETDONE;
353 rxresetdone_s2 <= rxresetdone_s1;
354 rxresetdone_s3 <= rxresetdone_s2;
356 time_out_wait_bypass_s1 <= time_out_wait_bypass;
357 time_out_wait_bypass_s2 <= time_out_wait_bypass_s1;
358 time_out_wait_bypass_s3 <= time_out_wait_bypass_s2;
363 timeout_buffer_bypass:
process(RXUSERCLK)
365 if rising_edge(RXUSERCLK) then
366 if run_phase_alignment_int_s3 = '0' then
367 wait_bypass_count <= 0;
368 time_out_wait_bypass <= '0';
369 elsif (run_phase_alignment_int_s3 = '1') and (rx_fsm_reset_done_int_s3 = '0') then
370 if wait_bypass_count = MAX_WAIT_BYPASS - 1 then
371 time_out_wait_bypass <= '1';
373 wait_bypass_count <= wait_bypass_count + 1;
379 refclk_lost <= '1' when ((RX_QPLL_USED and QPLLREFCLKLOST='1') or (not RX_QPLL_USED and CPLLREFCLKLOST='1')) else '0';
383 --FSM for resetting the GTX/GTH/GTP in the 7-series.
384 --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
386 -- Following steps are performed:
387 -- 1)
After configuration wait for approximately
500 ns as specified
in
388 -- answer-record 43482
389 -- 2)
Assert all resets
on the GT
and on an MMCM potentially connected.
390 -- After that wait until a reference-clock has been detected.
391 -- 3)
Release the reset
to the GT
and wait until the GT-PLL has locked.
392 -- 4)
Release the MMCM-reset
and wait until the MMCM has signalled lock.
393 -- Also get info from the TX-side which PLL has been reset.
394 -- 5)
Wait for the RESET_DONE-signal from the GT.
395 -- 6)
Signal to start the phase-alignment
procedure and wait for it
to
397 -- 7) Reset-sequence has successfully run through.
Signal this
to the
398 -- rest of the design by asserting RX_FSM_RESET_DONE.
400 reset_fsm:
process(STABLE_CLOCK)
402 if rising_edge(STABLE_CLOCK) then
403 if (SOFT_RESET = '1' or (not(rx_state = INIT) and not(rx_state = ASSERT_ALL_RESETS) and refclk_lost = '1')) then
408 rx_fsm_reset_done_int <= '0';
411 pll_reset_asserted <= '0';
412 reset_time_out <= '1';
413 retry_counter_int <= 0;
414 run_phase_alignment_int <= '0';
415 check_tlock_max <= '0';
416 RESET_PHALIGNMENT <= '1';
417 recclk_mon_count_reset <= '1';
418 adapt_count_reset <= '1';
428 --Initial state after configuration. This state will be left after
429 --approx. 500 ns
and not be re-entered.
430 if init_wait_done = '1' then
431 rx_state <= ASSERT_ALL_RESETS;
434 when ASSERT_ALL_RESETS =>
435 --This is the state into which the FSM will always jump back if any
436 --time-outs will occur.
437 --The number of retries is reported on the output RETRY_COUNTER. In
438 --case the transceiver never comes up for some reason, this machine
439 --will still continue its best and rerun until the FPGA is turned off
440 --or the transceivers come up correctly.
441 if RX_QPLL_USED and not TX_QPLL_USED then
442 if pll_reset_asserted = '0' then
444 pll_reset_asserted <= '1';
448 elsif not RX_QPLL_USED and TX_QPLL_USED then
449 if pll_reset_asserted = '0' then
451 pll_reset_asserted <= '1';
460 run_phase_alignment_int <= '0';
461 RESET_PHALIGNMENT <= '1';
462 check_tlock_max <= '0';
463 recclk_mon_count_reset <= '1';
464 adapt_count_reset <= '1';
467 if (RX_QPLL_USED and (QPLLREFCLKLOST = '0') and pll_reset_asserted = '1') or
468 (not RX_QPLL_USED and TX_QPLL_USED and (CPLLREFCLKLOST = '0') and pll_reset_asserted = '1') or
469 (not RX_QPLL_USED and not TX_QPLL_USED and (CPLLREFCLKLOST = '0') ) or
470 (RX_QPLL_USED and TX_QPLL_USED and (QPLLREFCLKLOST = '0') ) then
471 rx_state <= RELEASE_PLL_RESET;
472 reset_time_out <= '1';
475 when RELEASE_PLL_RESET =>
476 --PLL-Reset of the GTX gets released and the time-out counter
478 pll_reset_asserted <= '0';
479 reset_time_out <= '0';
482 if (RX_QPLL_USED and (QPLLLOCK = '1')) or
483 (not RX_QPLL_USED and (CPLLLOCK = '1')) then
484 rx_state <= VERIFY_RECCLK_STABLE;
485 reset_time_out <= '1';
486 recclk_mon_count_reset <= '0';
487 adapt_count_reset <= '0';
490 if time_out_2ms = '1' then
491 if retry_counter_int = MAX_RETRIES then
492 -- If too many retries are performed compared to what is specified in
493 -- the generic, the counter simply wraps around.
494 retry_counter_int <= 0;
496 retry_counter_int <= retry_counter_int + 1;
498 rx_state <= ASSERT_ALL_RESETS;
501 when VERIFY_RECCLK_STABLE =>
502 --reset_time_out <= '0';
503 --Time-out counter is not released in this state as here the FSM
504 --does not wait for a certain period of but checks on the number
505 --of retries in the RECCLK monitor
507 if RECCLK_STABLE = '1' then
508 rx_state <= RELEASE_MMCM_RESET;
509 reset_time_out <= '1';
513 if recclk_mon_restart_count = 2 then
514 --If two retries are performed in the RECCLK monitor
515 --the whole initialisation-sequence gets restarted.
516 if retry_counter_int = MAX_RETRIES then
517 -- If too many retries are performed compared to what is specified in
518 -- the generic, the counter simply wraps around.
519 retry_counter_int <= 0;
521 retry_counter_int <= retry_counter_int + 1;
523 rx_state <= ASSERT_ALL_RESETS;
526 when RELEASE_MMCM_RESET =>
527 --Release of the MMCM-reset. Waiting for the MMCM to lock.
528 reset_time_out <= '0';
529 check_tlock_max <= '1';
532 if mmcm_lock_reclocked(0) = '1' then
533 rx_state <= WAIT_RESET_DONE;
534 reset_time_out <= '1';
537 if time_tlock_max = '1' then
538 if retry_counter_int = MAX_RETRIES then
539 -- If too many retries are performed compared to what is specified in
540 -- the generic, the counter simply wraps around.
541 retry_counter_int <= 0;
543 retry_counter_int <= retry_counter_int + 1;
545 rx_state <= ASSERT_ALL_RESETS;
548 when WAIT_RESET_DONE =>
549 --When TXOUTCLK is the source for RXUSRCLK, RXUSERRDY depends on TXUSERRDY
550 --If RXOUTCLK is the source for RXUSRCLK, TXUSERRDY can be tied to '1'
551 if TXUSERRDY = '1' then
554 reset_time_out <= '0';
555 if rxresetdone_s3 = '1' then
556 rx_state <= DO_PHASE_ALIGNMENT;
557 reset_time_out <= '1';
560 if time_out_2ms = '1' then
561 if retry_counter_int = MAX_RETRIES then
562 -- If too many retries are performed compared to what is specified in
563 -- the generic, the counter simply wraps around.
564 retry_counter_int <= 0;
566 retry_counter_int <= retry_counter_int + 1;
568 rx_state <= ASSERT_ALL_RESETS;
571 when DO_PHASE_ALIGNMENT =>
572 --The direct handling of the signals for the Phase Alignment is done outside
573 --this state-machine.
574 RESET_PHALIGNMENT <= '0';
575 run_phase_alignment_int <= '1';
576 reset_time_out <= '0';
578 if PHALIGNMENT_DONE = '1' then
579 rx_state <= MONITOR_DATA_VALID;
580 reset_time_out <= '1';
583 if time_out_wait_bypass_s3 = '1' then
584 if retry_counter_int = MAX_RETRIES then
585 -- If too many retries are performed compared to what is specified in
586 -- the generic, the counter simply wraps around.
587 retry_counter_int <= 0;
589 retry_counter_int <= retry_counter_int + 1;
591 rx_state <= ASSERT_ALL_RESETS;
594 when MONITOR_DATA_VALID =>
595 reset_time_out <= '0';
597 if(time_out_100us = '1' and DATA_VALID ='0') then
598 rx_state <= ASSERT_ALL_RESETS;
599 rx_fsm_reset_done_int <= '0';
600 elsif (DATA_VALID = '1') then
601 rx_state <= FSM_DONE;
602 rx_fsm_reset_done_int <= '0';
603 reset_time_out <= '1';
607 reset_time_out <= '0';
608 if DATA_VALID = '0' then
609 rx_fsm_reset_done_int <= '0';
610 reset_time_out <= '1';
611 rx_state <= MONITOR_DATA_VALID;
612 elsif(time_out_1us = '1') then
613 rx_fsm_reset_done_int <= '1';
616 if(time_out_adapt = '1') then
617 if((GT_TYPE = "GTX" or GT_TYPE = "GTH") and EQ_MODE = "DFE") then
620 elsif(GT_TYPE = "GTH" and EQ_MODE = "LPM") then