SURF  1.0
Gtp7CfgPkg.vhd
Go to the documentation of this file.
1 -------------------------------------------------------------------------------
2 -- File : Gtp7CfgPkg.vhd
3 -- Company : SLAC National Accelerator Laboratory
4 -- Created : 2014-09-02
5 -- Last update: 2016-11-04
6 -------------------------------------------------------------------------------
7 -- Description: Provides useful functions for generating GTP7 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 Gtp7CfgPkg is
28 --! @file
29  --! @ingroup xilinx_7Series_gtp7
30 
31  -------------------------------------------------------------------------------------------------
32  -- QPLL Config Types, Constants and Function declarations
33  -------------------------------------------------------------------------------------------------
34  type Gtp7QPllCfgType is record
35  QPLL_REFCLK_DIV_G : integer;
36  QPLL_FBDIV_G : integer;
37  QPLL_FBDIV_45_G : integer;
38  OUT_DIV_G : integer;
39  CLK25_DIV_G : integer;
40  end record;
41 
42  constant QPLL_REFCLK_DIV_VALIDS_C : IntegerArray := (1, 2);
43  constant QPLL_FBDIV_VALIDS_C : IntegerArray := (1, 2, 3, 4, 5);
44  constant QPLL_FBDIV_45_VALIDS_C : IntegerArray := (4, 5);
45  constant QPLL_OUT_DIV_VALIDS_C : IntegerArray := (1, 2, 4, 8);
46 
47  constant QPLL_LOW_C : real := 1.6E9;
48  constant QPLL_HIGH_C : real := 3.3E9;
49 
50  function getGtp7QPllCfg (refClkFreq : real; lineRate : real) return Gtp7QPllCfgType;
51 
52  function ite (i : boolean; t : Gtp7QPllCfgType; e : Gtp7QPllCfgType) return Gtp7QPllCfgType;
53 
54 
55 end package Gtp7CfgPkg;
56 
57 package body Gtp7CfgPkg is
58 
59  -------------------------------------------------------------------------------------------------
60  -- QPLL Config
61  -------------------------------------------------------------------------------------------------
62  function getGtp7QPllCfg (
63  refClkFreq : real;
64  lineRate : real)
65  return Gtp7QPllCfgType
66  is
67  variable ret : Gtp7QPllCfgType;
68  variable pllClk : real;
69  variable rate : real;
70  variable found : boolean;
71  begin
72  found := false;
73  -- Walk through all possible configs and look for one that works
74  dloop : for d in QPLL_OUT_DIV_VALIDS_C'range loop
75  mloop : for m in QPLL_REFCLK_DIV_VALIDS_C'range loop
76  n2loop : for n2 in QPLL_FBDIV_VALIDS_C'range loop
77  n1loop : for n1 in QPLL_FBDIV_45_VALIDS_C'range loop
78 
79  pllClk := refClkFreq * real(QPLL_FBDIV_VALIDS_C(n2) * QPLL_FBDIV_45_VALIDS_C(n1)) /
80  real(QPLL_REFCLK_DIV_VALIDS_C(m));
81  rate := pllClk * 2.0 / real(QPLL_OUT_DIV_VALIDS_C(d));
82 
83  if (pllClk > QPLL_LOW_C and pllClk < QPLL_HIGH_C and rate = lineRate) then
84 
89  ret.CLK25_DIV_G := integer(refClkFreq / 25.0E6);
90 
91  found := true;
92 
93 -- report "Found GTX config: " & lf &
94 -- "refClkFreq: " & real'image(refClkFreq) & lf &
95 -- "lineRate: " & real'image(lineRate) & lf &
96 -- "QPLL_REFCLK_DIV_G: " & integer'image(ret.QPLL_REFCLK_DIV_G) & lf &
97 -- "QPLL_FBDIV_G: " & integer'image(ret.QPLL_FBDIV_G) & lf &
98 -- "QPLL_FBDIV_45_G: " & integer'image(ret.QPLL_FBDIV_45_G) & lf &
99 -- "OUT_DIV_G: " & integer'image(ret.OUT_DIV_G) & lf
100 -- severity note;
101 
102  exit dloop;
103  end if;
104  end loop;
105  end loop;
106  end loop;
107  end loop;
108 
109  assert (found) report "getGtp7QPllCfg: no feasible configuration found for refClkFreq: " &
110  real'image(refClkFreq) & " and lineRate: " & real'image(lineRate) severity failure;
111  return ret;
112 
113  end function;
114 
115  function ite (i : boolean; t : Gtp7QPllCfgType; e : Gtp7QPllCfgType) return Gtp7QPllCfgType is
116  begin
117  if (i) then
118  return t;
119  else
120  return e;
121  end if;
122  end function ite;
123 
124 
125 end package body Gtp7CfgPkg;
real := 1.6E9 QPLL_LOW_C
Definition: Gtp7CfgPkg.vhd:47
integer QPLL_FBDIV_45_G
Definition: Gtp7CfgPkg.vhd:37
real := 3.3E9 QPLL_HIGH_C
Definition: Gtp7CfgPkg.vhd:48
integer CLK25_DIV_G
Definition: Gtp7CfgPkg.vhd:39
IntegerArray :=( 1, 2) QPLL_REFCLK_DIV_VALIDS_C
Definition: Gtp7CfgPkg.vhd:42
Gtp7QPllCfgType getGtp7QPllCfgrefClkFreq,lineRate,
Definition: Gtp7CfgPkg.vhd:50
integer QPLL_REFCLK_DIV_G
Definition: Gtp7CfgPkg.vhd:35
integer QPLL_FBDIV_G
Definition: Gtp7CfgPkg.vhd:36
IntegerArray :=( 1, 2, 3, 4, 5) QPLL_FBDIV_VALIDS_C
Definition: Gtp7CfgPkg.vhd:43
integer OUT_DIV_G
Definition: Gtp7CfgPkg.vhd:38
IntegerArray :=( 4, 5) QPLL_FBDIV_45_VALIDS_C
Definition: Gtp7CfgPkg.vhd:44
IntegerArray :=( 1, 2, 4, 8) QPLL_OUT_DIV_VALIDS_C
Definition: Gtp7CfgPkg.vhd:45
Gtp7QPllCfgType itei,t,e,
Definition: Gtp7CfgPkg.vhd:52
array(natural range <> ) of integer IntegerArray
Definition: StdRtlPkg.vhd:33