AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
s6link_adapt_top_dfe.vhd
1 --////////////////////////////////////////////////////////////////////////////////
2 --// ____ ____
3 --// / /\/ /
4 --// /___/ \ / Vendor: Xilinx
5 --// \ \ \/ Version : 2.5
6 --// \ \ Application : 7 Series FPGAs Transceivers Wizard
7 --// / / Filename :s6link_adapt_top_dfe.vhd
8 --// /___/ /\
9 --// \ \ / \
10 --// \___\/\___\
11 --//
12 --//
13 -- Description : This module performs TX reset and initialization.
14 --
15 --
16 --
17 -- Module S6Link_adapt_top_dfe
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.STD_LOGIC_UNSIGNED.ALL;
73 use IEEE.STD_LOGIC_ARITH.ALL;
74 use IEEE.NUMERIC_STD.ALL;
75 
76 library unisim;
77 use unisim.vcomponents.all;
78 
80  generic (
81  AGC_TIMER : integer range 0 to 4095:= 150
82  );
83  port (
84  EN : in STD_LOGIC;
85  CTLE3_COMP_EN : in STD_LOGIC;
86  GTRXRESET : in STD_LOGIC;
87  RXPMARESET : in STD_LOGIC;
88  RXDFELPMRESET : in STD_LOGIC;
89  DCLK : in STD_LOGIC;
90  DO : in STD_LOGIC_VECTOR(15 downto 0);
91  DRDY : in STD_LOGIC;
92  DADDR : out STD_LOGIC_VECTOR(8 downto 0);
93  DI : out STD_LOGIC_VECTOR(15 downto 0);
94  DEN : out STD_LOGIC;
95  DWE : out STD_LOGIC;
96  RXMONITOR : in STD_LOGIC_VECTOR(6 downto 0);
97  RXMONITORSEL : out STD_LOGIC_VECTOR(1 downto 0);
98  AGCHOLD : out STD_LOGIC;
99  KLHOLD : out STD_LOGIC;
100  KHHOLD : out STD_LOGIC;
101  DONE : out STD_LOGIC;
102  DEBUG : out STD_LOGIC_VECTOR(53 downto 0)
103  );
104 end S6Link_ADAPT_TOP_DFE;
105 
106 architecture Behavioral of S6Link_ADAPT_TOP_DFE is
107 
108 component S6Link_adapt_starter
109 generic(
110  WAIT_CYC :integer range 0 to 16 := 10
111 );
112 port (
113 RST : in STD_LOGIC;
114 CLK : in STD_LOGIC;
115 DO : in STD_LOGIC_VECTOR(15 downto 0);
116 DRDY : in STD_LOGIC;
117 DADDR : out STD_LOGIC_VECTOR(8 downto 0);
118 DEN : out STD_LOGIC;
119 DWE : out STD_LOGIC;
120 READY : out STD_LOGIC;
121 curr_state_debug : out STD_LOGIC_VECTOR(3 downto 0);
122 counter_debug : out STD_LOGIC_VECTOR(2 downto 0);
123 rst_int_debug : out STD_LOGIC
124 );
125 end component;
126 
127 component S6Link_ctle_agc_comp
128 generic(
129  AGC_TIMER: integer range 0 to 4095 := 150
130 );
131 port (
132  RST : in STD_LOGIC; --RST low starts state machine
133  DONE : out STD_LOGIC; --DONE asserted when complete, deasserted with RST high
134  DRDY : in STD_LOGIC; --Connect to Channel DRP
135  DO : in STD_LOGIC_VECTOR(15 downto 0); --Connect to Channel DRP
136  DCLK : in STD_LOGIC; --Connect to same clk as Channel DRP DCLK
137  DADDR : out STD_LOGIC_VECTOR(8 downto 0); --Connect to Channel DRP
138  DI : out STD_LOGIC_VECTOR(15 downto 0); --Connect to Channel DRP
139  DEN : out STD_LOGIC; --Connect to Channel DRP
140  DWE : out STD_LOGIC; --Connect to Channel DRP
141  RXMONITOR : in STD_LOGIC_VECTOR(6 downto 0); --Connect to RXMONITOR port
142  RXMONITORSEL : out STD_LOGIC_VECTOR(1 downto 0); --Connect to RXMONITORSEL port
143  curr_state : out STD_LOGIC_VECTOR(3 downto 0);
144  agc_railing : out STD_LOGIC
145 );
146 end component;
147 
148 component S6Link_agc_loop_fsm
149 generic(
150  usr_clk : integer range 0 to 4095 :=150
151 );
152 port (
153 DCLK,reset,DRDY : in std_logic;
154 D0 : in STD_LOGIC_VECTOR(15 downto 0);
155 DI : out STD_LOGIC_VECTOR(15 downto 0);
156 holds : out STD_LOGIC_VECTOR(3 downto 0);
157 DWE,DEN : out std_logic;
158 DADDR : out STD_LOGIC_VECTOR(8 downto 0);
159 kill : out std_logic;
160 state : out STD_LOGIC_VECTOR(3 downto 0);
161 count_lock_out : out STD_LOGIC_VECTOR(31 downto 0);
162 lock0,lock1,lock2,lock3 : out std_logic
163 );
164 end component;
165 
166 signal rst : std_logic;
167 signal start_done : std_logic;
168 signal done_pre : std_logic;
169 signal lock_done : std_logic;
170 signal ctle3_done : std_logic;
171 signal en_b : std_logic;
172 
173 --DRP-related
174 signal daddr_starter : std_logic_vector(8 downto 0);
175 signal den_starter : std_logic;
176 signal dwe_starter : std_logic;
177 
178 signal daddr_lock : std_logic_vector(8 downto 0);
179 signal den_lock : std_logic;
180 signal dwe_lock : std_logic;
181 signal di_lock : std_logic_vector(15 downto 0);
182 
183 signal daddr_ctle : std_logic_vector(8 downto 0);
184 signal den_ctle : std_logic;
185 signal dwe_ctle : std_logic;
186 signal di_ctle : std_logic_vector(15 downto 0);
187 
188 signal holds : std_logic_vector(3 downto 0);
189 
190 signal rst_lock : std_logic;
191 signal rst_ctle : std_logic;
192 signal rst_ctle_b : std_logic;
193 signal rst_ctle_pre : std_logic;
194 
195 signal lock_done_r : std_logic;
196 signal lock_done_r2 : std_logic;
197 
198 --Debug signals
199 signal lock_state : std_logic_vector(3 downto 0);
200 signal lock_count : std_logic_vector(31 downto 0);
201 signal lock0 : std_logic;
202 signal lock1 : std_logic;
203 signal lock2 : std_logic;
204 signal lock3 : std_logic;
205 signal starter_state : std_logic_vector(3 downto 0);
206 signal starter_count : std_logic_vector(2 downto 0);
207 signal starter_rst_int : std_logic;
208 signal ctle_state : std_logic_vector(3 downto 0);
209 signal lock_done_rise : std_logic;
210 signal done_reg : std_logic;
211 
212 begin
213 ------------------------------------------------------------/
214 rst <= ((GTRXRESET or RXPMARESET or RXDFELPMRESET) and EN);
215 en_b <= not(EN);
216 --assign rst_lock = ~start_done | en_b;
217 --assign rst_ctle = ~lock_done | ~CTLE3_COMP_EN | en_b;
218 rst_lock <= not(start_done);
219 rst_ctle_pre <= (not(lock_done) or not(CTLE3_COMP_EN));
220 rst_ctle <= not(rst_ctle_b);
221 done_pre <= ctle3_done when CTLE3_COMP_EN='1' else lock_done;
222 DONE <= done_reg;
223 done_reg <= (done_pre and start_done); --So that DONE goes low immediately after any of RESET's is asserted
224 
225 --Start CTLE only after lock was just done. Don't want to start if user just asserted CTLE3_COMP_EN while lock_done already high.
226 rst_ctle_rise_sr_ff : FDCE
227 generic map ( INIT => '0'
228 )
229 port map (
230  Q => rst_ctle_b,
231  CLR => rst_ctle_pre,
232  D => '1',
233  CE => lock_done_rise ,
234  C => DCLK
235  );
236 
237 process (DCLK)
238 begin
239  if rising_edge(DCLK) then
240  lock_done_r <= lock_done;
241  lock_done_r2 <= lock_done_r;
242  end if;
243 end process;
244 
245 lock_done_rise <= (not(lock_done_r2) and lock_done_r);
246 
247 DEBUG <= lock_state(3 downto 0) & lock_count(31 downto 0) & lock0 & lock1 & lock2 & lock3 & starter_state(3 downto 0) & starter_count(2 downto 0) & starter_rst_int & ctle_state(3 downto 0) & rst_lock & rst_ctle;
248 AGCHOLD <= done_reg;
249 KLHOLD <= done_reg;
250 KHHOLD <= done_reg;
251 
252 --When a block is not active, it will hold DADDR,DI,DEN,DWE low
253 DADDR <= (others => '0') when en_b='1' else (daddr_starter or daddr_lock or daddr_ctle);
254 DI <= (others => '0') when en_b='1' else (di_lock or di_ctle);
255 DEN <= '0' when en_b='1' else (den_starter or den_lock or den_ctle);
256 DWE <= '0' when en_b='1' else (dwe_starter or dwe_lock or dwe_ctle);
257 
258 ----------------------------------------
259 ---- Sequence of operation:
260 ---- adapt_starter -> triggered by any of above resets to deassert then waits for DFE LPM reset to complete
261 ---- agc_loop_fsm -> triggered by adapt_starter completion then waits for all loops to lock
262 ---- ctle_agc_comp -> triggered by agc_loop_fsmm done and adjusts CTLE3 until AGC not railing or CTLE3 at max/min.
263 ----------------------------------------
264 i_starter : S6Link_adapt_starter
265 generic map (
266  WAIT_CYC => 10
267 )
268 port map (
269  RST => rst ,
270  CLK => DCLK,
271  DO => DO,
272  DRDY => DRDY,
273  DADDR => daddr_starter,
274  DEN => den_starter,
275  DWE => dwe_starter,
276  READY => start_done,
277  curr_state_debug => starter_state(3 downto 0),
278  counter_debug => starter_count(2 downto 0),
279  rst_int_debug => starter_rst_int
280 );
281 
282 i_lock : S6Link_agc_loop_fsm
283 generic map (
284  usr_clk => AGC_TIMER
285 )
286 port map (
287  DCLK => DCLK,
288  reset => rst_lock,
289  DRDY => DRDY,
290  D0 => DO,
291  DI => di_lock,
292  DWE => dwe_lock,
293  DEN => den_lock,
294  DADDR => daddr_lock,
295  holds => holds, --RXAGCHOLD,NC,KLHOLD,KHHOLD
296  kill => lock_done,
297  state => lock_state(3 downto 0),
298  count_lock_out => lock_count(31 downto 0),
299  lock0 => lock0,
300  lock1 => lock1,
301  lock2 => lock2,
302  lock3 => lock3
303 );
304 
305 i_ctle : S6Link_ctle_agc_comp
306 generic map(
307  AGC_TIMER => AGC_TIMER
308 )
309 port map(
310  RST => rst_ctle, --RST low starts state machine
311  DONE => ctle3_done, --DONE asserted when complete, deasserted with RST high
312  DRDY => DRDY, --Connect to Channel DRP
313  DO => DO, --Connect to Channel DRP
314  DCLK => DCLK, --Connect to same clk as Channel DRP DCLK
315  DADDR => daddr_ctle, --Connect to Channel DRP
316  DI => di_ctle, --Connect to Channel DRP
317  DEN => den_ctle, --Connect to Channel DRP
318  DWE => dwe_ctle, --Connect to Channel DRP
319  RXMONITOR => RXMONITOR, --Connect to RXMONITOR port
320  RXMONITORSEL => RXMONITORSEL, --Connect to RXMONITORSEL port
321  curr_state => ctle_state(3 downto 0),
322  agc_railing => OPEN
323 );
324 
325 end Behavioral;
326