AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
block_sync_sm.vhd
1 -------------------------------------------------------------------------------
2 -- ____ ____
3 -- / /\/ /
4 -- /___/ \ / Vendor: Xilinx
5 -- \ \ \/ Version : 2.3
6 -- \ \ Application : 7 Series FPGAs Transceivers Wizard
7 -- / / Filename : sfp3_v2_3_block_sync_sm.vhd
8 -- /___/ /\
9 -- \ \ / \
10 -- \___\/\___\
11 --
12 --
13 -- Module BLOCK_SYNC_SM
14 -- Generated by Xilinx 7 Series FPGAs Transceivers Wizard
15 --
16 --
17 -- (c) Copyright 2010-2012 Xilinx, Inc. All rights reserved.
18 --
19 -- This file contains confidential and proprietary information
20 -- of Xilinx, Inc. and is protected under U.S. and
21 -- international copyright and other intellectual property
22 -- laws.
23 --
24 -- DISCLAIMER
25 -- This disclaimer is not a license and does not grant any
26 -- rights to the materials distributed herewith. Except as
27 -- otherwise provided in a valid license issued to you by
28 -- Xilinx, and to the maximum extent permitted by applicable
29 -- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
30 -- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
31 -- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
32 -- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
33 -- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
34 -- (2) Xilinx shall not be liable (whether in contract or tort,
35 -- including negligence, or under any other theory of
36 -- liability) for any loss or damage of any kind or nature
37 -- related to, arising under or in connection with these
38 -- materials, including for any direct, or any indirect,
39 -- special, incidental, or consequential loss or damage
40 -- (including loss of data, profits, goodwill, or any type of
41 -- loss or damage suffered as a result of any action brought
42 -- by a third party) even if such damage or loss was
43 -- reasonably foreseeable or Xilinx had been advised of the
44 -- possibility of the same.
45 --
46 -- CRITICAL APPLICATIONS
47 -- Xilinx products are not designed or intended to be fail-
48 -- safe, or for use in any application requiring fail-safe
49 -- performance, such as life-support or safety devices or
50 -- systems, Class III medical devices, nuclear facilities,
51 -- applications related to the deployment of airbags, or any
52 -- other applications that could lead to death, personal
53 -- injury, or severe property or environmental damage
54 -- (individually and collectively, "Critical
55 -- Applications"). Customer assumes the sole risk and
56 -- liability of any use of Xilinx products in Critical
57 -- Applications, subject only to applicable laws and
58 -- regulations governing limitations on product liability.
59 --
60 -- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
61 -- PART OF THIS FILE AT ALL TIMES.
62 
63 
64 library ieee;
65 use ieee.std_logic_1164.all;
66 use ieee.numeric_std.all;
67 library UNISIM;
68 use UNISIM.VCOMPONENTS.ALL;
69 
70 entity BLOCK_SYNC_SM is
71 generic
72 (
73  SH_CNT_MAX : integer := 64;
74  SH_INVALID_CNT_MAX : integer := 16
75 );
76 port
77 (
78  -- User Interface
79  BLOCKSYNC_OUT : out std_logic;
80  RXGEARBOXSLIP_OUT : out std_logic;
81  RXHEADER_IN : in std_logic_vector(2 downto 0);
82  RXHEADERVALID_IN : in std_logic;
83 
84  -- System Interface
85  USER_CLK : in std_logic;
86  SYSTEM_RESET : in std_logic
87 );
88 
89 
90 end BLOCK_SYNC_SM;
91 
92 architecture RTL of BLOCK_SYNC_SM is
93 
94 --***********************************Parameter Declarations********************
95 
96  constant DLY : time := 10 ps;
97 
98 --********************************* Wire Declarations**************************
99 
100  signal next_begin_c : std_logic;
101  signal next_sh_invalid_c : std_logic;
102  signal next_sh_valid_c : std_logic;
103  signal next_slip_c : std_logic;
104  signal next_sync_done_c : std_logic;
105  signal next_test_sh_c : std_logic;
106  signal sh_count_equals_max_i : std_logic;
107  signal sh_invalid_cnt_equals_max_i : std_logic;
108  signal sh_invalid_cnt_equals_zero_i : std_logic;
109  signal slip_done_i : std_logic;
110  signal slip_pulse_i : std_logic;
111  signal sync_found_i : std_logic;
112 
113 ---***************************Internal Register Declarations***************************
114 
115  signal begin_r : std_logic;
116  signal blocksync_out_i : std_logic;
117  signal rxgearboxslip_out_i : std_logic;
118  signal sh_invalid_r : std_logic;
119  signal sh_valid_r : std_logic;
120  signal slip_count_i : std_logic_vector(31 downto 0);
121  signal slip_r : std_logic;
122  signal sync_done_r : std_logic;
123  signal sync_header_count_i : unsigned(9 downto 0);
124  signal sync_header_invalid_count_i : unsigned(9 downto 0);
125  signal test_sh_r : std_logic;
126 
127 ---**************************** Main Body of Code *******************************
128 begin
129 
130 
131  sync_found_i <= '1' when ((RXHEADER_IN(1 downto 0) = "01") or (RXHEADER_IN(1 downto 0) = "10")) else '0';
132 
133  ---________________________________ State machine __________________________
134 
135  --- State registers
136  process( USER_CLK )
137  begin
138  if(USER_CLK'event and USER_CLK = '1') then
139  if(SYSTEM_RESET = '1') then
140  begin_r <= '1' after DLY;
141  test_sh_r <= '0' after DLY;
142  sh_valid_r <= '0' after DLY;
143  sh_invalid_r <= '0' after DLY;
144  slip_r <= '0' after DLY;
145  sync_done_r <= '0' after DLY;
146  else
147  begin_r <= next_begin_c after DLY;
148  test_sh_r <= next_test_sh_c after DLY;
149  sh_valid_r <= next_sh_valid_c after DLY;
150  sh_invalid_r <= next_sh_invalid_c after DLY;
151  slip_r <= next_slip_c after DLY;
152  sync_done_r <= next_sync_done_c after DLY;
153  end if;
154  end if;
155  end process;
156 
157  --- Next state logic
158  next_begin_c <= sync_done_r
159  or (slip_r and slip_done_i)
160  or (sh_valid_r and sh_count_equals_max_i and not sh_invalid_cnt_equals_max_i)
161  or (sh_invalid_r and sh_count_equals_max_i and not sh_invalid_cnt_equals_max_i and blocksync_out_i);
162 
163  next_test_sh_c <= begin_r
164  or (test_sh_r and not RXHEADERVALID_IN)
165  or (sh_valid_r and not sh_count_equals_max_i)
166  or (sh_invalid_r and not sh_count_equals_max_i and not sh_invalid_cnt_equals_max_i and blocksync_out_i);
167 
168 
169  next_sh_valid_c <= (test_sh_r and RXHEADERVALID_IN and sync_found_i);
170 
171  next_sh_invalid_c <= (test_sh_r and RXHEADERVALID_IN and not sync_found_i);
172 
173  next_slip_c <= (sh_invalid_r and (sh_invalid_cnt_equals_max_i or not blocksync_out_i))
174  or (slip_r and not slip_done_i);
175 
176  next_sync_done_c <= (sh_valid_r and sh_count_equals_max_i and sh_invalid_cnt_equals_zero_i);
177 
178  ---________________ Counter keep track of sync headers counted _____________
179 
180  process( USER_CLK )
181  begin
182  if(USER_CLK'event and USER_CLK = '1') then
183  if(begin_r = '1') then
184  sync_header_count_i <= (others => '0') after DLY;
185  elsif ((sh_valid_r= '1') or (sh_invalid_r = '1')) then
186  sync_header_count_i <= sync_header_count_i + 1 after DLY;
187  end if;
188  end if;
189  end process;
190 
191  sh_count_equals_max_i <= '1' when (sync_header_count_i=SH_CNT_MAX) else '0';
192 
193  ---________________ Counter keep track of invalid sync headers ____________
194 
195  process( USER_CLK )
196  begin
197  if(USER_CLK'event and USER_CLK = '1') then
198  if(begin_r = '1') then
199  sync_header_invalid_count_i <= (others => '0') after DLY;
200  elsif (sh_invalid_r = '1') then
201  sync_header_invalid_count_i <= sync_header_invalid_count_i + 1 after DLY;
202  end if;
203  end if;
204  end process;
205 
206  --- signal to indicate max number of invalid sync headers has been reached
207  sh_invalid_cnt_equals_max_i <= '1' when (sync_header_invalid_count_i=SH_INVALID_CNT_MAX)
208  else '0';
209 
210  --- signal to indicate no invalid sync headers
211  sh_invalid_cnt_equals_zero_i <= '1' when (sync_header_invalid_count_i=0) else '0';
212 
213  ---_______ Counter wait for 16 cycles to ensure that slip is complete _______
214 
215  slip_pulse_i <= next_slip_c and not slip_r;
216 
217  process( USER_CLK )
218  begin
219  if(USER_CLK'event and USER_CLK = '1') then
220  rxgearboxslip_out_i <= slip_pulse_i after DLY;
221  end if;
222  end process;
223 
224  ---_____________ Ouput assignment to indicate block sync complete _________
225 
226  process( USER_CLK )
227  begin
228  if(USER_CLK'event and USER_CLK = '1') then
229  if(slip_r = '0') then
230  slip_count_i <= (others => '0') after DLY;
231  else
232  slip_count_i <= (slip_count_i(30 downto 0) & rxgearboxslip_out_i) after DLY;
233  end if;
234  end if;
235  end process;
236 
237  slip_done_i <= slip_count_i(31);
238 
239 
240  ---_____________ Pulse GEARBOXSLIP port to slip the data by 1 bit _________
241 
242  process( USER_CLK )
243  begin
244  if(USER_CLK'event and USER_CLK = '1') then
245  if((SYSTEM_RESET='1') or (slip_r= '1')) then
246  blocksync_out_i <= '0' after DLY;
247  elsif (sync_done_r = '1') then
248  blocksync_out_i <= '1' after DLY;
249  end if;
250  end if;
251  end process;
252 
253 
254  --__________________________ Ouput Port Assignment ________________________
255 
256  BLOCKSYNC_OUT <= blocksync_out_i;
257  RXGEARBOXSLIP_OUT <= rxgearboxslip_out_i;
258 
259 end RTL;
260 
261