Belle II KLM Scint Firmware  1
b2tt_clk_s6.vhd
1 ------------------------------------------------------------------------
2 --
3 -- b2tt_clk_s6.vhd --- clock for Spartan 6
4 --
5 -- Mikihiko Nakao, KEK IPNS
6 --
7 -- 20120409 0.01 new
8 -- 20130411 0.02 renamed from mnictrl
9 -- 20130718 0.03 packed into b2tt_clk
10 -- 20131011 0.04 renamed to b2tt_clk_v5 for virtex5
11 -- 20131012 0.05 unification with v6 as much as possible
12 -- 20131101 0.06 no more std_logic_arith
13 -- 20141008 0.08 rawclkg
14 -- 20150105 0.09 rawclk after bufg (no more rawclkg) / no more FLIPCLK
15 -- 20150630 0.10 dummy USE254IN generic
16 ------------------------------------------------------------------------
17 
18 ------------------------------------------------------------------------
19 -- b2tt_clk
20 ------------------------------------------------------------------------
21 library ieee;
22 use ieee.std_logic_1164.all;
23 use ieee.std_logic_unsigned.all;
24 use ieee.numeric_std.all;
25 library unisim;
26 use unisim.vcomponents.all;
27 
28 entity b2tt_clk is
29  generic (
30  USEPLL : std_logic := '1'; -- unused flag, PLL is always used in s6
31  USEICTRL : std_logic := '0';
32  USE254IN : std_logic := '0' ); -- dummy for s6 (only used by v6/DHH)
33  port (
34  clkp : in std_logic;
35  clkn : in std_logic;
36  reset : in std_logic;
37  rawclk : out std_logic;
38  clock : out std_logic;
39  invclock : out std_logic; -- (only for Spartan-6)
40  dblclock : out std_logic; -- (only for Virtex-6)
41  dblclockb : out std_logic; -- (only for Virtex-6)
42  hlfclock : out std_logic;
43  locked : out std_logic;
44  stat : out std_logic_vector (1 downto 0) );
45 end b2tt_clk;
46 
47 architecture implementation of b2tt_clk is
48  signal clk_127 : std_logic := '0';
49  signal sig_127 : std_logic := '0';
50 
51  signal sig_fbout : std_logic := '0';
52  -- signal sig_xcm203 : std_logic := '0'; -- #CK commented out this line
53  signal clk_fb : std_logic := '0';
54  -- signal clk_203 : std_logic := '0'; -- #CK commented out this line
55 
56  signal sta_xcm : std_logic := '0';
57  signal clr_xcm : std_logic := '0';
58  signal sta_ictrl : std_logic := '1';
59  signal clr_ictrl : std_logic := '0';
60  signal cnt_xcmreset : std_logic_vector (3 downto 0) := (others => '0');
61  signal cnt_xcmlock : std_logic_vector (13 downto 0) := (others => '0');
62  signal cnt_ictrl : std_logic_vector (9 downto 0) := (others => '0');
63 
64  signal clk_xcm127 : std_logic := '0';
65  signal sig_xcm127 : std_logic := '0';
66  signal sig_xcm127b : std_logic := '0';
67  signal sig_inv127 : std_logic := '0';
68  signal sig_xcm254 : std_logic := '0';
69  signal sig_clk3 : std_logic := '0';
70 
71  signal cnt_lck : std_logic_vector(15 downto 0) := (others => '0');
72  signal sig_lckd : std_logic := '0';
73 
74 begin
75  ------------------------------------------------------------------------
76  -- clock buffers
77  ------------------------------------------------------------------------
78  rawclk <= clk_127;
79  map_ick: ibufds port map ( o => sig_127, i => clkp, ib => clkn );
80  map_ig: bufg port map ( i => sig_127, o => clk_127 );
81 
82  map_fb: bufg port map ( i => sig_fbout, o => clk_fb );
83  -- map_203g: bufg port map ( i => sig_xcm203, o => clk_203 ); -- #CK commented out this line
84 
85  -----------------------------------------------------------------------
86  -- PLL (always needed in Spartan 6)
87  ------------------------------------------------------------------------
88 
89  -- unused in the Spartan 6 design
90  --dblclock <= '0'; --! comment
91  dblclockb <= '0';
92 
93  clock <= clk_xcm127;
94  map_127g: bufg port map ( i => sig_xcm127, o => clk_xcm127 );
95  map_invg: bufg port map ( i => sig_xcm127b, o => invclock );
96  map_254g: bufg port map ( i => sig_xcm254, o => dblclock );--!add
97  map_64g: bufg port map ( i => sig_clk3, o => hlfclock );--!add
98 
99  map_pll: pll_base
100  generic map (
101  CLKIN_PERIOD => 7.861, -- F_VCO has to be between 400 - 1000 MHz #CK
102  -- CLKIN_PERIOD => 7.8, -- F_VCO has to be between 400 - 1000 MHz
103  CLKFBOUT_MULT => 16, -- F_VCO = F_CLKIN * CLKFBOUT_MULT --8
104  DIVCLK_DIVIDE => 2, -- / DIVCLK_DIVIDE --1
105  CLKOUT0_DIVIDE => 8, -- F_OUT = F_VCO / CLKOUTn_DIVIDE --8
106  CLKOUT1_DIVIDE => 8, --8
107  CLKOUT1_PHASE => 180.0,
108  CLKOUT2_DIVIDE => 4,
109  CLKOUT2_PHASE => 0.0,
110  CLKOUT3_DIVIDE => 16, --16
111  CLKOUT3_PHASE => 0.0,
112  --CLKOUT4_DIVIDE => 5,
113  REF_JITTER => 0.2, -- #CK
114  BANDWIDTH => "OPTIMIZED" )
115  port map (
116  clkin => clk_127,
117  rst => reset,
118  clkfbout => sig_fbout,
119  clkout0 => sig_xcm127,
120  clkout1 => sig_xcm127b,
121  clkout2 => sig_xcm254,
122  clkout3 => sig_clk3,
123  --clkout4 => sig_clk4,
124  locked => sta_xcm,
125  clkfbin => clk_fb );
126 
127  ------------------------------------------------------------------------
128  -- no idelayctrl for Spartan 6
129  ------------------------------------------------------------------------
130  sta_ictrl <= '1';
131 
132  ------------------------------------------------------------------------
133  -- reset
134  -- idelayctrl initial reset (>3us or >385clk)
135  -- XCM at least 3 clkin to reset, several thousand clocks to lock
136  ------------------------------------------------------------------------
137  proc_reset: process (clk_127)
138  begin
139  if clk_127'event and clk_127 = '1' then
140  -- XCM reset
141  if cnt_xcmreset(3) = '0' then
142  clr_xcm <= '1';
143  cnt_xcmreset <= cnt_xcmreset + 1;
144  cnt_xcmlock <= (others => '0');
145  elsif cnt_xcmlock(13) = '0' then
146  clr_xcm <= '0';
147  cnt_xcmlock <= cnt_xcmlock + 1;
148  elsif reset = '1' or sta_xcm = '0' then
149  cnt_xcmreset <= (others => '0');
150  end if;
151 
152  -- IDELAYCTRL reset
153  if clr_xcm = '1' or sta_xcm = '0' then
154  cnt_ictrl <= (others => '0');
155  elsif cnt_ictrl(9) = '0' then
156  clr_ictrl <= '1';
157  cnt_ictrl <= cnt_ictrl + 1;
158  else
159  clr_ictrl <= '0';
160  end if;
161  end if;
162  end process;
163 
164  process(clk_xcm127)
165  begin
166  if rising_edge(clk_xcm127) then
167  if sta_xcm = '1' then
168  if cnt_lck(13) = '1' then
169  sig_lckd <= '1';
170  else
171  sig_lckd <= '0';
172  cnt_lck <= cnt_lck + 1;
173  end if;
174  end if;
175  end if;
176  end process;
177 
178  --stat <= sta_ictrl & sig_lckd;
179  --locked <= sig_lckd and sta_xcm;
180 
181  -- out
182  stat <= sta_ictrl & sta_xcm;
183  locked <= sta_ictrl and sta_xcm;
184 
185 end implementation;
pll_base map_pllmap_pll
add
std_logic := '0' sig_xcm254
uncomment
Definition: b2tt_clk_s6.vhd:68
out hlfclockstd_logic
add
Definition: b2tt_clk_s6.vhd:42
std_logic := '0' sig_clk3
add
Definition: b2tt_clk_s6.vhd:69