SURF  1.0
Gtx7CfgPkg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : Gtx7CfgPkg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-09-02
5 -- Last update: 2015-01-08
6 -------------------------------------------------------------------------------
7 -- Description: Provides useful functions for generating GTX7 configurations.
8 -------------------------------------------------------------------------------
9 -- This file is part of 'SLAC Firmware Standard Library'.
10 -- It is subject to the license terms in the LICENSE.txt file found in the
11 -- top-level directory of this distribution and at:
12 -- https://confluence.slac.stanford.edu/display/ppareg/LICENSE.html.
13 -- No part of 'SLAC Firmware Standard Library', including this file,
14 -- may be copied, modified, propagated, or distributed except according to
15 -- the terms contained in the LICENSE.txt file.
16 -------------------------------------------------------------------------------
17 
18 
19 library IEEE;
20 use IEEE.STD_LOGIC_1164.all;
21 use IEEE.STD_LOGIC_UNSIGNED.all;
22 use IEEE.STD_LOGIC_ARITH.all;
23 use IEEE.math_real.all;
24 
25 use work.StdRtlPkg.all;
26 
27 package Gtx7CfgPkg is
28 --! @file
29  --! @ingroup xilinx_7Series_gtx7
30 
31  constant GTX7CFG_0_C : sl := '0';
32  constant GTX7CFG_1_C : sl := '1';
33 
34  -------------------------------------------------------------------------------------------------
35  -- CPLL Config Types, Constants and Function declarations
36  -------------------------------------------------------------------------------------------------
37  type Gtx7CPllCfgType is record
38  CPLL_REFCLK_DIV_G : integer;
39  CPLL_FBDIV_G : integer;
40  CPLL_FBDIV_45_G : integer;
41  OUT_DIV_G : integer;
42  CLK25_DIV_G : integer;
43  end record Gtx7CPllCfgType;
44 
45  constant CPLL_REFCLK_DIV_VALIDS_C : IntegerArray := (1, 2);
46  constant CPLL_FBDIV_VALIDS_C : IntegerArray := (1, 2, 3, 4, 5);
47  constant CPLL_FBDIV_45_VALIDS_C : IntegerArray := (4, 5);
48  constant CPLL_OUT_DIV_VALIDS_C : IntegerArray := (1, 2, 4, 8);
49 
50  constant CPLL_LOW_C : real := 1.6E9;
51  constant CPLL_HIGH_C : real := 3.3E9;
52 
53  function getGtx7CPllCfg (refClkFreq : real; lineRate : real) return Gtx7CPllCfgType;
54 
55  -------------------------------------------------------------------------------------------------
56  -- QPLL
57  -------------------------------------------------------------------------------------------------
58  type Gtx7QPllCfgType is record
59  QPLL_CFG_G : bit_vector(27 downto 0);
60  QPLL_REFCLK_DIV_G : integer;
62  QPLL_FBDIV_G : bit_vector(9 downto 0);
63  OUT_DIV_G : integer;
64  CLK25_DIV_G : integer;
65  end record Gtx7QPllCfgType;
66 
67  constant QPLL_CFG_VCO_UPPER_C : bit_vector := x"0680181";
68  constant QPLL_CFG_VCO_LOWER_C : bit_vector := x"06801C1";
69 
70  constant QPLL_REFCLK_DIV_VALIDS_C : IntegerArray := (1, 2, 3, 4);
71  constant QPLL_FBDIV_INT_VALIDS_C : IntegerArray := (16, 20, 32, 40, 64, 66, 80, 100);
72  constant QPLL_OUT_DIV_VALIDS_C : IntegerArray := (1, 2, 4, 8, 16);
73 
74  constant QPLL_LOWER_BAND_LOW_C : real := 5.93E9;
75  constant QPLL_LOWER_BAND_HIGH_C : real := 8.0E9;
76  constant QPLL_UPPER_BAND_LOW_C : real := 9.8E9;
77  constant QPLL_UPPER_BAND_HIGH_C : real := 12.5E9;
78 
79  function getQPllFbdiv (fbdivInt : integer) return bit_vector;
80 
81  function getGtx7QPllCfg (refClkFreq : real; lineRate : real) return Gtx7QPllCfgType;
82 
83  -------------------------------------------------------------------------------------------------
84  -- GT config
85  -------------------------------------------------------------------------------------------------
86  type Gtx7CfgType is record
87  CPLL_REFCLK_DIV_G : integer;
88  CPLL_FBDIV_G : integer;
89  CPLL_FBDIV_45_G : integer;
90  RXOUT_DIV_G : integer;
91  TXOUT_DIV_G : integer;
92  RX_CLK25_DIV_G : integer;
93  TX_CLK25_DIV_G : integer;
94  end record Gtx7CfgType;
95 
96  function getGtx7Cfg (
97  txPll : string;
98  rxPll : string;
99  cPllCfg : Gtx7CPllCfgType;
100  qPllCfg : Gtx7QPllCfgType)
101  return Gtx7CfgType;
102 
103 end package Gtx7CfgPkg;
104 
105 package body Gtx7CfgPkg is
106 
107  -------------------------------------------------------------------------------------------------
108  -- CPLL Config
109  -------------------------------------------------------------------------------------------------
110  function getGtx7CPllCfg (
111  refClkFreq : real;
112  lineRate : real)
113  return Gtx7CPllCfgType
114  is
115  variable pllClk : real;
116  variable rate : real;
117  variable found : boolean;
118  variable ret : Gtx7CPllCfgType;
119  begin
120  found := false;
121  -- Walk through all possible configs and look for one that works
122  dloop : for d in CPLL_OUT_DIV_VALIDS_C'range loop
123  mloop : for m in CPLL_REFCLK_DIV_VALIDS_C'range loop
124  n2loop : for n2 in CPLL_FBDIV_VALIDS_C'range loop
125  n1loop : for n1 in CPLL_FBDIV_45_VALIDS_C'range loop
126 
127  pllClk := refClkFreq * real(CPLL_FBDIV_VALIDS_C(n2) * CPLL_FBDIV_45_VALIDS_C(n1)) /
128  real(CPLL_REFCLK_DIV_VALIDS_C(m));
129  rate := pllClk * 2.0 / real(CPLL_OUT_DIV_VALIDS_C(d));
130 
131  if (pllClk > CPLL_LOW_C and pllClk < CPLL_HIGH_C and rate = lineRate) then
132 
137  ret.CLK25_DIV_G := integer(refClkFreq / 25.0E6);
138 
139  found := true;
140 
141 -- report "Found GTX config: " & lf &
142 -- "refClkFreq: " & real'image(refClkFreq) & lf &
143 -- "lineRate: " & real'image(lineRate) & lf &
144 -- "CPLL_REFCLK_DIV_G: " & integer'image(ret.CPLL_REFCLK_DIV_G) & lf &
145 -- "CPLL_FBDIV_G: " & integer'image(ret.CPLL_FBDIV_G) & lf &
146 -- "CPLL_FBDIV_45_G: " & integer'image(ret.CPLL_FBDIV_45_G) & lf &
147 -- "OUT_DIV_G: " & integer'image(ret.RXOUT_DIV_G) & lf
148 -- severity note;
149 
150  exit dloop;
151  end if;
152  end loop;
153  end loop;
154  end loop;
155  end loop;
156 
157  assert (found) report "getGtx7CPllCfg: no feasible configuration found for refClkFreq: " &
158  real'image(refClkFreq) & " and lineRate: " & real'image(lineRate) severity failure;
159  return ret;
160 
161  end function;
162 
163  -------------------------------------------------------------------------------------------------
164  -- QPLL
165  -------------------------------------------------------------------------------------------------
166  function getQPllFbdiv (fbdivInt : integer) return bit_vector is
167  variable ret : bit_vector(9 downto 0) := (others => '0');
168  begin
169  case (fbdivInt) is
170  when 16 => ret := "0000100000";
171  when 20 => ret := "0000110000";
172  when 32 => ret := "0001100000";
173  when 40 => ret := "0010000000";
174  when 64 => ret := "0011100000";
175  when 66 => ret := "0101000000";
176  when 80 => ret := "0100100000";
177  when 100 => ret := "0101110000";
178  when others => ret := "0000000000"; --Added others ulegat
179  end case;
180  return ret;
181  end function getQPllFbdiv;
182 
183  function getGtx7QPllCfg (
184  refClkFreq : real;
185  lineRate : real)
186  return Gtx7QPllCfgType
187  is
188  variable ret : Gtx7QPllCfgType;
189  variable vcoClk : real;
190  variable pllClk : real;
191  variable rate : real;
192  variable found : boolean;
193  begin
194  found := false;
195  -- Walk through all possible configs and look for one that works
196  dloop : for d in QPLL_OUT_DIV_VALIDS_C'range loop
197  mloop : for m in QPLL_REFCLK_DIV_VALIDS_C'range loop
198  nloop : for n in QPLL_FBDIV_INT_VALIDS_C'range loop
199 
200  vcoClk := refClkFreq * real(QPLL_FBDIV_INT_VALIDS_C(n)) /
201  (real(QPLL_REFCLK_DIV_VALIDS_C(m)));
202  pllClk := vcoClk / 2.0;
203  rate := pllClk * 2.0 / real(QPLL_OUT_DIV_VALIDS_C(d));
204 
205 -- report
206 -- "--------" & lf &
207 -- "M: " & integer'image(QPLL_REFCLK_DIV_VALIDS_C(m)) & lf &
208 -- "N: " & integer'image(QPLL_FBDIV_INT_VALIDS_C(n)) & lf &
209 -- "D: " & integer'image(QPLL_OUT_DIV_VALIDS_C(d)) & lf &
210 -- "vcoClk: " & real'image(vcoClk) & lf &
211 -- "pllClk: " & real'image(pllClk) & lf &
212 -- "rate: " & real'image(rate) & lf
213 -- severity note;
214 
215  if ( rate = lineRate) then
216  if (vcoClk >= QPLL_LOWER_BAND_LOW_C and vcoClk <= QPLL_LOWER_BAND_HIGH_C) then
218  found := true;
219  elsif (vcoClk >= QPLL_UPPER_BAND_LOW_C and vcoClk <= QPLL_UPPER_BAND_HIGH_C) then
221  found := true;
222  end if;
223 
224  if (found) then
226  ret.QPLL_FBDIV_G := getQPllFbdiv(QPLL_FBDIV_INT_VALIDS_C(n));
227  if (QPLL_FBDIV_INT_VALIDS_C(n) = 66) then
228  ret.QPLL_FBDIV_RATIO_G := '0';
229  else
230  ret.QPLL_FBDIV_RATIO_G := '1';
231  end if;
233  ret.CLK25_DIV_G := integer(refClkFreq / 25.0E6);
234 -- report "FOUND!!!" severity note;
235  exit dloop;
236  end if;
237  end if;
238  end loop;
239  end loop;
240  end loop;
241 
242  assert (found) report "getGtx7QPllCfg: no feasible configuration found for refClkFreq: " &
243  real'image(refClkFreq) & " and lineRate: " & real'image(lineRate) severity failure;
244  return ret;
245 
246  end function;
247 
248  -------------------------------------------------------------------------------------------------
249  -- GT Config
250  -------------------------------------------------------------------------------------------------
251  function getGtx7Cfg (
252  txPll : string;
253  rxPll : string;
254  cPllCfg : Gtx7CPllCfgType;
255  qPllCfg : Gtx7QPllCfgType)
256  return Gtx7CfgType is
257  variable ret : Gtx7CfgType;
258  begin
259  ret.CPLL_REFCLK_DIV_G := cPllCfg.CPLL_REFCLK_DIV_G;
260  ret.CPLL_FBDIV_G := cPllCfg.CPLL_FBDIV_G;
261  ret.CPLL_FBDIV_45_G := cPllCfg.CPLL_FBDIV_45_G;
262 
263  if (txPll = "CPLL") then
264  ret.TXOUT_DIV_G := cPllCfg.OUT_DIV_G;
265  ret.TX_CLK25_DIV_G := cPllCfg.CLK25_DIV_G;
266  elsif (txPll = "QPLL") then
267  ret.TXOUT_DIV_G := qPllCfg.OUT_DIV_G;
268  ret.TX_CLK25_DIV_G := qPllCfg.CLK25_DIV_G;
269  else
270  assert (false) report "Gtx7CfgPkg: getGtx7Cfg: Illegal TX PLL type: " & txPll severity failure;
271  end if;
272 
273  if (rxPll = "CPLL") then
274  ret.RXOUT_DIV_G := cPllCfg.OUT_DIV_G;
275  ret.RX_CLK25_DIV_G := cPllCfg.CLK25_DIV_G;
276  elsif (rxPll = "QPLL") then
277  ret.RXOUT_DIV_G := qPllCfg.OUT_DIV_G;
278  ret.RX_CLK25_DIV_G := qPllCfg.CLK25_DIV_G;
279  else
280  assert (false) report "Gtx7CfgPkg: getGtx7Cfg: Illegal RX PLL type: " & rxPll severity failure;
281  end if;
282 
283  return ret;
284  end function getGtx7Cfg;
285 
286 
287 end package body Gtx7CfgPkg;
real := 3.3E9 CPLL_HIGH_C
Definition: Gtx7CfgPkg.vhd:51
integer CLK25_DIV_G
Definition: Gtx7CfgPkg.vhd:42
IntegerArray :=( 1, 2, 3, 4) QPLL_REFCLK_DIV_VALIDS_C
Definition: Gtx7CfgPkg.vhd:70
integer QPLL_REFCLK_DIV_G
Definition: Gtx7CfgPkg.vhd:60
IntegerArray :=( 1, 2, 4, 8, 16) QPLL_OUT_DIV_VALIDS_C
Definition: Gtx7CfgPkg.vhd:72
std_logic sl
Definition: StdRtlPkg.vhd:28
real := 8.0E9 QPLL_LOWER_BAND_HIGH_C
Definition: Gtx7CfgPkg.vhd:75
real := 12.5E9 QPLL_UPPER_BAND_HIGH_C
Definition: Gtx7CfgPkg.vhd:77
IntegerArray :=( 1, 2) CPLL_REFCLK_DIV_VALIDS_C
Definition: Gtx7CfgPkg.vhd:45
bit_vector := x"0680181" QPLL_CFG_VCO_UPPER_C
Definition: Gtx7CfgPkg.vhd:67
IntegerArray :=( 4, 5) CPLL_FBDIV_45_VALIDS_C
Definition: Gtx7CfgPkg.vhd:47
real := 5.93E9 QPLL_LOWER_BAND_LOW_C
Definition: Gtx7CfgPkg.vhd:74
sl := '1' GTX7CFG_1_C
Definition: Gtx7CfgPkg.vhd:32
bit_vector( 9 downto 0) QPLL_FBDIV_G
Definition: Gtx7CfgPkg.vhd:62
integer RXOUT_DIV_G
Definition: Gtx7CfgPkg.vhd:90
IntegerArray :=( 1, 2, 4, 8) CPLL_OUT_DIV_VALIDS_C
Definition: Gtx7CfgPkg.vhd:48
Gtx7CfgType getGtx7CfgtxPll,rxPll,cPllCfg,qPllCfg,
Definition: Gtx7CfgPkg.vhd:96
integer CPLL_FBDIV_G
Definition: Gtx7CfgPkg.vhd:39
integer TX_CLK25_DIV_G
Definition: Gtx7CfgPkg.vhd:93
integer CPLL_FBDIV_45_G
Definition: Gtx7CfgPkg.vhd:40
bit_vector getQPllFbdivfbdivInt,
Definition: Gtx7CfgPkg.vhd:79
integer TXOUT_DIV_G
Definition: Gtx7CfgPkg.vhd:91
integer CPLL_REFCLK_DIV_G
Definition: Gtx7CfgPkg.vhd:38
Gtx7CPllCfgType getGtx7CPllCfgrefClkFreq,lineRate,
Definition: Gtx7CfgPkg.vhd:53
Gtx7QPllCfgType getGtx7QPllCfgrefClkFreq,lineRate,
Definition: Gtx7CfgPkg.vhd:81
integer RX_CLK25_DIV_G
Definition: Gtx7CfgPkg.vhd:92
sl := '0' GTX7CFG_0_C
Definition: Gtx7CfgPkg.vhd:31
integer OUT_DIV_G
Definition: Gtx7CfgPkg.vhd:41
IntegerArray :=( 1, 2, 3, 4, 5) CPLL_FBDIV_VALIDS_C
Definition: Gtx7CfgPkg.vhd:46
bit_vector := x"06801C1" QPLL_CFG_VCO_LOWER_C
Definition: Gtx7CfgPkg.vhd:68
real := 1.6E9 CPLL_LOW_C
Definition: Gtx7CfgPkg.vhd:50
IntegerArray :=( 16, 20, 32, 40, 64, 66, 80, 100) QPLL_FBDIV_INT_VALIDS_C
Definition: Gtx7CfgPkg.vhd:71
array(natural range <> ) of integer IntegerArray
Definition: StdRtlPkg.vhd:33
real := 9.8E9 QPLL_UPPER_BAND_LOW_C
Definition: Gtx7CfgPkg.vhd:76
bit_vector( 27 downto 0) QPLL_CFG_G
Definition: Gtx7CfgPkg.vhd:59
bit QPLL_FBDIV_RATIO_G
Definition: Gtx7CfgPkg.vhd:61