AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
s6link_agc_loop_fsm.vhd
1 --////////////////////////////////////////////////////////////////////////////////
2 --// ____ ____
3 --// / /\/ /
4 --// /___/ \ / Vendor: Xilinx
5 --// \ \ \/ Version : 2.5
6 --// \ \ Application : 7 Series FPGAs Transceivers Wizard
7 --// / / Filename :s6link_agc_loop_fsm.vhd
8 --// /___/ /\
9 --// \ \ / \
10 --// \___\/\___\
11 --//
12 --//
13 -- Description : This module performs TX reset and initialization.
14 --
15 --
16 --
17 -- Module S6Link_agc_loop_fsm
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 
71 library IEEE;
72 use IEEE.STD_LOGIC_1164.ALL;
73 
74 entity drp_wr_fsm is
75 port (
76 lock0,lock1,lock2,lock3,clk,reset,ready : in std_logic;
77 di0 : in STD_LOGIC_VECTOR(15 downto 0);
78 holds : out STD_LOGIC_VECTOR(3 downto 0);
79 DI : out STD_LOGIC_VECTOR(15 downto 0);
80 Address : out STD_LOGIC_VECTOR(8 downto 0);
81 state : out STD_LOGIC_VECTOR(3 downto 0);
82 done : out std_logic;
83 kill : out std_logic;
84 rd_drp : out std_logic;
85 wr_drp : out std_logic
86 );
87 end drp_wr_fsm;
88 
89 architecture drp_wr_fsm_beh of drp_wr_fsm is
90 
91 signal store_di0 : std_logic_vector(15 downto 0) := (others => '0');
92 
93 signal holds_reg : std_logic_vector(3 downto 0) := (others => '0');
94 signal DI_reg : std_logic_vector(15 downto 0) := (others => '0');
95 signal Address_reg : std_logic_vector(8 downto 0) := (others => '0');
96 signal state_reg : std_logic_vector(3 downto 0);
97 signal done_reg : std_logic := '0';
98 signal kill_reg : std_logic := '0';
99 signal rd_drp_reg : std_logic := '0';
100 signal wr_drp_reg : std_logic := '0';
101 signal not_kill : std_logic := '1';
102 
103 constant load_addr_agc : std_logic_vector(3 downto 0) := "0001";
104 constant rd_drp_agc : std_logic_vector(3 downto 0) := "0010";
105 constant wait_drprdy_agc : std_logic_vector(3 downto 0) := "0011";
106 constant mod_drp_agc : std_logic_vector(3 downto 0) := "0100";
107 constant load_drp_agc : std_logic_vector(3 downto 0) := "0101";
108 constant pulse_wr_agc : std_logic_vector(3 downto 0) := "0110";
109 constant wait_drp_dy_agc : std_logic_vector(3 downto 0) := "0111";
110 constant lock_agc : std_logic_vector(3 downto 0) := "1000";
111 constant endstate : std_logic_vector(3 downto 0) := "1001";
112 constant resetstate : std_logic_vector(3 downto 0) := "1010";
113 
114 begin
115 
116 holds <= holds_reg;
117 DI <= DI_reg;
118 Address <= Address_reg;
119 state <= state_reg;
120 done <= done_reg;
121 kill <= kill_reg;
122 rd_drp <= rd_drp_reg;
123 wr_drp <= wr_drp_reg;
124 not_kill <= not(kill_reg);
125 
126 process(clk)
127 begin
128 if rising_edge(clk) then
129  if(reset='1') then
130  state_reg <=resetstate;
131  holds_reg <=(others => '0');
132  DI_reg <=(others => '0');
133  Address_reg <=(others => '0');
134  wr_drp_reg <='0';
135  done_reg <='0';
136  kill_reg <='0';
137  elsif((lock0='1' or lock1='1' or lock2='1' or lock3='1') and (not_kill='1')) then
138  case state_reg is
139 
140  when resetstate =>
141  state_reg <= load_addr_agc;
142  done_reg <= '0';
143  holds_reg <= (others => '0');
144 
145  --AGC LOOP--/
146 
147  when load_addr_agc =>
148  Address_reg <= "000011101";
149  state_reg <= rd_drp_agc;
150 
151  when rd_drp_agc => -- Start Read Sequence Wait for DRPRDY
152  rd_drp_reg <= '1';
153  state_reg <= wait_drprdy_agc;
154 
155  when wait_drprdy_agc => -- Wait for DRPRDY
156  if(ready='1') then
157  store_di0 <= di0;
158  state_reg <= mod_drp_agc;
159  else
160  state_reg<=wait_drprdy_agc;
161  end if;
162 
163  when mod_drp_agc =>
164  rd_drp_reg <= '0';
165 
166  if ((lock0='1' and lock1='0' and lock2='0' and lock3='0'))then
167  store_di0(15 downto 12) <= "0110"; --/ 64X
168  state_reg <= load_drp_agc;
169  elsif (lock1='1' and lock2='0' and lock3='0') then
170  store_di0(15 downto 12) <= "0100"; --/ 16X
171  state_reg <= load_drp_agc;
172  elsif(lock2='1' and lock3='0') then
173  store_di0(15 downto 12) <= "0010"; -- 4X
174  state_reg <= load_drp_agc;
175  elsif (lock3='1') then
176  store_di0(15 downto 12) <= "0000"; --/ 1X
177  state_reg <= load_drp_agc;
178  end if;
179 
180  when load_drp_agc =>
181  state_reg <= pulse_wr_agc;
182  DI_reg <= store_di0;
183 
184  when pulse_wr_agc =>
185  wr_drp_reg <= '1';
186  state_reg <= wait_drp_dy_agc;
187 
188  when wait_drp_dy_agc =>
189  if(ready='1') then
190  wr_drp_reg <= '0';
191  DI_reg <= store_di0;
192  state_reg <= lock_agc;
193  end if;
194 
195  when lock_agc =>
196  if(done_reg='1') then
197  state_reg <= endstate;
198  elsif(lock0='1' and lock1='1') then
199  state_reg <= mod_drp_agc;
200  elsif(lock1='1' and lock2='0') then
201  state_reg <= mod_drp_agc;
202  elsif(lock2='1' and lock3='0') then
203  state_reg <= mod_drp_agc;
204  elsif(lock3='1') then
205  state_reg <= mod_drp_agc;
206  done_reg <= '1';
207  else
208  state_reg <= lock_agc;
209  end if;
210 
211 
212  when endstate =>
213  holds_reg <= "1011";
214  DI_reg <= (others => '0');
215  Address_reg <= (others => '0');
216  wr_drp_reg <= '0';
217  rd_drp_reg <= '0';
218  kill_reg <= done_reg;
219 
220  when others => state_reg <= "XXXX";
221  end case;
222 
223 end if;
224 end if;
225 end process;
226 end drp_wr_fsm_beh;
227 
228 library IEEE;
229 use IEEE.STD_LOGIC_1164.ALL;
230 use IEEE.STD_LOGIC_UNSIGNED.ALL;
231 use IEEE.STD_LOGIC_ARITH.ALL;
232 
233 entity lock_detect is
234 generic(
235  usr_clk : integer range 0 to 4095 :=150
236 );
237 port(
238  lock0,lock1,lock2,lock3,start : out std_logic;
239  count_lock_out : in std_logic_vector(31 downto 0);
240  dclk,reset : in std_logic
241 );
242 end lock_detect;
243 
244 architecture lock_detect_beh of lock_detect is
245 
246 --signal lock0_reg,lock1_reg,lock2_reg,lock3_reg : std_logic := '0';
247 
248 begin
249 
250 process(dclk)
251 begin
252 if rising_edge(dclk) then
253  if(reset ='1') then
254  lock0 <= '0';
255  lock1 <= '0';
256  lock2 <= '0';
257  lock3 <= '0';
258  start <= '0';
259  else
260  start <= '1';
261  if(count_lock_out=X"0000000A") then
262  lock0 <= '1';
263  elsif(UNSIGNED(count_lock_out)=usr_clk*40) then
264  lock1 <= '1';
265  elsif (UNSIGNED(count_lock_out)=160*usr_clk) then
266  lock2 <= '1';
267  elsif (UNSIGNED(count_lock_out)=640*usr_clk) then
268  lock3 <= '1';
269  start <= '0';
270  end if;
271  end if;
272  end if;
273 end process;
274 
275 end lock_detect_beh;
276 
277 library IEEE;
278 use IEEE.STD_LOGIC_1164.ALL;
279 use IEEE.STD_LOGIC_UNSIGNED.ALL;
280 use IEEE.STD_LOGIC_ARITH.ALL;
281 use IEEE.NUMERIC_STD.ALL;
282 
283 entity counter is
284 port (
285 reset,start,stop,dclk : in std_logic;
286 count_lock_out : out std_logic_vector(31 downto 0)
287 );
288 end counter;
289 
290 architecture counter_beh of counter is
291 
292 signal count_lock_out_reg : std_logic_vector(31 downto 0) := (others=>'0');
293 
294 begin
295 
296 count_lock_out <= count_lock_out_reg;
297 
298 process(dclk)
299 begin
300 if rising_edge(dclk) then
301  if(reset='1' or stop='1') then
302  count_lock_out_reg <= (others=>'0');
303  elsif (start='1') then
304  count_lock_out_reg <= count_lock_out_reg + 1;
305  else
306  count_lock_out_reg <= (others=>'0');
307  end if;
308 end if;
309 end process;
310 
311 end counter_beh;
312 
313 library IEEE;
314 use IEEE.STD_LOGIC_1164.ALL;
315 use IEEE.STD_LOGIC_UNSIGNED.ALL;
316 use IEEE.STD_LOGIC_ARITH.ALL;
317 use IEEE.NUMERIC_STD.ALL;
318 
320 generic(
321  usr_clk : integer range 0 to 4095 :=150
322 );
323 port (
324 
325 DCLK,reset,DRDY : in std_logic;
326 D0 : in STD_LOGIC_VECTOR(15 downto 0);
327 DI : out STD_LOGIC_VECTOR(15 downto 0);
328 holds : out STD_LOGIC_VECTOR(3 downto 0);
329 DWE,DEN : out std_logic;
330 DADDR : out STD_LOGIC_VECTOR(8 downto 0);
331 kill : out std_logic;
332 
333 -- input[7:0] usr_clk,
334 state : out STD_LOGIC_VECTOR(3 downto 0);
335 count_lock_out : out STD_LOGIC_VECTOR(31 downto 0);
336 lock0,lock1,lock2,lock3 : out std_logic
337 );
338 end S6Link_agc_loop_fsm;
339 
340 architecture Behavioral of S6Link_agc_loop_fsm is
341 
342 component drp_wr_fsm
343 port (
344 lock0,lock1,lock2,lock3,clk,reset,ready : in std_logic;
345 di0 : in STD_LOGIC_VECTOR(15 downto 0);
346 holds : out STD_LOGIC_VECTOR(3 downto 0);
347 DI : out STD_LOGIC_VECTOR(15 downto 0);
348 Address : out STD_LOGIC_VECTOR(8 downto 0);
349 state : out STD_LOGIC_VECTOR(3 downto 0);
350 done : out std_logic;
351 kill : out std_logic;
352 rd_drp : out std_logic;
353 wr_drp : out std_logic
354 );
355 end component;
356 
357 component lock_detect
358 generic(
359  usr_clk : integer range 0 to 4095 :=150
360 );
361 port(
362  lock0,lock1,lock2,lock3,start : out std_logic;
363  count_lock_out : in std_logic_vector(31 downto 0);
364  dclk,reset : in std_logic
365 );
366 end component;
367 
368 component counter
369 port (
370 reset,start,stop,dclk : in std_logic;
371 count_lock_out : out std_logic_vector(31 downto 0)
372 );
373 end component;
374 
375 signal rd_drp : std_logic;
376 signal wr_drp : std_logic;
377 signal lock0_reg,lock1_reg,lock2_reg,lock3_reg,start_reg,done_reg : std_logic;
378 signal count_lock_out_reg : std_logic_vector(31 downto 0);
379 
380 begin
381 
382 count_lock_out <= count_lock_out_reg;
383 DWE <= wr_drp;
384 DEN <= rd_drp or wr_drp;
385 lock0 <= lock0_reg;
386 lock1 <= lock1_reg;
387 lock2 <= lock2_reg;
388 lock3 <= lock3_reg;
389 
390 I1 : drp_wr_fsm
391 port map (
392 lock0 => lock0_reg,
393 lock1 => lock1_reg,
394 lock2 => lock2_reg,
395 lock3 => lock3_reg,
396 clk => DCLK,
397 reset => reset,
398 ready => DRDY,
399 holds => holds,
400 done => done_reg,
401 kill => kill,
402 state => state,
403 DI => DI,
404 di0 => D0,
405 Address => DADDR,
406 rd_drp => rd_drp,
407 wr_drp => wr_drp
408 );
409 
410 I2 : lock_detect
411 generic map (
412  usr_clk => usr_clk
413 )
414 port map (
415 start => start_reg,
416 count_lock_out => count_lock_out_reg,
417 dclk => DCLK,
418 reset => reset ,
419 lock0 => lock0_reg,
420 lock1 => lock1_reg,
421 lock2 => lock2_reg,
422 lock3 => lock3_reg
423 );
424 
425 I3 : counter
426 port map (
427 dclk => DCLK,
428 reset => reset ,
429 count_lock_out => count_lock_out_reg,
430 start => start_reg,
431 stop => done_reg
432 );
433 
434 end Behavioral;
435 
436