AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
s6link_tx_startup_fsm.vhd
1 --////////////////////////////////////////////////////////////////////////////////
2 --// ____ ____
3 --// / /\/ /
4 --// /___/ \ / Vendor: Xilinx
5 --// \ \ \/ Version : 2.5
6 --// \ \ Application : 7 Series FPGAs Transceivers Wizard
7 --// / / Filename :s6link_tx_startup_fsm.vhd
8 --// /___/ /\
9 --// \ \ / \
10 --// \___\/\___\
11 --//
12 --//
13 -- Description : This module performs TX reset and initialization.
14 --
15 --
16 --
17 -- Module S6Link_tx_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 
75  Generic( GT_TYPE : string := "GTX";
76  STABLE_CLOCK_PERIOD : integer range 4 to 20 := 8; --Period of the stable clock driving this state-machine, unit is [ns]
77  RETRY_COUNTER_BITWIDTH : integer range 2 to 8 := 8;
78  TX_QPLL_USED : boolean := False; -- the TX and RX Reset FSMs must
79  RX_QPLL_USED : boolean := False; -- share these two generic values
80  PHASE_ALIGNMENT_MANUAL : boolean := True -- Decision if a manual phase-alignment is necessary or the automatic
81  -- is enough. For single-lane applications the automatic alignment is
82  -- sufficient
83  );
84  Port ( STABLE_CLOCK : in STD_LOGIC; --Stable Clock, either a stable clock from the PCB
85  --or reference-clock present at startup.
86  TXUSERCLK : in STD_LOGIC; --TXUSERCLK as used in the design
87  SOFT_RESET : in STD_LOGIC; --User Reset, can be pulled any time
88  QPLLREFCLKLOST : in STD_LOGIC; --QPLL Reference-clock for the GT is lost
89  CPLLREFCLKLOST : in STD_LOGIC; --CPLL Reference-clock for the GT is lost
90  QPLLLOCK : in STD_LOGIC; --Lock Detect from the QPLL of the GT
91  CPLLLOCK : in STD_LOGIC; --Lock Detect from the CPLL of the GT
92  TXRESETDONE : in STD_LOGIC;
93  MMCM_LOCK : in STD_LOGIC;
94  GTTXRESET : out STD_LOGIC:='0';
95  MMCM_RESET : out STD_LOGIC:='1';
96  QPLL_RESET : out STD_LOGIC:='0'; --Reset QPLL
97  CPLL_RESET : out STD_LOGIC:='0'; --Reset CPLL
98  TX_FSM_RESET_DONE : out STD_LOGIC; --Reset-sequence has sucessfully been finished.
99  TXUSERRDY : out STD_LOGIC:='0';
100  RUN_PHALIGNMENT : out STD_LOGIC:='0';
101  RESET_PHALIGNMENT : out STD_LOGIC:='0';
102  PHALIGNMENT_DONE : in STD_LOGIC;
103 
104  RETRY_COUNTER : out STD_LOGIC_VECTOR (RETRY_COUNTER_BITWIDTH-1 downto 0):=(others=>'0')-- Number of
105  -- Retries it took to get the transceiver up and running
106  );
107 end S6Link_TX_STARTUP_FSM;
108 
109 --Interdependencies:
110 -- * Timing depends on the frequency of the stable clock. Hence counters-sizes
111 -- are calculated at design-time based on the Generics
112 --
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
115 -- *
116 
117 
118 
119 architecture RTL of S6Link_TX_STARTUP_FSM is
120 
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,
124  RESET_FSM_DONE);
125 
126  signal tx_state : tx_rst_fsm_type := INIT;
127 
128  constant MMCM_LOCK_CNT_MAX : integer := 1024;
129  constant STARTUP_DELAY : integer := 500;--AR43482: Transceiver needs to wait for 500 ns after configuration
130  constant WAIT_CYCLES : integer := STARTUP_DELAY / STABLE_CLOCK_PERIOD; -- Number of Clock-Cycles to wait after configuration
131  constant WAIT_MAX : integer := WAIT_CYCLES + 10; -- 500 ns plus some additional margin
132 
133  constant WAIT_TIMEOUT_2ms : integer := 2000000 / STABLE_CLOCK_PERIOD;-- 2 ms time-out
134  constant WAIT_TLOCK_MAX : integer := 100000 / STABLE_CLOCK_PERIOD;--100 us time-out
135  constant WAIT_TIMEOUT_500us : integer := 500000 / STABLE_CLOCK_PERIOD;--100 us time-out
136 
137  signal init_wait_count : integer range 0 to WAIT_MAX:=0;
138  signal init_wait_done : std_logic := '0';
139  signal pll_reset_asserted : std_logic := '0';
140 
141  signal tx_fsm_reset_done_int : std_logic := '0';
142  signal tx_fsm_reset_done_int_s1 : std_logic := '0';
143  signal tx_fsm_reset_done_int_s2 : std_logic := '0';
144  signal tx_fsm_reset_done_int_s3 : std_logic := '0';
145 
146  signal txresetdone_s1 : std_logic := '0';
147  signal txresetdone_s2 : std_logic := '0';
148  signal txresetdone_s3 : std_logic := '0';
149 
150  constant MAX_RETRIES : integer := 2**RETRY_COUNTER_BITWIDTH-1;
151  signal retry_counter_int : integer range 0 to MAX_RETRIES;
152  signal time_out_counter : integer range 0 to WAIT_TIMEOUT_2ms := 0;
153 
154  signal reset_time_out : std_logic := '0';
155  signal time_out_2ms : std_logic := '0';--\Flags that the various time-out points
156  signal time_tlock_max : std_logic := '0';--|have been reached.
157  signal time_out_500us : std_logic := '0';--/
158 
159  signal mmcm_lock_count : integer range 0 to MMCM_LOCK_CNT_MAX-1:=0;
160  signal mmcm_lock_int : std_logic := '0';
161  signal mmcm_lock_reclocked : std_logic_vector(3 downto 0) := (others=>'0');
162 
163  signal run_phase_alignment_int : std_logic := '0';
164  signal run_phase_alignment_int_s1 : std_logic := '0';
165  signal run_phase_alignment_int_s2 : std_logic := '0';
166  signal run_phase_alignment_int_s3 : std_logic := '0';
167 
168  constant MAX_WAIT_BYPASS : integer := 110000; --110000 TXUSRCLK cycles is the max time for Multi lane designs
169  signal wait_bypass_count : integer range 0 to MAX_WAIT_BYPASS-1;
170  signal time_out_wait_bypass : std_logic := '0';
171  signal time_out_wait_bypass_s1 : std_logic := '0';
172  signal time_out_wait_bypass_s2 : std_logic := '0';
173  signal time_out_wait_bypass_s3 : std_logic := '0';
174  signal refclk_lost : std_logic;
175 
176 begin
177  --Alias section, signals used within this module mapped to output ports:
178  RETRY_COUNTER <= STD_LOGIC_VECTOR(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;
181 
182  process(STABLE_CLOCK)
183  begin
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';
190  else
191  init_wait_count <= init_wait_count + 1;
192  end if;
193  end if;
194  end process;
195 
196 
197  timeouts:process(STABLE_CLOCK)
198  begin
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;
205  time_out_2ms <= '0';
206  time_tlock_max <= '0';
207  time_out_500us <= '0';
208  else
209  if time_out_counter = WAIT_TIMEOUT_2ms then
210  time_out_2ms <= '1';
211  else
212  time_out_counter <= time_out_counter + 1;
213  end if;
214 
215  if time_out_counter = WAIT_TLOCK_MAX then
216  time_tlock_max <= '1';
217  end if;
218 
219  if time_out_counter = WAIT_TIMEOUT_500us then
220  time_out_500us <= '1';
221  end if;
222  end if;
223  end if;
224  end process;
225 
226  mmcm_lock_wait:process(TXUSERCLK)
227  begin
228  if rising_edge(TXUSERCLK) then
229  if MMCM_LOCK = '0' then
230  mmcm_lock_count <= 0;
231  mmcm_lock_int <= '0';
232  else
233  if mmcm_lock_count < MMCM_LOCK_CNT_MAX - 1 then
234  mmcm_lock_count <= mmcm_lock_count + 1;
235  else
236  mmcm_lock_int <= '1';
237  end if;
238  end if;
239  end if;
240  end process;
241 
242  reclocking:process(STABLE_CLOCK)
243  --Reclocking onto the FSM-clock.
244  begin
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.
251 
252  mmcm_lock_reclocked <= (others => '0');
253  else
254  mmcm_lock_reclocked(3) <= mmcm_lock_int;
255  mmcm_lock_reclocked(2 downto 0) <= mmcm_lock_reclocked(3 downto 1);
256  end if;
257  end if;
258  end process;
259 
260 
261  -- Clock Domain Crossing
262  process(TXUSERCLK)
263  begin
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;
268 
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;
272  end if;
273  end process;
274 
275  process(STABLE_CLOCK)
276  begin
277  if rising_edge(STABLE_CLOCK) then
278  txresetdone_s1 <= TXRESETDONE;
279  txresetdone_s2 <= txresetdone_s1;
280  txresetdone_s3 <= txresetdone_s2;
281 
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;
285  end if;
286  end process;
287 
288 
289  timeout_buffer_bypass:process(TXUSERCLK)
290  begin
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';
298  else
299  wait_bypass_count <= wait_bypass_count + 1;
300  end if;
301  end if;
302  end if;
303  end process;
304 
305  refclk_lost <= '1' when ((TX_QPLL_USED and QPLLREFCLKLOST='1') or (not TX_QPLL_USED and CPLLREFCLKLOST='1')) else '0';
306 
307 
308  --FSM for resetting the GTX/GTH/GTP in the 7-series.
309  --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
310  --
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
321  -- finish.
322  -- 7) Reset-sequence has successfully run through. Signal this to the
323  -- rest of the design by asserting TX_FSM_RESET_DONE.
324 
325  reset_fsm:process(STABLE_CLOCK)
326  begin
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
329  tx_state <= INIT;
330  TXUSERRDY <= '0';
331  GTTXRESET <= '0';
332  MMCM_RESET <= '1';
333  tx_fsm_reset_done_int <= '0';
334  QPLL_RESET <= '0';
335  CPLL_RESET <= '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';
341  else
342 
343  case tx_state is
344  when INIT =>
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';
350  end if;
351 
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.
359  if TX_QPLL_USED then
360  if pll_reset_asserted = '0' then
361  QPLL_RESET <= '1';
362  pll_reset_asserted <= '1';
363  else
364  QPLL_RESET <= '0';
365  end if;
366  else
367  if pll_reset_asserted = '0' then
368  CPLL_RESET <= '1';
369  pll_reset_asserted <= '1';
370  else
371  CPLL_RESET <= '0';
372  end if;
373  end if;
374  TXUSERRDY <= '0';
375  GTTXRESET <= '1';
376  MMCM_RESET <= '1';
377  reset_time_out <= '0';
378  run_phase_alignment_int <= '0';
379  RESET_PHALIGNMENT <= '1';
380 
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;
384  end if;
385 
386  when RELEASE_PLL_RESET =>
387  --PLL-Reset of the GTX gets released and the time-out counter
388  --starts running.
389  pll_reset_asserted <= '1';
390 
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';
395  end if;
396 
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;
402  else
403  retry_counter_int <= retry_counter_int + 1;
404  end if;
405  tx_state <= ASSERT_ALL_RESETS;
406  end if;
407 
408  when RELEASE_MMCM_RESET =>
409  GTTXRESET <= '0';
410  reset_time_out <= '0';
411  --Release of the MMCM-reset. Waiting for the MMCM to lock.
412  MMCM_RESET <= '0';
413  if mmcm_lock_reclocked(0) = '1' then
414  tx_state <= WAIT_RESET_DONE;
415  reset_time_out <= '1';
416  end if;
417 
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;
423  else
424  retry_counter_int <= retry_counter_int + 1;
425  end if;
426  tx_state <= ASSERT_ALL_RESETS;
427  end if;
428 
429  when WAIT_RESET_DONE =>
430  TXUSERRDY <= '1';
431  reset_time_out <= '0';
432  if txresetdone_s3 = '1' then
433  tx_state <= DO_PHASE_ALIGNMENT;
434  reset_time_out <= '1';
435  end if;
436 
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;
442  else
443  retry_counter_int <= retry_counter_int + 1;
444  end if;
445  tx_state <= ASSERT_ALL_RESETS;
446  end if;
447 
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';
454 
455  if PHALIGNMENT_DONE = '1' then
456  tx_state <= RESET_FSM_DONE;
457  end if;
458 
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;
464  else
465  retry_counter_int <= retry_counter_int + 1;
466  end if;
467  tx_state <= ASSERT_ALL_RESETS;
468  end if;
469 
470  when RESET_FSM_DONE =>
471  reset_time_out <= '1';
472  tx_fsm_reset_done_int <= '1';
473 
474  end case;
475  end if;
476  end if;
477  end process;
478 
479 end RTL;
480