AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
DAQ_LINK_Kintex.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 10:14:48 04/20/2014
6 -- Design Name:
7 -- Module Name: DAQ_LINK - Behavioral
8 -- Project Name:
9 -- Target Devices:
10 -- Tool versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 library IEEE;
21 use IEEE.STD_LOGIC_1164.ALL;
22 use IEEE.STD_LOGIC_ARITH.ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.ALL;
24 use IEEE.std_logic_misc.all;
25 
26 -- Uncomment the following library declaration if using
27 -- arithmetic functions with Signed or Unsigned values
28 --use IEEE.NUMERIC_STD.ALL;
29 
30 -- Uncomment the following library declaration if instantiating
31 -- any Xilinx primitives in this code.
32 library UNISIM;
33 use UNISIM.VComponents.all;
34 Library UNIMACRO;
35 use UNIMACRO.vcomponents.all;
36 
37 entity DAQ_LINK_Kintex is
38  Generic (
39 -- REFCLK frequency, select one among 100, 125, 200 and 250
40 -- If your REFCLK frequency is not in the list, please contact wusx@bu.edu
41  F_REFCLK : integer := 125;
42  SYSCLK_IN_period : integer := 10; -- unit is ns
43 -- If you do not use the trigger port, set it to false
44  USE_TRIGGER_PORT : boolean := true;
45  simulation : boolean := false);
46  Port (
47  reset : in STD_LOGIC; -- asynchronous reset, assert reset until GTX REFCLK stable
48 -- GTX signals
49  GTX_REFCLK : in STD_LOGIC;
50  GTX_RXN : in STD_LOGIC;
51  GTX_RXP : in STD_LOGIC;
52  GTX_TXN : out STD_LOGIC;
53  GTX_TXP : out STD_LOGIC;
54 -- TRIGGER port
55  TTCclk : in STD_LOGIC;
56  BcntRes : in STD_LOGIC;
57  trig : in STD_LOGIC_VECTOR (7 downto 0);
58 -- TTS port
59  TTSclk : in STD_LOGIC; -- clock source which clocks TTS signals
60  TTS : in STD_LOGIC_VECTOR (3 downto 0);
61 -- SYSCLK_IN is required by the GTX ip core, you can connect any clock source(e.g. TTSclk, TTCclk or EventDataClk) as long as its period is in the range of 8-250ns
62 -- do not forget to specify its period in the generic port
63  SYSCLK_IN : in STD_LOGIC;
64 -- Data port
65  EventDataClk : in STD_LOGIC;
66  EventData_valid : in STD_LOGIC; -- used as data write enable
67  EventData_header : in STD_LOGIC; -- first data word
68  EventData_trailer : in STD_LOGIC; -- last data word
69  EventData : in STD_LOGIC_VECTOR (63 downto 0);
70  AlmostFull : out STD_LOGIC; -- buffer almost full
71  Ready : out STD_LOGIC);
72 end DAQ_LINK_Kintex;
73 
74 architecture Behavioral of DAQ_LINK_Kintex is
75 COMPONENT DAQ_Link_7S
76  Generic (
77  simulation : boolean := false);
78  PORT(
79  reset : IN std_logic;
80  USE_TRIGGER_PORT : boolean;
81  UsrClk : IN std_logic;
82  cplllock : IN std_logic;
83  RxResetDone : IN std_logic;
84  txfsmresetdone : IN std_logic;
85  RXNOTINTABLE : IN std_logic_vector(1 downto 0);
86  RXCHARISCOMMA : IN std_logic_vector(1 downto 0);
87  RXCHARISK : IN std_logic_vector(1 downto 0);
88  RXDATA : IN std_logic_vector(15 downto 0);
89  TTCclk : IN std_logic;
90  BcntRes : IN std_logic;
91  trig : IN std_logic_vector(7 downto 0);
92  TTSclk : IN std_logic;
93  TTS : IN std_logic_vector(3 downto 0);
94  EventDataClk : IN std_logic;
95  EventData_valid : IN std_logic;
96  EventData_header : IN std_logic;
97  EventData_trailer : IN std_logic;
98  EventData : IN std_logic_vector(63 downto 0);
99  TXCHARISK : OUT std_logic_vector(1 downto 0);
100  TXDATA : OUT std_logic_vector(15 downto 0);
101  AlmostFull : OUT std_logic;
102  Ready : OUT std_logic;
103  sysclk : in STD_LOGIC;
104  L1A_DATA_we : out STD_LOGIC; -- last data word
105  L1A_DATA : out STD_LOGIC_VECTOR (15 downto 0)
106  );
107 end COMPONENT;
108 COMPONENT DAQLINK_7S_init
109 generic
110 (
111  EXAMPLE_SIM_GTRESET_SPEEDUP : string := "TRUE"; -- simulation setting for GT SecureIP model
112  EXAMPLE_SIMULATION : integer := 0; -- Set to 1 for simulation
113  STABLE_CLOCK_PERIOD : integer := 16; --Period of the stable clock driving this state-machine, unit is [ns]
114  EXAMPLE_USE_CHIPSCOPE : integer := 0; -- Set to 1 to use Chipscope to drive resets
115  -- REFCLK frequency, select one among 100, 125, 200 and 250 If your REFCLK frequency is not in the list, please contact wusx@bu.edu
116  F_REFCLK : integer := 125
117 
118 );
119  PORT(
120  SYSCLK_IN : IN std_logic;
121  SOFT_RESET_IN : IN std_logic;
122  DONT_RESET_ON_DATA_ERROR_IN : IN std_logic;
123  GT0_DATA_VALID_IN : IN std_logic;
124  GT0_CPLLLOCKDETCLK_IN : IN std_logic;
125  GT0_CPLLRESET_IN : IN std_logic;
126  GT0_GTREFCLK0_IN : IN std_logic;
127  GT0_DRPADDR_IN : IN std_logic_vector(8 downto 0);
128  GT0_DRPCLK_IN : IN std_logic;
129  GT0_DRPDI_IN : IN std_logic_vector(15 downto 0);
130  GT0_DRPEN_IN : IN std_logic;
131  GT0_DRPWE_IN : IN std_logic;
132  GT0_LOOPBACK_IN : IN std_logic_vector(2 downto 0);
133  GT0_RXUSERRDY_IN : IN std_logic;
134  GT0_RXUSRCLK_IN : IN std_logic;
135  GT0_RXUSRCLK2_IN : IN std_logic;
136  GT0_RXPRBSSEL_IN : IN std_logic_vector(2 downto 0);
137  GT0_RXPRBSCNTRESET_IN : IN std_logic;
138  GT0_GTXRXP_IN : IN std_logic;
139  GT0_GTXRXN_IN : IN std_logic;
140  GT0_RXMCOMMAALIGNEN_IN : IN std_logic;
141  GT0_RXPCOMMAALIGNEN_IN : IN std_logic;
142  GT0_GTRXRESET_IN : IN std_logic;
143  GT0_RXPMARESET_IN : IN std_logic;
144  GT0_GTTXRESET_IN : IN std_logic;
145  GT0_TXUSERRDY_IN : IN std_logic;
146  GT0_TXUSRCLK_IN : IN std_logic;
147  GT0_TXUSRCLK2_IN : IN std_logic;
148  GT0_TXDIFFCTRL_IN : IN std_logic_vector(3 downto 0);
149  GT0_TXDATA_IN : IN std_logic_vector(15 downto 0);
150  GT0_TXCHARISK_IN : IN std_logic_vector(1 downto 0);
151  GT0_TXPRBSSEL_IN : IN std_logic_vector(2 downto 0);
152  GT0_GTREFCLK0_COMMON_IN : IN std_logic;
153  GT0_QPLLLOCKDETCLK_IN : IN std_logic;
154  GT0_QPLLRESET_IN : IN std_logic;
155  GT0_TX_FSM_RESET_DONE_OUT : OUT std_logic;
156  GT0_RX_FSM_RESET_DONE_OUT : OUT std_logic;
157  GT0_CPLLFBCLKLOST_OUT : OUT std_logic;
158  GT0_CPLLLOCK_OUT : OUT std_logic;
159  GT0_DRPDO_OUT : OUT std_logic_vector(15 downto 0);
160  GT0_DRPRDY_OUT : OUT std_logic;
161  GT0_EYESCANDATAERROR_OUT : OUT std_logic;
162  GT0_RXCDRLOCK_OUT : OUT std_logic;
163  GT0_RXCLKCORCNT_OUT : OUT std_logic_vector(1 downto 0);
164  GT0_RXDATA_OUT : OUT std_logic_vector(15 downto 0);
165  GT0_RXPRBSERR_OUT : OUT std_logic;
166  GT0_RXDISPERR_OUT : OUT std_logic_vector(1 downto 0);
167  GT0_RXNOTINTABLE_OUT : OUT std_logic_vector(1 downto 0);
168  GT0_RXCHARISCOMMA_OUT : OUT std_logic_vector(1 downto 0);
169  GT0_RXCHARISK_OUT : OUT std_logic_vector(1 downto 0);
170  GT0_RXRESETDONE_OUT : OUT std_logic;
171  GT0_GTXTXN_OUT : OUT std_logic;
172  GT0_GTXTXP_OUT : OUT std_logic;
173  GT0_TXOUTCLK_OUT : OUT std_logic;
174  GT0_TXOUTCLKFABRIC_OUT : OUT std_logic;
175  GT0_TXOUTCLKPCS_OUT : OUT std_logic;
176  GT0_TXRESETDONE_OUT : OUT std_logic;
177  GT0_QPLLLOCK_OUT : OUT std_logic
178  );
179 END COMPONENT;
180 function GTXRESET_SPEEDUP(is_sim : boolean) return string is
181  begin
182  if(is_sim)then
183  return "TRUE";
184  else
185  return "FALSE";
186  end if;
187  end function;
188 signal UsrClk : std_logic := '0';
189 signal cplllock : std_logic := '0';
190 signal TXOUTCLK : std_logic := '0';
191 signal RxResetDone : std_logic := '0';
192 signal txfsmresetdone : std_logic := '0';
193 signal LoopBack : std_logic_vector(2 downto 0) := (others => '0');
194 signal K_Cntr : std_logic_vector(7 downto 0) := (others => '0');
195 signal reset_SyncRegs : std_logic_vector(3 downto 0) := (others => '0');
196 signal RxResetDoneSyncRegs : std_logic_vector(2 downto 0) := (others => '0');
197 signal DATA_VALID : std_logic := '0';
198 signal RXNOTINTABLE : std_logic_vector(1 downto 0) := (others => '0');
199 signal RXCHARISCOMMA : std_logic_vector(1 downto 0) := (others => '0');
200 signal RXCHARISK : std_logic_vector(1 downto 0) := (others => '0');
201 signal RXDATA : std_logic_vector(15 downto 0) := (others => '0');
202 signal TXDIFFCTRL : std_logic_vector(3 downto 0) := x"b"; -- 790mV drive
203 signal TXCHARISK : std_logic_vector(1 downto 0) := (others => '0');
204 signal TXDATA : std_logic_vector(15 downto 0) := (others => '0');
205 begin
206 i_DAQ_Link_7S : DAQ_Link_7S
207  generic map(simulation => simulation)
208  PORT MAP (
209  reset => reset,
210  USE_TRIGGER_PORT => USE_TRIGGER_PORT,
211  UsrClk => UsrClk,
212  cplllock => cplllock,
213  RxResetDone => RxResetDone,
214  txfsmresetdone => txfsmresetdone,
215  RXNOTINTABLE => RXNOTINTABLE,
216  RXCHARISCOMMA => RXCHARISCOMMA,
217  RXCHARISK => RXCHARISK,
218  RXDATA => RXDATA,
219  TXCHARISK => TXCHARISK,
220  TXDATA => TXDATA,
221  TTCclk => TTCclk ,
222  BcntRes => BcntRes,
223  trig => trig,
224  TTSclk => TTSclk ,
225  TTS => TTS,
226  EventDataClk => EventDataClk,
227  EventData_valid => EventData_valid,
228  EventData_header => EventData_header,
229  EventData_trailer => EventData_trailer,
230  EventData => EventData,
231  AlmostFull => AlmostFull,
232  Ready => Ready,
233  sysclk => '0',
234  L1A_DATA => open,
235  L1A_DATA_we => open
236  );
237 process(UsrClk,RxResetDone)
238 begin
239  if(RxResetDone = '0')then
240  RxResetDoneSyncRegs <= (others => '0');
241  elsif(UsrClk'event and UsrClk = '1')then
242  RxResetDoneSyncRegs <= RxResetDoneSyncRegs(1 downto 0) & '1';
243  end if;
244 end process;
245 process(UsrClk,reset,RxResetDone,txfsmresetdone,cplllock)
246 begin
247  if(reset = '1' or RXRESETDONE = '0' or txfsmresetdone = '0' or cplllock = '0')then
248  reset_SyncRegs <= (others => '1');
249  elsif(UsrClk'event and UsrClk = '1')then
250  reset_SyncRegs <= reset_SyncRegs(2 downto 0) & '0';
251  end if;
252 end process;
253 process(UsrClk)
254 begin
255  if(UsrClk'event and UsrClk = '1')then
256  if(RXCHARISK = "11" and RXDATA = x"3cbc")then
257  DATA_VALID <= '1';
258  elsif(RxResetDoneSyncRegs(2) = '0' or or_reduce(RXNOTINTABLE) = '1' or K_Cntr(7) = '1')then
259  DATA_VALID <= '0';
260  end if;
261  if((RXCHARISK = "11" and RXDATA = x"3cbc"))then
262  K_Cntr <= (others => '0');
263  else
264  K_Cntr <= K_Cntr + 1;
265  end if;
266  end if;
267 end process;
268 i_DAQLINK_7S_init : DAQLINK_7S_init
269  generic map
270  (
271  EXAMPLE_SIM_GTRESET_SPEEDUP => GTXRESET_SPEEDUP(simulation),
272  EXAMPLE_SIMULATION => 0,
273  STABLE_CLOCK_PERIOD => sysclk_in_period,
274  EXAMPLE_USE_CHIPSCOPE => 0,
275  F_REFCLK => F_REFCLK
276  )
277  port map
278  (
279  SYSCLK_IN => SYSCLK_IN ,
280  SOFT_RESET_IN => '0',
281  DONT_RESET_ON_DATA_ERROR_IN => '0',
282  GT0_TX_FSM_RESET_DONE_OUT => txfsmresetdone,
283  GT0_RX_FSM_RESET_DONE_OUT => open,
284  GT0_DATA_VALID_IN => DATA_VALID,
285 
286 
287 
288 
289 
290  --_____________________________________________________________________
291  --_____________________________________________________________________
292  --GT0 (X1Y0)
293 
294  --------------------------------- CPLL Ports -------------------------------
295  GT0_CPLLFBCLKLOST_OUT => open,
296  GT0_CPLLLOCK_OUT => cplllock,
297  GT0_CPLLLOCKDETCLK_IN => sysclk_in,
298  GT0_CPLLRESET_IN => reset,
299  -------------------------- Channel - Clocking Ports ------------------------
300  GT0_GTREFCLK0_IN => GTX_REFCLK,
301  ---------------------------- Channel - DRP Ports --------------------------
302  GT0_DRPADDR_IN => (others => '0'),
303  GT0_DRPCLK_IN => sysclk_in ,
304  GT0_DRPDI_IN => (others => '0'),
305  GT0_DRPDO_OUT => open,
306  GT0_DRPEN_IN => '0',
307  GT0_DRPRDY_OUT => open,
308  GT0_DRPWE_IN => '0',
309  ------------------------------- Loopback Ports -----------------------------
310  GT0_LOOPBACK_IN => LOOPBACK,
311  --------------------- RX Initialization and Reset Ports --------------------
312  GT0_RXUSERRDY_IN => '0',
313  -------------------------- RX Margin Analysis Ports ------------------------
314  GT0_EYESCANDATAERROR_OUT => open,
315  ------------------------- Receive Ports - CDR Ports ------------------------
316  GT0_RXCDRLOCK_OUT => open,
317  ------------------ Receive Ports - FPGA RX Interface Ports -----------------
318  GT0_RXUSRCLK_IN => UsRClk,
319  GT0_RXUSRCLK2_IN => UsRClk,
320  ------------------ Receive Ports - FPGA RX interface Ports -----------------
321  GT0_RXDATA_OUT => RXDATA,
322  ------------------- Receive Ports - Pattern Checker Ports ------------------
323  GT0_RXPRBSERR_OUT => open,
324  GT0_RXPRBSSEL_IN => (others => '0'),
325  ------------------- Receive Ports - Pattern Checker ports ------------------
326  GT0_RXPRBSCNTRESET_IN => '0',
327  ------------------ Receive Ports - RX 8B/10B Decoder Ports -----------------
328  GT0_RXDISPERR_OUT => open,
329  GT0_RXNOTINTABLE_OUT => RXNOTINTABLE,
330  --------------------------- Receive Ports - RX AFE -------------------------
331  GT0_GTXRXP_IN => GTX_RXP,
332  ------------------------ Receive Ports - RX AFE Ports ----------------------
333  GT0_GTXRXN_IN => GTX_RXN,
334  -------------- Receive Ports - RX Byte and Word Alignment Ports ------------
335  GT0_RXMCOMMAALIGNEN_IN => reset_SyncRegs(3),
336  GT0_RXPCOMMAALIGNEN_IN => reset_SyncRegs(3),
337  ------------- Receive Ports - RX Initialization and Reset Ports ------------
338  GT0_GTRXRESET_IN => reset,
339  GT0_RXPMARESET_IN => '0',
340  ------------------- Receive Ports - RX8B/10B Decoder Ports -----------------
341  GT0_RXCHARISCOMMA_OUT => RXCHARISCOMMA,
342  GT0_RXCHARISK_OUT => RXCHARISK,
343  -------------- Receive Ports -RX Initialization and Reset Ports ------------
344  GT0_RXRESETDONE_OUT => RXRESETDONE,
345  --------------------- TX Initialization and Reset Ports --------------------
346  GT0_GTTXRESET_IN => reset,
347  GT0_TXUSERRDY_IN => '0',
348  ------------------ Transmit Ports - FPGA TX Interface Ports ----------------
349  GT0_TXUSRCLK_IN => UsRClk,
350  GT0_TXUSRCLK2_IN => UsRClk,
351  --------------- Transmit Ports - TX Configurable Driver Ports --------------
352  GT0_TXDIFFCTRL_IN => TXDIFFCTRL,
353  ------------------ Transmit Ports - TX Data Path interface -----------------
354  GT0_TXDATA_IN => TXDATA,
355  ---------------- Transmit Ports - TX Driver and OOB signaling --------------
356  GT0_GTXTXN_OUT => GTX_TXN,
357  GT0_GTXTXP_OUT => GTX_TXP,
358  ----------- Transmit Ports - TX Fabric Clock Output Control Ports ----------
359  GT0_TXOUTCLK_OUT => TXOUTCLK,
360  GT0_TXOUTCLKFABRIC_OUT => open,
361  GT0_TXOUTCLKPCS_OUT => open,
362  --------------------- Transmit Ports - TX Gearbox Ports --------------------
363  GT0_TXCHARISK_IN => TXCHARISK,
364  ------------- Transmit Ports - TX Initialization and Reset Ports -----------
365  GT0_TXRESETDONE_OUT => open,
366  ------------------ Transmit Ports - pattern Generator Ports ----------------
367  GT0_TXPRBSSEL_IN => "000",
368 
369 
370 
371 
372  --____________________________COMMON PORTS________________________________
373  ---------------------- Common Block - Ref Clock Ports ---------------------
374  GT0_GTREFCLK0_COMMON_IN => '0',
375  ------------------------- Common Block - QPLL Ports ------------------------
376  GT0_QPLLLOCK_OUT => open,
377  GT0_QPLLLOCKDETCLK_IN => '0',
378  GT0_QPLLRESET_IN => '0'
379 
380  );
381 i_UsrClk : BUFG
382  port map (
383  O => UsrClk, -- Clock buffer output
384  I => TXOUTCLK -- Clock buffer input
385  );
386 end Behavioral;
387