1 --////////////////////////////////////////////////////////////////////////////////     4 --// /___/  \  /    Vendor: Xilinx      5 --// \   \   \/     Version : 2.2     6 --//  \   \         Application : 7 Series FPGAs Transceivers Wizard      7 --//  /   /         Filename : kintexgtxlowlat_recclk_monitor.vhd    13 --  Description :     This module is the ppm monitor between the    14 --                GT RxRecClk and the reference clock        16 --                    This module will declare that the Rx RECCLK is stable if the     17 --                    recovered clock is within +/-5000PPM of the reference clock.    20 --                    There are 3 counters running on local clocks for both     21 --                    recovered clocks and one for the reference clock.  The    22 --                    COUNTER_UPPER_VALUE parameter is the width of these    23 --                    counters. The PPM offset is checked when these counters     26 --                    There is also a counter running on the system clock.    27 --                    This can be running at a much lower frequency and is    30 --                    To set the parameters correctly here is what you need to    31 --                    do.  Lets assume taht the reference and recovered    32 --                    clocks are running at 156MHz and the system clock is    35 --                    To ensure that the interval is long enough we want to    36 --                    to make the COUNTER_UPPER_VALUE to be reasonable.  The    37 --                    CLOCK_PULSES is the number of sytem clock cycles we can    38 --                    expect to be off based on these frequencies:    40 --                    Example: Rec Clk and Ref Clk 156MHz, System clock 50MHz    41 --                             PPM Offset to tolerate +/- 5000PPM    43 --                    COUNTER_UPPER_VALUE = 15 -> 2^15 counter = 32768    44 --                    GCLK_COUNTER_UPPER_VALUE = 15 -> 2^15 counter = 32768    46 --                    PPM OFFSET = 5000 => 32768 * 5000/1000000 = 164    48 --                    Now we are using the system clock to do the    49 --                    calculations, therfore we need to scale the PPM_OFFSET    52 --                    CLOCK_PULSES = PPM_OFFSET * sysclk_freq/refclk_freq     53 --                                 = 164 * 50/156 = 52    56 --                    When the counters are checked if they are off by less    57 --                    than 52, we can delcare that the particular RECCLK is    60 --                    All FFs that have the _meta are metastability FFs and    61 --                    can be ignored from a timing perspective. The following    62 --                    constraint can be added to the UCF to ensure that they    65 --                    INST "*_meta" TNM = "METASTABILITY_FFS";    66 --                    TIMESPEC "TS_METASTABILITY" = FROM FFS TO "METASTABILITY_FFS" TIG;    68 -- Module KintexGtxLowLat_RECCLK_MONITOR    69 -- Generated by Xilinx 7 Series FPGAs Transceivers Wizard    72 -- (c) Copyright 2010-2012 Xilinx, Inc. All rights reserved.    74 -- This file contains confidential and proprietary information    75 -- of Xilinx, Inc. and is protected under U.S. and    76 -- international copyright and other intellectual property    80 -- This disclaimer is not a license and does not grant any    81 -- rights to the materials distributed herewith. Except as    82 -- otherwise provided in a valid license issued to you by    83 -- Xilinx, and to the maximum extent permitted by applicable    84 -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND    85 -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES    86 -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING    87 -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-    88 -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and    89 -- (2) Xilinx shall not be liable (whether in contract or tort,    90 -- including negligence, or under any other theory of    91 -- liability) for any loss or damage of any kind or nature    92 -- related to, arising under or in connection with these    93 -- materials, including for any direct, or any indirect,    94 -- special, incidental, or consequential loss or damage    95 -- (including loss of data, profits, goodwill, or any type of    96 -- loss or damage suffered as a result of any action brought    97 -- by a third party) even if such damage or loss was    98 -- reasonably foreseeable or Xilinx had been advised of the    99 -- possibility of the same.   101 -- CRITICAL APPLICATIONS   102 -- Xilinx products are not designed or intended to be fail-   103 -- safe, or for use in any application requiring fail-safe   104 -- performance, such as life-support or safety devices or   105 -- systems, Class III medical devices, nuclear facilities,   106 -- applications related to the deployment of airbags, or any   107 -- other applications that could lead to death, personal   108 -- injury, or severe property or environmental damage   109 -- (individually and collectively, "Critical   110 -- Applications"). Customer assumes the sole risk and   111 -- liability of any use of Xilinx products in Critical   112 -- Applications, subject only to applicable laws and   113 -- regulations governing limitations on product liability.   115 -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS   116 -- PART OF THIS FILE AT ALL TIMES.    119 --*******************************************************************************   124 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
   127  --! @ingroup xilinx_7Series_gtx7   134                                                       --full HW-circuitry gets simulated.   135                                                       --NOTE OF CARE: This can extend the necessary simulation-   136                                                       --time to beyond 600 ?s (six-hundred, sic!)   145                                      -- it can be tied high as the PLL-LK has already been    146                                      -- verified in the previous state.   150 end ENTITY Gtx7RecClkMonitor;
   155 --------------------------------------------------------------------------------   156 -- Declaration of wires/regs   157 --------------------------------------------------------------------------------   158 type FSM is (WAIT_FOR_LOCK,REFCLK_EVENT,CALC_PPM_DIFF,CHECK_SIGN,COMP_CNTR,RESTART);
   206  function simulation_func return  is   207     --This function detects at compile-time whether the design    208     --is synthesised or simulated. For Simulation the Pragma-   209     --constructs below are just comments and the variable "sim"   211     --For synthesis the Pragma-constructs turn off the translation   212     --between the _off and _on part and hence only the value false   213     --is returned for the function.   214     variable sim:  := false;
   217     --pragma translate_off   219     --pragma translate_on   225 --------------------------------------------------------------------------------   227 --------------------------------------------------------------------------------   267 --------------------------------------------------------------------------------   270 --We will also need 3 counters running on a global clock, one corresponding to    271 --each of the local counters.  For this example I will use a 50MHz clock, but it    272 --can be anything.  We use the global clock to sample the 20th bit of the local    273 --counter, it has to be sampled twice for metastability.  Whenever we detect a    274 --falling edge on that signal, it means that the counter has rolled over.  We    275 --use this to latch the current count value to FFs and reset the counter.  Now    276 --you have the amount of time it took to count ~1M clock cycles.  In an ideal    277 --world, this would be 6.7ms or 335,602 50MHz clock periods.  You would do the    278 --same for the reference clock and then you could compare both counts and ensure    279 --that the difference is less than 1,678 (33.55us), if its not then you know    280 --you?ve exceeded your PPM limit.  All the counts could be set as parameters and    281 --could easily be adjusted based on the global clock frequency and the PPM offset   283 --------------------------------------------------------------------------------   285 -- Synchronize reset to global Clock domain   304           state     <= WAIT_FOR_LOCK;
   305           ppm0      <= (others => '1');
   311          when WAIT_FOR_LOCK =>   314               state <= REFCLK_EVENT;
   316               state <= WAIT_FOR_LOCK;
   319            state <= WAIT_FOR_LOCK;
   323             state <= CALC_PPM_DIFF;
   325             state <= REFCLK_EVENT;
   327           when CALC_PPM_DIFF =>   333           --check the sign bit - if 1'b1, then convert to binary.   346                   state <= WAIT_FOR_LOCK;
   349               state     <= WAIT_FOR_LOCK;
   350               ppm0      <= (others => '1');
   359 -- On clock roll-over, latch counter value once and event occurance.   375         --only latch it the first time around   380         --take the 2's complement number after we latched it   389 -- increment clock counters'   407       else -- double flop msb count bit to system clock domain   417 --falling edge detect   421 -- Manage counter reset/restart   427      if (state = RESTART) then   442     --This Generate-branch is ONLY FOR SIMULATION and is not implemented in HW.   443     --The whole purpose of this shortcut-branch is to avoid huge simulation- 
