1 --//////////////////////////////////////////////////////////////////////////////
4 -- /___/ \ / Vendor: Xilinx
5 -- \ \ \/ Version : 3.
6
6 -- \ \ Application : 7 Series FPGAs Transceivers Wizard
7 -- / / Filename :amc_gtx5gpd_tx_startup_fsm.vhd
13 -- Description : This module performs TX reset and initialization.
17 -- Module amc_gtx5Gpd_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;
76 EXAMPLE_SIMULATION : := 0;
77 STABLE_CLOCK_PERIOD : range 4 to 250 := 8;
--Period of the stable clock driving this state-machine, unit is [ns]
78 RETRY_COUNTER_BITWIDTH : range 2 to 8 := 8;
79 TX_QPLL_USED : := False;
-- the TX and RX Reset FSMs must
80 RX_QPLL_USED : := False;
-- share these two generic values
81 PHASE_ALIGNMENT_MANUAL : := True -- Decision if a manual phase-alignment is necessary or the automatic
82 -- is enough. For single-lane applications the automatic alignment is
85 Port ( STABLE_CLOCK : in ;
--Stable Clock, either a stable clock from the PCB
86 --or reference-clock present at startup.
87 TXUSERCLK : in ;
--TXUSERCLK as used in the design
88 SOFT_RESET : in ;
--User Reset, can be pulled any
89 QPLLREFCLKLOST : in ;
--QPLL Reference-clock for the GT is lost
90 CPLLREFCLKLOST : in ;
--CPLL Reference-clock for the GT is lost
91 QPLLLOCK : in ;
--Lock Detect from the QPLL of the GT
92 CPLLLOCK : in ;
--Lock Detect from the CPLL of the GT
96 MMCM_RESET : out :='1';
97 QPLL_RESET : out :='0';
--Reset QPLL
98 CPLL_RESET : out :='0';
--Reset CPLL
99 TX_FSM_RESET_DONE : out ;
--Reset-sequence has sucessfully been finished.
100 TXUSERRDY : out :='0';
101 RUN_PHALIGNMENT : out :='0';
102 RESET_PHALIGNMENT : out :='0';
103 PHALIGNMENT_DONE : in ;
105 RETRY_COUNTER : out (RETRY_COUNTER_BITWIDTH-1 downto 0):=(others=>'0')-- Number of
106 -- Retries it took to get the transceiver up and running
108 end amc_gtx5Gpd_TX_STARTUP_FSM;
111 -- * Timing depends on the frequency of the stable clock. Hence counters-sizes
112 -- are calculated at design-time based on the Generics
114 -- * if either of PLLs is reset during TX-startup, it does not need to be reset again by RX
115 -- => signal which PLL has been reset
124 INITIALISE : (
5 downto 0) := "
000000"
133 type tx_rst_fsm_type is(
134 INIT, ASSERT_ALL_RESETS, WAIT_FOR_PLL_LOCK, RELEASE_PLL_RESET,
135 WAIT_FOR_TXOUTCLK, RELEASE_MMCM_RESET, WAIT_FOR_TXUSRCLK, WAIT_RESET_DONE, DO_PHASE_ALIGNMENT,
138 signal tx_state : tx_rst_fsm_type := INIT;
140 constant MMCM_LOCK_CNT_MAX : := 256;
141 constant STARTUP_DELAY : := 500;
--AR43482: Transceiver needs to wait for 500 ns
after configuration
142 constant WAIT_CYCLES : := STARTUP_DELAY / STABLE_CLOCK_PERIOD;
-- Number of Clock-Cycles to wait after configuration
143 constant WAIT_MAX : := WAIT_CYCLES + 10;
-- 500 ns plus some additional margin
145 constant WAIT_TIMEOUT_2ms : := 2000000 / STABLE_CLOCK_PERIOD;
-- 2 ms time-out
146 constant WAIT_TLOCK_MAX : := 100000 / STABLE_CLOCK_PERIOD;
--100 us time-out
147 constant WAIT_TIMEOUT_500us : := 500000 / STABLE_CLOCK_PERIOD;
--100 us time-out
148 constant WAIT_1us_cycles : := 1000 / STABLE_CLOCK_PERIOD;
--1 us time-out
149 constant WAIT_1us : := WAIT_1us_cycles+ 10;
-- 1us plus some additional margin
151 signal init_wait_count : range 0 to WAIT_MAX:=0;
152 signal init_wait_done : := '0';
153 signal pll_reset_asserted : := '0';
156 signal tx_fsm_reset_done_int : := '0';
157 signal tx_fsm_reset_done_int_s2 : := '0';
158 signal tx_fsm_reset_done_int_s3 : := '0';
160 signal txresetdone_s2 : := '0';
161 signal txresetdone_s3 : := '0';
163 constant MAX_RETRIES : := 2**RETRY_COUNTER_BITWIDTH-1;
164 signal retry_counter_int : range 0 to MAX_RETRIES;
165 signal time_out_counter : range 0 to WAIT_TIMEOUT_2ms := 0;
167 signal reset_time_out : := '0';
168 signal time_out_2ms : := '0';
--\Flags that the various time-out points
169 signal time_tlock_max : := '0';
--|have been reached.
170 signal time_out_500us : := '0';
--/
172 signal mmcm_lock_count : range 0 to MMCM_LOCK_CNT_MAX-1:=0;
173 signal mmcm_lock_int : := '0';
174 signal mmcm_lock_i : := '0';
175 signal mmcm_lock_reclocked : := '0';
177 signal run_phase_alignment_int : := '0';
178 signal run_phase_alignment_int_s2 : := '0';
179 signal run_phase_alignment_int_s3 : := '0';
180 constant MAX_WAIT_BYPASS : := 91648;
--110000 TXUSRCLK cycles is the max for Multi lane designs
182 constant WAIT_TIME_MAX : := 100 ;
--10 us time-out
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_s2 : := '0';
187 signal time_out_wait_bypass_s3 : := '0';
188 signal txuserrdy_i : := '0';
189 signal refclk_lost : ;
190 signal gttxreset_i : := '0';
191 signal txpmaresetdone_i : := '0';
192 signal txpmaresetdone_sync : ;
194 signal cplllock_sync: := '0';
195 signal qplllock_sync: := '0';
196 signal cplllock_prev: := '0';
197 signal qplllock_prev: := '0';
198 signal cplllock_ris_edge: := '0';
199 signal qplllock_ris_edge: := '0';
200 signal wait_time_cnt : range 0 to WAIT_TIME_MAX;
201 signal wait_time_done :;
204 --Alias section, signals used within this module mapped to output ports:
205 RETRY_COUNTER <= (TO_UNSIGNED(retry_counter_int,RETRY_COUNTER_BITWIDTH));
206 RUN_PHALIGNMENT <= run_phase_alignment_int;
207 TX_FSM_RESET_DONE <= tx_fsm_reset_done_int;
208 GTTXRESET <= gttxreset_i;
210 process(STABLE_CLOCK,SOFT_RESET)
212 if (SOFT_RESET = '1') then
213 init_wait_done <= '0';
214 init_wait_count <= 0 ;
215 elsif rising_edge(STABLE_CLOCK) then
216 -- The counter starts running when configuration has finished and
217 -- the clock is stable. When its maximum count-value has been reached,
218 -- the 500 ns from Answer
Record 43482 have been passed.
219 if init_wait_count = WAIT_MAX then
220 init_wait_done <= '1';
222 init_wait_count <= init_wait_count + 1;
227 timeouts:
process(STABLE_CLOCK)
229 if rising_edge(STABLE_CLOCK) then
230 -- One common large counter for generating three time-out signals.
231 -- Intermediate time-outs are derived from calculated values, based
232 -- on the period of the provided clock.
233 if reset_time_out = '1' then
234 time_out_counter <= 0;
236 time_tlock_max <= '0';
237 time_out_500us <= '0';
239 if time_out_counter = WAIT_TIMEOUT_2ms then
242 time_out_counter <= time_out_counter + 1;
245 if time_out_counter = WAIT_TLOCK_MAX then
246 time_tlock_max <= '1';
249 if time_out_counter = WAIT_TIMEOUT_500us then
250 time_out_500us <= '1';
256 mmcm_lock_wait:
process(STABLE_CLOCK)
258 if rising_edge(STABLE_CLOCK) then
259 if mmcm_lock_i = '0' then
260 mmcm_lock_count <= 0;
261 mmcm_lock_reclocked <= '0';
263 if mmcm_lock_count < MMCM_LOCK_CNT_MAX - 1 then
264 mmcm_lock_count <= mmcm_lock_count + 1;
266 mmcm_lock_reclocked <= '1';
274 -- Clock Domain Crossing
280 data_in => run_phase_alignment_int ,
281 data_out => run_phase_alignment_int_s2
288 data_in => tx_fsm_reset_done_int,
289 data_out => tx_fsm_reset_done_int_s2
294 if rising_edge(TXUSERCLK) then
295 run_phase_alignment_int_s3 <= run_phase_alignment_int_s2;
297 tx_fsm_reset_done_int_s3 <= tx_fsm_reset_done_int_s2;
305 data_in => TXRESETDONE,
306 data_out => txresetdone_s2
313 data_in => time_out_wait_bypass,
314 data_out => time_out_wait_bypass_s2
321 data_in => MMCM_LOCK,
322 data_out => mmcm_lock_i
325 process(STABLE_CLOCK)
327 if rising_edge(STABLE_CLOCK) then
328 txresetdone_s3 <= txresetdone_s2;
330 time_out_wait_bypass_s3 <= time_out_wait_bypass_s2;
332 cplllock_prev <= cplllock_sync;
333 qplllock_prev <= qplllock_sync;
342 data_out => cplllock_sync
350 data_out => qplllock_sync
354 process (STABLE_CLOCK)
356 if rising_edge(STABLE_CLOCK) then
357 if(SOFT_RESET = '1' ) then
358 cplllock_ris_edge <= '0';
359 elsif((cplllock_prev = '0') and (cplllock_sync = '1')) then
360 cplllock_ris_edge <= '1';
361 elsif(tx_state = ASSERT_ALL_RESETS or tx_state = RELEASE_PLL_RESET) then
362 cplllock_ris_edge <= cplllock_ris_edge;
364 cplllock_ris_edge <= '0';
369 process (STABLE_CLOCK)
371 if rising_edge(STABLE_CLOCK) then
372 if(SOFT_RESET = '1' ) then
373 qplllock_ris_edge <= '0';
374 elsif((qplllock_prev = '0') and (qplllock_sync = '1')) then
375 qplllock_ris_edge <= '1';
376 elsif(tx_state = ASSERT_ALL_RESETS or tx_state = RELEASE_PLL_RESET) then
377 qplllock_ris_edge <= qplllock_ris_edge;
379 qplllock_ris_edge <= '0';
386 timeout_buffer_bypass:
process(TXUSERCLK)
388 if rising_edge(TXUSERCLK) then
389 if run_phase_alignment_int_s3 = '0' then
390 wait_bypass_count <= 0;
391 time_out_wait_bypass <= '0';
392 elsif (run_phase_alignment_int_s3 = '1') and (tx_fsm_reset_done_int_s3 = '0') then
393 if wait_bypass_count = MAX_WAIT_BYPASS - 1 then
394 time_out_wait_bypass <= '1';
396 wait_bypass_count <= wait_bypass_count + 1;
402 refclk_lost <= '1' when ((TX_QPLL_USED and QPLLREFCLKLOST='1') or (not TX_QPLL_USED and CPLLREFCLKLOST='1')) else '0';
405 timeout_max:
process(STABLE_CLOCK)
407 if rising_edge(STABLE_CLOCK) then
408 if((tx_state = ASSERT_ALL_RESETS) or
409 (tx_state = RELEASE_PLL_RESET) or
410 (tx_state = RELEASE_MMCM_RESET)) then
411 wait_time_cnt <= WAIT_TIME_MAX;
412 elsif (wait_time_cnt > 0 ) then
413 wait_time_cnt <= wait_time_cnt - 1;
418 wait_time_done <= '1' when (wait_time_cnt = 0) else '0';
421 --FSM for resetting the GTX/GTH/GTP in the 7-series.
422 --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
424 -- Following steps are performed:
425 -- 1) Only
for GTX -
After configuration wait for approximately
500 ns as specified
in
426 -- answer-record 43482
427 -- 2)
Assert all resets
on the GT
and on an MMCM potentially connected.
428 -- After that wait until a reference-clock has been detected.
429 -- 3)
Release the reset
to the GT
and wait until the GT-PLL has locked.
430 -- 4)
Release the MMCM-reset
and wait until the MMCM has signalled lock.
431 -- Also signal to the RX-side which PLL has been reset.
432 -- 5)
Wait for the RESET_DONE-signal from the GT.
433 -- 6)
Signal to start the phase-alignment
procedure and wait for it
to
435 -- 7) Reset-sequence has successfully run through.
Signal this
to the
436 -- rest of the design by asserting TX_FSM_RESET_DONE.
438 reset_fsm:
process(STABLE_CLOCK)
440 if rising_edge(STABLE_CLOCK) then
441 if(SOFT_RESET = '1') then
442 --if(SOFT_RESET = '1' or (not(tx_state = INIT) and not(tx_state = ASSERT_ALL_RESETS) and refclk_lost = '1')) then
447 tx_fsm_reset_done_int <= '0';
450 pll_reset_asserted <= '0';
451 reset_time_out <= '0';
452 retry_counter_int <= 0;
453 run_phase_alignment_int <= '0';
454 RESET_PHALIGNMENT <= '1';
459 --Initial state after configuration. This state will be left after
460 --approx. 500 ns
and not be re-entered.
461 if init_wait_done = '1' then
462 tx_state <= ASSERT_ALL_RESETS;
463 reset_time_out <= '1';
466 when ASSERT_ALL_RESETS =>
467 --This is the state into which the FSM will always jump back if any
468 --time-outs will occur.
469 --The number of retries is reported on the output RETRY_COUNTER. In
470 --case the transceiver never comes up for some reason, this machine
471 --will still continue its best and rerun until the FPGA is turned off
472 --or the transceivers come up correctly.
474 if (pll_reset_asserted = '0' and refclk_lost = '0') then
476 pll_reset_asserted <= '1';
481 if (pll_reset_asserted = '0' and refclk_lost = '0') then
483 pll_reset_asserted <= '1';
491 reset_time_out <= '1';
492 run_phase_alignment_int <= '0';
493 RESET_PHALIGNMENT <= '1';
495 if (TX_QPLL_USED and (qplllock_sync = '0') and pll_reset_asserted = '1' ) or
496 (not TX_QPLL_USED and (cplllock_sync = '0') and pll_reset_asserted = '1' ) then
497 tx_state <= WAIT_FOR_PLL_LOCK;
500 when WAIT_FOR_PLL_LOCK =>
501 if(wait_time_done = '1') then
502 tx_state <= RELEASE_PLL_RESET;
505 when RELEASE_PLL_RESET =>
506 --PLL-Reset of the GTX gets released and the time-out counter
508 pll_reset_asserted <= '0';
510 if (TX_QPLL_USED and (qplllock_sync = '1')) or
511 (not TX_QPLL_USED and (cplllock_sync = '1')) then
512 tx_state <= WAIT_FOR_TXOUTCLK;
513 reset_time_out <= '1';
516 if time_out_2ms = '1' then
517 if retry_counter_int = MAX_RETRIES then
518 -- If too many retries are performed compared to what is specified in
519 -- the generic, the counter simply wraps around.
520 retry_counter_int <= 0;
522 retry_counter_int <= retry_counter_int + 1;
524 tx_state <= ASSERT_ALL_RESETS;
527 when WAIT_FOR_TXOUTCLK =>
529 if(wait_time_done = '1') then
530 tx_state <= RELEASE_MMCM_RESET;
533 when RELEASE_MMCM_RESET =>
534 --Release of the MMCM-reset. Waiting for the MMCM to lock.
536 reset_time_out <= '0';
537 if mmcm_lock_reclocked = '1' then
538 tx_state <= WAIT_FOR_TXUSRCLK;
539 reset_time_out <= '1';
542 if (time_tlock_max = '1' and mmcm_lock_reclocked = '0' and reset_time_out = '0') then
543 if retry_counter_int = MAX_RETRIES then
544 -- If too many retries are performed compared to what is specified in
545 -- the generic, the counter simply wraps around.
546 retry_counter_int <= 0;
548 retry_counter_int <= retry_counter_int + 1;
550 tx_state <= ASSERT_ALL_RESETS;
553 when WAIT_FOR_TXUSRCLK =>
554 if(wait_time_done = '1') then
555 tx_state <= WAIT_RESET_DONE;
558 when WAIT_RESET_DONE =>
560 reset_time_out <= '0';
561 if txresetdone_s3 = '1' then
562 tx_state <= DO_PHASE_ALIGNMENT;
563 reset_time_out <= '1';
566 if (time_out_500us = '1' and reset_time_out = '0') then
567 if retry_counter_int = MAX_RETRIES then
568 -- If too many retries are performed compared to what is specified in
569 -- the generic, the counter simply wraps around.
570 retry_counter_int <= 0;
572 retry_counter_int <= retry_counter_int + 1;
574 tx_state <= ASSERT_ALL_RESETS;
577 when DO_PHASE_ALIGNMENT =>
578 --The direct handling of the signals for the Phase Alignment is done outside
579 --this state-machine.
580 RESET_PHALIGNMENT <= '0';
581 run_phase_alignment_int <= '1';
582 reset_time_out <= '0';
584 if PHALIGNMENT_DONE = '1' then
585 tx_state <= RESET_FSM_DONE;
588 if time_out_wait_bypass_s3 = '1' then
589 if retry_counter_int = MAX_RETRIES then
590 -- If too many retries are performed compared to what is specified in
591 -- the generic, the counter simply wraps around.
592 retry_counter_int <= 0;
594 retry_counter_int <= retry_counter_int + 1;
596 tx_state <= ASSERT_ALL_RESETS;
599 when RESET_FSM_DONE =>
600 reset_time_out <= '1';
601 tx_fsm_reset_done_int <= '1';