1 --////////////////////////////////////////////////////////////////////////////////
4 --// /___/ \ / Vendor: Xilinx
5 --// \ \ \/ Version : 2.
5
6 --// \ \ Application : 7 Series FPGAs Transceivers Wizard
7 --// / / Filename :s6link_tx_startup_fsm.vhd
13 -- Description : This module performs TX reset and initialization.
17 -- Module S6Link_tx_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( GT_TYPE : := "GTX";
76 STABLE_CLOCK_PERIOD : range 4 to 20 := 8;
--Period of the stable clock driving this state-machine, unit is [ns]
77 RETRY_COUNTER_BITWIDTH : range 2 to 8 := 8;
78 TX_QPLL_USED : := False;
-- the TX and RX Reset FSMs must
79 RX_QPLL_USED : := False;
-- share these two generic values
80 PHASE_ALIGNMENT_MANUAL : := True -- Decision if a manual phase-alignment is necessary or the automatic
81 -- is enough. For single-lane applications the automatic alignment is
84 Port ( STABLE_CLOCK : in ;
--Stable Clock, either a stable clock from the PCB
85 --or reference-clock present at startup.
86 TXUSERCLK : in ;
--TXUSERCLK as used in the design
87 SOFT_RESET : in ;
--User Reset, can be pulled any
88 QPLLREFCLKLOST : in ;
--QPLL Reference-clock for the GT is lost
89 CPLLREFCLKLOST : in ;
--CPLL Reference-clock for the GT is lost
90 QPLLLOCK : in ;
--Lock Detect from the QPLL of the GT
91 CPLLLOCK : in ;
--Lock Detect from the CPLL of the GT
94 GTTXRESET : out :='0';
95 MMCM_RESET : out :='1';
96 QPLL_RESET : out :='0';
--Reset QPLL
97 CPLL_RESET : out :='0';
--Reset CPLL
98 TX_FSM_RESET_DONE : out ;
--Reset-sequence has sucessfully been finished.
99 TXUSERRDY : out :='0';
100 RUN_PHALIGNMENT : out :='0';
101 RESET_PHALIGNMENT : out :='0';
102 PHALIGNMENT_DONE : in ;
104 RETRY_COUNTER : out (RETRY_COUNTER_BITWIDTH-1 downto 0):=(others=>'0')-- Number of
105 -- Retries it took to get the transceiver up and running
107 end S6Link_TX_STARTUP_FSM;
110 -- * Timing depends on the frequency of the stable clock. Hence counters-sizes
111 -- are calculated at design-time based on the Generics
113 -- * if either of PLLs is reset during TX-startup, it does not need to be reset again by RX
114 -- => signal which PLL has been reset
121 type tx_rst_fsm_type is(
122 INIT, ASSERT_ALL_RESETS, RELEASE_PLL_RESET,
123 RELEASE_MMCM_RESET, WAIT_RESET_DONE, DO_PHASE_ALIGNMENT,
126 signal tx_state : tx_rst_fsm_type := INIT;
128 constant MMCM_LOCK_CNT_MAX : := 1024;
129 constant STARTUP_DELAY : := 500;
--AR43482: Transceiver needs to wait for 500 ns
after configuration
130 constant WAIT_CYCLES : := STARTUP_DELAY / STABLE_CLOCK_PERIOD;
-- Number of Clock-Cycles to wait after configuration
131 constant WAIT_MAX : := WAIT_CYCLES + 10;
-- 500 ns plus some additional margin
133 constant WAIT_TIMEOUT_2ms : := 2000000 / STABLE_CLOCK_PERIOD;
-- 2 ms time-out
134 constant WAIT_TLOCK_MAX : := 100000 / STABLE_CLOCK_PERIOD;
--100 us time-out
135 constant WAIT_TIMEOUT_500us : := 500000 / STABLE_CLOCK_PERIOD;
--100 us time-out
137 signal init_wait_count : range 0 to WAIT_MAX:=0;
138 signal init_wait_done : := '0';
139 signal pll_reset_asserted : := '0';
141 signal tx_fsm_reset_done_int : := '0';
142 signal tx_fsm_reset_done_int_s1 : := '0';
143 signal tx_fsm_reset_done_int_s2 : := '0';
144 signal tx_fsm_reset_done_int_s3 : := '0';
146 signal txresetdone_s1 : := '0';
147 signal txresetdone_s2 : := '0';
148 signal txresetdone_s3 : := '0';
150 constant MAX_RETRIES : := 2**RETRY_COUNTER_BITWIDTH-1;
151 signal retry_counter_int : range 0 to MAX_RETRIES;
152 signal time_out_counter : range 0 to WAIT_TIMEOUT_2ms := 0;
154 signal reset_time_out : := '0';
155 signal time_out_2ms : := '0';
--\Flags that the various time-out points
156 signal time_tlock_max : := '0';
--|have been reached.
157 signal time_out_500us : := '0';
--/
159 signal mmcm_lock_count : range 0 to MMCM_LOCK_CNT_MAX-1:=0;
160 signal mmcm_lock_int : := '0';
161 signal mmcm_lock_reclocked : (3 downto 0) := (others=>'0');
163 signal run_phase_alignment_int : := '0';
164 signal run_phase_alignment_int_s1 : := '0';
165 signal run_phase_alignment_int_s2 : := '0';
166 signal run_phase_alignment_int_s3 : := '0';
168 constant MAX_WAIT_BYPASS : := 110000;
--110000 TXUSRCLK cycles is the max for Multi lane designs
169 signal wait_bypass_count : range 0 to MAX_WAIT_BYPASS-1;
170 signal time_out_wait_bypass : := '0';
171 signal time_out_wait_bypass_s1 : := '0';
172 signal time_out_wait_bypass_s2 : := '0';
173 signal time_out_wait_bypass_s3 : := '0';
174 signal refclk_lost : ;
177 --Alias section, signals used within this module mapped to output ports:
178 RETRY_COUNTER <= (TO_UNSIGNED(retry_counter_int,RETRY_COUNTER_BITWIDTH));
179 RUN_PHALIGNMENT <= run_phase_alignment_int;
180 TX_FSM_RESET_DONE <= tx_fsm_reset_done_int;
182 process(STABLE_CLOCK)
184 if rising_edge(STABLE_CLOCK) then
185 -- The counter starts running when configuration has finished and
186 -- the clock is stable. When its maximum count-value has been reached,
187 -- the 500 ns from Answer
Record 43482 have been passed.
188 if init_wait_count = WAIT_MAX then
189 init_wait_done <= '1';
191 init_wait_count <= init_wait_count + 1;
197 timeouts:
process(STABLE_CLOCK)
199 if rising_edge(STABLE_CLOCK) then
200 -- One common large counter for generating three time-out signals.
201 -- Intermediate time-outs are derived from calculated values, based
202 -- on the period of the provided clock.
203 if reset_time_out = '1' then
204 time_out_counter <= 0;
206 time_tlock_max <= '0';
207 time_out_500us <= '0';
209 if time_out_counter = WAIT_TIMEOUT_2ms then
212 time_out_counter <= time_out_counter + 1;
215 if time_out_counter = WAIT_TLOCK_MAX then
216 time_tlock_max <= '1';
219 if time_out_counter = WAIT_TIMEOUT_500us then
220 time_out_500us <= '1';
226 mmcm_lock_wait:
process(TXUSERCLK)
228 if rising_edge(TXUSERCLK) then
229 if MMCM_LOCK = '0' then
230 mmcm_lock_count <= 0;
231 mmcm_lock_int <= '0';
233 if mmcm_lock_count < MMCM_LOCK_CNT_MAX - 1 then
234 mmcm_lock_count <= mmcm_lock_count + 1;
236 mmcm_lock_int <= '1';
242 reclocking:
process(STABLE_CLOCK)
243 --Reclocking onto the FSM-clock.
245 if rising_edge(STABLE_CLOCK) then
246 if MMCM_LOCK = '0' then
247 --The reset-signal is here on purpose. This avoids
248 --getting the shift-register targetted to an SRL.
249 --The reason for this is that an SRL will not help
250 --on the cross-clock domain but "real" Flip-flops will.
252 mmcm_lock_reclocked <= (others => '0');
254 mmcm_lock_reclocked(3) <= mmcm_lock_int;
255 mmcm_lock_reclocked(2 downto 0) <= mmcm_lock_reclocked(3 downto 1);
261 -- Clock Domain Crossing
264 if rising_edge(TXUSERCLK) then
265 run_phase_alignment_int_s1 <= run_phase_alignment_int;
266 run_phase_alignment_int_s2 <= run_phase_alignment_int_s1;
267 run_phase_alignment_int_s3 <= run_phase_alignment_int_s2;
269 tx_fsm_reset_done_int_s1 <= tx_fsm_reset_done_int;
270 tx_fsm_reset_done_int_s2 <= tx_fsm_reset_done_int_s1;
271 tx_fsm_reset_done_int_s3 <= tx_fsm_reset_done_int_s2;
275 process(STABLE_CLOCK)
277 if rising_edge(STABLE_CLOCK) then
278 txresetdone_s1 <= TXRESETDONE;
279 txresetdone_s2 <= txresetdone_s1;
280 txresetdone_s3 <= txresetdone_s2;
282 time_out_wait_bypass_s1 <= time_out_wait_bypass;
283 time_out_wait_bypass_s2 <= time_out_wait_bypass_s1;
284 time_out_wait_bypass_s3 <= time_out_wait_bypass_s2;
289 timeout_buffer_bypass:
process(TXUSERCLK)
291 if rising_edge(TXUSERCLK) then
292 if run_phase_alignment_int_s3 = '0' then
293 wait_bypass_count <= 0;
294 time_out_wait_bypass <= '0';
295 elsif (run_phase_alignment_int_s3 = '1') and (tx_fsm_reset_done_int_s3 = '0') then
296 if wait_bypass_count = MAX_WAIT_BYPASS - 1 then
297 time_out_wait_bypass <= '1';
299 wait_bypass_count <= wait_bypass_count + 1;
305 refclk_lost <= '1' when ((TX_QPLL_USED and QPLLREFCLKLOST='1') or (not TX_QPLL_USED and CPLLREFCLKLOST='1')) else '0';
308 --FSM for resetting the GTX/GTH/GTP in the 7-series.
309 --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311 -- Following steps are performed:
312 -- 1) Only
for GTX -
After configuration wait for approximately
500 ns as specified
in
313 -- answer-record 43482
314 -- 2)
Assert all resets
on the GT
and on an MMCM potentially connected.
315 -- After that wait until a reference-clock has been detected.
316 -- 3)
Release the reset
to the GT
and wait until the GT-PLL has locked.
317 -- 4)
Release the MMCM-reset
and wait until the MMCM has signalled lock.
318 -- Also signal to the RX-side which PLL has been reset.
319 -- 5)
Wait for the RESET_DONE-signal from the GT.
320 -- 6)
Signal to start the phase-alignment
procedure and wait for it
to
322 -- 7) Reset-sequence has successfully run through.
Signal this
to the
323 -- rest of the design by asserting TX_FSM_RESET_DONE.
325 reset_fsm:
process(STABLE_CLOCK)
327 if rising_edge(STABLE_CLOCK) then
328 if(SOFT_RESET = '1' or (not(tx_state = INIT) and not(tx_state = ASSERT_ALL_RESETS) and refclk_lost = '1')) then
333 tx_fsm_reset_done_int <= '0';
336 pll_reset_asserted <= '0';
337 reset_time_out <= '0';
338 retry_counter_int <= 0;
339 run_phase_alignment_int <= '0';
340 RESET_PHALIGNMENT <= '1';
345 --Initial state after configuration. This state will be left after
346 --approx. 500 ns
and not be re-entered.
347 if init_wait_done = '1' then
348 tx_state <= ASSERT_ALL_RESETS;
349 reset_time_out <= '1';
352 when ASSERT_ALL_RESETS =>
353 --This is the state into which the FSM will always jump back if any
354 --time-outs will occur.
355 --The number of retries is reported on the output RETRY_COUNTER. In
356 --case the transceiver never comes up for some reason, this machine
357 --will still continue its best and rerun until the FPGA is turned off
358 --or the transceivers come up correctly.
360 if pll_reset_asserted = '0' then
362 pll_reset_asserted <= '1';
367 if pll_reset_asserted = '0' then
369 pll_reset_asserted <= '1';
377 reset_time_out <= '0';
378 run_phase_alignment_int <= '0';
379 RESET_PHALIGNMENT <= '1';
381 if (TX_QPLL_USED and (QPLLREFCLKLOST = '0') and pll_reset_asserted = '1') or
382 (not TX_QPLL_USED and (CPLLREFCLKLOST = '0') and pll_reset_asserted = '1') then
383 tx_state <= RELEASE_PLL_RESET;
386 when RELEASE_PLL_RESET =>
387 --PLL-Reset of the GTX gets released and the time-out counter
389 pll_reset_asserted <= '1';
391 if (TX_QPLL_USED and (QPLLLOCK = '1')) or
392 (not TX_QPLL_USED and (CPLLLOCK = '1')) then
393 tx_state <= RELEASE_MMCM_RESET;
394 reset_time_out <= '1';
397 if time_out_2ms = '1' then
398 if retry_counter_int = MAX_RETRIES then
399 -- If too many retries are performed compared to what is specified in
400 -- the generic, the counter simply wraps around.
401 retry_counter_int <= 0;
403 retry_counter_int <= retry_counter_int + 1;
405 tx_state <= ASSERT_ALL_RESETS;
408 when RELEASE_MMCM_RESET =>
410 reset_time_out <= '0';
411 --Release of the MMCM-reset. Waiting for the MMCM to lock.
413 if mmcm_lock_reclocked(0) = '1' then
414 tx_state <= WAIT_RESET_DONE;
415 reset_time_out <= '1';
418 if time_tlock_max = '1' and mmcm_lock_reclocked(0) = '0' then
419 if retry_counter_int = MAX_RETRIES then
420 -- If too many retries are performed compared to what is specified in
421 -- the generic, the counter simply wraps around.
422 retry_counter_int <= 0;
424 retry_counter_int <= retry_counter_int + 1;
426 tx_state <= ASSERT_ALL_RESETS;
429 when WAIT_RESET_DONE =>
431 reset_time_out <= '0';
432 if txresetdone_s3 = '1' then
433 tx_state <= DO_PHASE_ALIGNMENT;
434 reset_time_out <= '1';
437 if time_out_500us = '1' then
438 if retry_counter_int = MAX_RETRIES then
439 -- If too many retries are performed compared to what is specified in
440 -- the generic, the counter simply wraps around.
441 retry_counter_int <= 0;
443 retry_counter_int <= retry_counter_int + 1;
445 tx_state <= ASSERT_ALL_RESETS;
448 when DO_PHASE_ALIGNMENT =>
449 --The direct handling of the signals for the Phase Alignment is done outside
450 --this state-machine.
451 RESET_PHALIGNMENT <= '0';
452 run_phase_alignment_int <= '1';
453 reset_time_out <= '0';
455 if PHALIGNMENT_DONE = '1' then
456 tx_state <= RESET_FSM_DONE;
459 if time_out_wait_bypass_s3 = '1' then
460 if retry_counter_int = MAX_RETRIES then
461 -- If too many retries are performed compared to what is specified in
462 -- the generic, the counter simply wraps around.
463 retry_counter_int <= 0;
465 retry_counter_int <= retry_counter_int + 1;
467 tx_state <= ASSERT_ALL_RESETS;
470 when RESET_FSM_DONE =>
471 reset_time_out <= '1';
472 tx_fsm_reset_done_int <= '1';