std_logic_vector( 1 downto  0)   ref_clk_edge_rt
std_logic_vector(   GCLK_COUNTER_UPPER_VALUE- 1 downto  0)   ppm0
out RECCLK_STABLEstd_logic  
std_logic   reset_logic_ref_sync
out EXEC_RESTARTstd_logic  
std_logic_vector( 2 downto  1)   ref_clk_msb
std_logic_vector( 2 downto  1)   rec_clk0_msb
std_logic_vector(   COUNTER_UPPER_VALUE- 1 downto  0)  :=( others => '0') rec_clk0_cnt
std_logic   gt_pll_locked_meta
std_logic_vector(   GCLK_COUNTER_UPPER_VALUE- 1 downto  0)   sys_clk_counter
std_logic_vector(   GCLK_COUNTER_UPPER_VALUE- 1 downto  0)   ref_clk_compare_cnt_latch
std_logic_vector(   GCLK_COUNTER_UPPER_VALUE- 1 downto  0)   rec_clk0_compare_cnt_latch
GCLK_COUNTER_UPPER_VALUEinteger  := 20
std_logic_vector( 3 downto  0)   reset_logic
std_logic   ref_clk_msb_meta
std_logic_vector(   COUNTER_UPPER_VALUE- 1 downto  0)   ref_clk_cnt
COUNTER_UPPER_VALUEinteger  := 20
(WAIT_FOR_LOCK,REFCLK_EVENT,CALC_PPM_DIFF,CHECK_SIGN,COMP_CNTR,RESTART) FSM
std_logic   gt_pll_locked_sync
std_logic   rec_clk0_edge_event
CLOCK_PULSESinteger  := 5000
std_logic   rec_clk_0_msb_meta
std_logic   reset_logic_rec0_meta
boolean  :=   simulation_func simulation
std_logic_vector( 1 downto  0)   ref_clk_edge_event
EXAMPLE_SIMULATIONinteger  := 0
std_logic   reset_logic_rec0_sync
std_logic  := '0' recclk_stable0_int
std_logic   reset_logic_ref_meta