AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
DAQLSCXG_if.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 14:07:47 10/07/2013
6 -- Design Name:
7 -- Module Name: TCPIP_if - 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 use IEEE.numeric_std.all;
26 use work.amc13_pack.all;
27 
28 -- Uncomment the following library declaration if using
29 -- arithmetic functions with Signed or Unsigned values
30 --use IEEE.NUMERIC_STD.ALL;
31 
32 -- Uncomment the following library declaration if instantiating
33 -- any Xilinx primitives in this code.
34 library UNISIM;
35 use UNISIM.VComponents.all;
36 Library UNIMACRO;
37 use UNIMACRO.vcomponents.all;
38 
39 entity DAQLSCXG_if is
40  generic(N_SFP : integer := 1);
41  Port ( sysclk : in STD_LOGIC;
42  clk125 : in STD_LOGIC;
43  DRPclk : in STD_LOGIC;
44  reset : in STD_LOGIC;
45  daq_reset : in STD_LOGIC;
46  gtx_reset : in STD_LOGIC;
47  rstCntr : in STD_LOGIC;
48  Dis_pd : in STD_LOGIC;
49  test : in STD_LOGIC;
50  DB_cmd : IN std_logic;
51  enSFP : IN std_logic_vector(3 downto 0);
52  SFP_ABS : IN std_logic_vector(2 downto 0);
53  LSC_ID : IN std_logic_vector(15 downto 0);
54  SFP_down : OUT std_logic_vector(2 downto 0);
55  inc_ddr_pa : in STD_LOGIC;
56 -- event data in
57  evt_data_rdy : in std_logic_vector(2 downto 0);
58  EventData_in : in array3X67;
59  EventData_we : in std_logic_VECTOR(2 downto 0);
60  EventData_re : out std_logic_VECTOR(2 downto 0); --
61  evt_buf_full : out std_logic_vector(2 downto 0);
62  buf_rqst : in std_logic_vector(3 downto 0);
63  WaitMonBuf : IN std_logic;
64  MonBufOverWrite : in STD_LOGIC;
65  TCPBuf_avl : out STD_LOGIC;
66  MonBuf_avl : out STD_LOGIC;
67  MonBuf_empty : out STD_LOGIC;
68  MonBufOvfl : out STD_LOGIC;
69  mon_evt_cnt : out std_logic_vector(31 downto 0);
70  WrtMonBlkDone : in STD_LOGIC_VECTOR(2 downto 0);
71  WrtMonEvtDone : in STD_LOGIC_VECTOR(2 downto 0);
72 -- ddr wportA status
73  wport_rdy : in std_logic_vector(2 downto 0);
74  wport_FIFO_full : in std_logic_vector(2 downto 0);
75 -- signal to ddr_if, AMC_if to start moving data
76  EventBufAddr_we : out std_logic_VECTOR(2 downto 0);
77  EventBufAddr : out array3X14;
78 -- SFP ports
79  SFP0_RXN : in STD_LOGIC;
80  SFP0_RXP : in STD_LOGIC;
81  SFP1_RXN : in STD_LOGIC;
82  SFP1_RXP : in STD_LOGIC;
83  SFP2_RXN : in STD_LOGIC;
84  SFP2_RXP : in STD_LOGIC;
85  SFP0_TXN : out STD_LOGIC;
86  SFP0_TXP : out STD_LOGIC;
87  SFP1_TXN : out STD_LOGIC;
88  SFP1_TXP : out STD_LOGIC;
89  SFP2_TXN : out STD_LOGIC;
90  SFP2_TXP : out STD_LOGIC;
91  SFP_REFCLK_P : in STD_LOGIC;
92  SFP_REFCLK_N : in STD_LOGIC;
93  GbE_REFCLK : in STD_LOGIC;
94 -- ipbus signals
95  ipb_clk : in STD_LOGIC;
96  ipb_write : in STD_LOGIC;
97  ipb_strobe : in STD_LOGIC;
98  ipb_addr : in STD_LOGIC_VECTOR(31 downto 0);
99  ipb_wdata : in STD_LOGIC_VECTOR(31 downto 0);
100  ipb_rdata : out STD_LOGIC_VECTOR(31 downto 0);
101  ipb_ack : out STD_LOGIC
102  );
103 end DAQLSCXG_if;
104 
105 architecture Behavioral of DAQLSCXG_if is
106 COMPONENT DaqLSCXG10G
107  generic(N_SFP : integer := 1);
108  Port ( sys_reset : in STD_LOGIC; -- active high reset of all logic but GTX
109  sys_clk : in STD_LOGIC;
110  sfp_pd : in array3x2;
111  DRP_clk : in STD_LOGIC;
112  LinkWe : in STD_LOGIC_VECTOR (2 downto 0);
113  LinkCtrl : in STD_LOGIC_VECTOR (2 downto 0);
114  LinkData : in array3x64;
115  srcID : in array3x16;
116  LinkDown : out STD_LOGIC_VECTOR (2 downto 0);
117  LinkFull : out STD_LOGIC_VECTOR (2 downto 0);
118  sync_loss : out STD_LOGIC_VECTOR (2 downto 0); -- goes to '1' (rxusrclk) when SERDES is out of synch
119  status_ce : in std_logic_VECTOR (2 downto 0); -- not implemented yet
120  status_addr : in STD_LOGIC_VECTOR (15 downto 0); -- not implemented yet
121  status_port : out array3x64; -- first 32 bits are hard-wired
122  --
123  txusrclk_o : out STD_LOGIC; -- reconstructed tx clock, to be used to clock sending circuitry
124  rxusrclk_o : out STD_LOGIC; -- reconstructed rx clock, to be used to clock receiving circuitry
125  --
126  gtx_reset : in std_logic; -- full reset of GTX only
127  gtx_refclk_p : in std_logic; -- iob for refclk neg
128  gtx_refclk_n : in std_logic; -- iob for refclk neg
129  sfp_rxn : in std_logic_VECTOR (2 downto 0); -- sfp iobs
130  sfp_rxp : in std_logic_VECTOR (2 downto 0);
131  sfp_txn : out std_logic_VECTOR (2 downto 0);
132  sfp_txp : out std_logic_VECTOR (2 downto 0)
133  );
134 END COMPONENT;
135 COMPONENT DaqLSCXG
136  generic(N_SFP : integer := 1);
137  Port ( sys_reset : in STD_LOGIC; -- active high reset of all logic but GTX
138  sys_clk : in STD_LOGIC;
139  sfp_pd : in array3x2;
140  DRP_clk : in STD_LOGIC;
141  LinkWe : in STD_LOGIC_VECTOR (2 downto 0);
142  LinkCtrl : in STD_LOGIC_VECTOR (2 downto 0);
143  LinkData : in array3x64;
144  srcID : in array3x16;
145  LinkDown : out STD_LOGIC_VECTOR (2 downto 0);
146  LinkFull : out STD_LOGIC_VECTOR (2 downto 0);
147  sync_loss : out STD_LOGIC_VECTOR (2 downto 0); -- goes to '1' (rxusrclk) when SERDES is out of synch
148  status_ce : in std_logic_VECTOR (2 downto 0); -- not implemented yet
149  status_addr : in STD_LOGIC_VECTOR (15 downto 0); -- not implemented yet
150  status_port : out array3x64; -- first 32 bits are hard-wired
151  --
152  txusrclk_o : out STD_LOGIC; -- reconstructed tx clock, to be used to clock sending circuitry
153  rxusrclk_o : out STD_LOGIC; -- reconstructed rx clock, to be used to clock receiving circuitry
154  --
155  gtx_reset : in std_logic; -- full reset of GTX only
156  gtx_refclk : in std_logic; -- iob for refclk neg
157  sfp_rxn : in std_logic_VECTOR (2 downto 0); -- sfp iobs
158  sfp_rxp : in std_logic_VECTOR (2 downto 0);
159  sfp_txn : out std_logic_VECTOR (2 downto 0);
160  sfp_txp : out std_logic_VECTOR (2 downto 0)
161  );
162 END COMPONENT;
163 COMPONENT cmsCRC64
164  PORT(
165  clk : IN std_logic;
166  reset : IN std_logic;
167  crc_init : IN std_logic;
168  trailer : IN std_logic;
169  crc_d : IN std_logic_vector(63 downto 0);
170  crc_ce : IN std_logic;
171  crc : OUT std_logic_vector(15 downto 0);
172  crc_err : OUT std_logic;
173  dout : OUT std_logic_vector(63 downto 0);
174  dout_vld : OUT std_logic
175  );
176 END COMPONENT;
177 COMPONENT check_event
178  PORT(
179  clk : IN std_logic;
180  reset : IN std_logic;
181  en_stop : IN std_logic_vector(4 downto 0);
182  cmsCRC_err : IN std_logic_vector(2 downto 0);
183  EventData_in : IN array3X67;
184  EventData_we : IN std_logic_vector(2 downto 0);
185  inc_err : OUT array3X5;
186  stop : OUT std_logic
187  );
188 END COMPONENT;
189 COMPONENT SFP_cntr
190  PORT(
191  sysclk : IN std_logic;
192  clk125 : IN std_logic;
193  ipb_clk : IN std_logic;
194  resetCntr : IN std_logic;
195  DB_cmd : IN std_logic;
196  Cntr_DATA : IN std_logic_vector(31 downto 0);
197  ipb_addr : IN std_logic_vector(15 downto 0);
198  Cntr_ADDR : OUT std_logic_vector(6 downto 0);
199  ipb_rdata : OUT std_logic_vector(31 downto 0)
200  );
201 END COMPONENT;
202 function A_GT_B (A, B : std_logic_vector(10 downto 0)) return boolean is
203 variable tmp : std_logic_vector(10 downto 0);
204 begin
205  tmp := A - B;
206  if(tmp(10) = '0' and or_reduce(tmp(9 downto 0)) = '1')then
207  return true;
208  else
209  return false;
210  end if;
211 end A_GT_B;
212 function A_GE_B (A, B : std_logic_vector(10 downto 0)) return boolean is
213 variable tmp : std_logic_vector(10 downto 0);
214 begin
215  tmp := A - B;
216  if(tmp(10) = '0')then
217  return true;
218  else
219  return false;
220  end if;
221 end A_GE_B;
222 signal resetSyncRegs : std_logic_vector(2 downto 0) := (others => '0');
223 signal daq_resetSyncRegs : std_logic_vector(2 downto 0) := (others => '0');
224 signal inc_ddr_paSyncRegs : std_logic_vector(3 downto 0) := (others => '0');
225 signal bldr2SFP_sel : array3X2 := (others => (others => '0'));
226 signal SFP2bldr_sel : array3X2 := (others => (others => '0'));
227 signal EventBufAddr_we_i : std_logic_vector(2 downto 0) := (others => '0');
228 signal ReadBusy : std_logic_vector(2 downto 0) := (others => '0');
229 signal sysDIV2 : std_logic := '0';
230 --signal MonBuf_avl_i : std_logic := '0';
231 signal MonBuf_wa : std_logic_vector(10 downto 0) := (others => '0');
232 signal MonBuf_ra : std_logic_vector(10 downto 0) := (others => '0');
233 signal MonBufUsed : std_logic_vector(9 downto 0) := (others => '0');
234 signal NXT_MonBuf : array3X11 := (others => (others => '0'));
235 signal Written_MonBuf : array4X11 := (others => (others => '0'));
236 signal Written_MonBufMatch : std_logic_vector(2 downto 0) := (others => '0');
237 signal AddrOffset : array3X10 := (others => (others => '0'));
238 signal header : std_logic_vector(2 downto 0) := (others => '0');
239 signal header_q : std_logic_vector(2 downto 0) := (others => '0');
240 signal sfp_rxn : std_logic_vector(2 downto 0) := (others => '0');
241 signal sfp_rxp : std_logic_vector(2 downto 0) := (others => '0');
242 signal sfp_txn : std_logic_vector(2 downto 0) := (others => '0');
243 signal sfp_txp : std_logic_vector(2 downto 0) := (others => '0');
244 signal sync_loss : std_logic_vector(2 downto 0) := (others => '0');
245 signal LinkFull_n : std_logic_vector(2 downto 0) := (others => '0');
246 signal LinkFull : std_logic_vector(2 downto 0) := (others => '0');
247 signal LinkCtrl : std_logic_vector(2 downto 0) := (others => '0');
248 signal LinkWe : std_logic_vector(2 downto 0) := (others => '0');
249 signal LinkDown : std_logic_vector(2 downto 0) := (others => '0');
250 signal DaqLSC_status : array3X64 := (others => (others => '0'));
251 signal LinkData : array3X65 := (others => (others => '0'));
252 signal sync_lossSync : array3X3 := (others => (others => '0'));
253 signal sync_loss_cntr : array3X32 := (others => (others => '0'));
254 signal SFP_we : std_logic_vector(2 downto 0) := (others => '0');
255 signal EoB : std_logic_vector(2 downto 0) := (others => '0');
256 signal SFP_evt_cntr : array3X32 := (others => (others => '0'));
257 signal SFP_blk_cntr : array3X32 := (others => (others => '0'));
258 signal SFP_word_cntr : array3X32 := (others => (others => '0'));
259 signal event_cntr : array3X32 := (others => (others => '0'));
260 signal word_cntr : array3X32 := (others => (others => '0'));
261 signal EventBufAddr_we_cntr : array3X32 := (others => (others => '0'));
262 signal src_ID : array3X16 := (others => (others => '0'));
263 signal txusrclk : std_logic := '0';
264 signal LinkDatap : array3X64 := (others => (others => '0'));
265 signal sfp_pd : array3X2 := (others => (others => '0'));
266 signal WrtMonEvtDoneCntr : array3X8 := (others => (others => '0'));
267 signal chk_MonBuf_avl : std_logic := '0';
268 signal FirstBlkAddrDo : array2x3x12 := (others => (others => (others => '0')));
269 signal FirstBlkAddr_ra : array2x3x5 := (others => (others => (others => '0')));
270 signal FirstBlkAddr_re : array2X3 := (others => (others => '0'));
271 signal WrtMonEvtDone_l : std_logic_vector(2 downto 0) := (others => '0');
272 signal MonEvtQueued : std_logic_vector(2 downto 0) := (others => '0');
273 signal FirstBlkAddrDoValid : array2X3 := (others => (others => '0'));
274 signal FirstBlkAddr_wa : std_logic_vector(4 downto 0) := (others => '0');
275 signal FirstBlkAddrDi : std_logic_vector(11 downto 0) := (others => '0');
276 signal FirstBlkAddr_we : std_logic := '0';
277 signal MonBuf_full : std_logic := '0';
278 signal mon_evt_cnt_i : std_logic_vector(10 downto 0) := (others => '0');
279 signal status_addr : std_logic_vector(15 downto 0) := (others => '0');
280 signal cmsCRC_initp : std_logic_vector(2 downto 0) := (others => '0');
281 signal cmsCRC_init : std_logic_vector(2 downto 0) := (others => '0');
282 signal cmsCRC_err : std_logic_vector(2 downto 0) := (others => '0');
283 signal cmsCRC_errCntr : array3X32 := (others => (others => '0'));
284 signal EvtLength_errCntr : array3X32 := (others => (others => '0'));
285 signal AMClength_errCntr : array3X32 := (others => (others => '0'));
286 signal AMCvalid_errCntr : array3X32 := (others => (others => '0'));
287 signal AMCcrc_errCntr : array3X32 := (others => (others => '0'));
288 signal BackPressureCntr : array3X32 := (others => (others => '0'));
289 signal TotalEvtLengthCntr : array3X32 := (others => (others => '0'));
290 signal BackPressure31 : std_logic_vector(2 downto 0) := (others => '1');
291 signal BackPressure31_q : std_logic_vector(2 downto 0) := (others => '1');
292 signal IsBackPressure : std_logic := '0';
293 signal StopOverWrite : std_logic := '0';
294 signal en_stop : std_logic_vector(4 downto 0) := (others => '1');
295 signal stop : std_logic := '0';
296 signal Cntr2ms : std_logic_vector(18 downto 0) := (others => '1');
297 signal LiveTimeCntr : array3x19 := (others => (others => '0'));
298 signal LiveTime : array3x8 := (others => (others => '0'));
299 signal inc_err : array3x5 := (others => (others => '0'));
300 signal Cntr_DATA : std_logic_vector(31 downto 0) := (others => '0');
301 signal Cntr_ADDR : std_logic_vector(6 downto 0) := (others => '0');
302 component chipscope1 is
303  generic (N : integer := 5);
304  Port ( clk : in STD_LOGIC;
305  Din : in STD_LOGIC_VECTOR (303 downto 0));
306 end component;
307 signal cs : std_logic_vector(303 downto 0) := (others => '0');
308 begin
309 --i_chipscope: chipscope1
310 -- Port map( clk => sysclk, Din => cs);
311 TCPBuf_avl <= '1';
312 MonBufOvfl <= '0';
313 EventBufAddr_we <= EventBufAddr_we_i;
314 mon_evt_cnt(31 downto 11) <= (others => '0');
315 mon_evt_cnt(10 downto 0) <= mon_evt_cnt_i;
316 ipb_ack <= '0';
317 sfp_pd(0) <= "00" when Dis_pd = '1' or SFP_ABS(0) = '0' else "11";
318 sfp_pd(1) <= "00" when Dis_pd = '1' or SFP_ABS(1) = '0' else "11";
319 sfp_pd(2) <= "00" when Dis_pd = '1' or SFP_ABS(2) = '0' else "11";
320 SFP_down(2) <= not LinkDown(2) and not enSFP(3) and enSFP(2);
321 SFP_down(1) <= not LinkDown(1) and not enSFP(3) and enSFP(1);
322 SFP_down(0) <= not LinkDown(0) and not enSFP(3) and enSFP(0);
323 LinkFull(2) <= not LinkFull_n(2) and not enSFP(3) and enSFP(2);
324 LinkFull(1) <= not LinkFull_n(1) and not enSFP(3) and enSFP(1);
325 LinkFull(0) <= not LinkFull_n(0) and not enSFP(3) and enSFP(0);
326 g_10g : if (lsc_speed = 10) generate
327  i_DaqLSCXG: DaqLSCXG10G PORT MAP(
328  sys_reset => daq_resetSyncRegs(2),
329  sys_clk => sysclk,
330  sfp_pd => sfp_pd,
331  DRP_clk => DRPclk,
332  LinkWe => LinkWe,
333  LinkCtrl => LinkCtrl,
334  LinkData => LinkDatap,
335  srcID => src_ID,
336  LinkDown => LinkDown,
337  LinkFull => LinkFull_n,
338  sync_loss => sync_loss,
339  status_ce => "000",
340  status_addr => status_addr,
341  status_port => DaqLSC_status,
342  txusrclk_o => txusrclk,
343  rxusrclk_o => open,
344  gtx_reset => gtx_reset,
345  gtx_refclk_p => SFP_REFCLK_P,
346  gtx_refclk_n => SFP_REFCLK_N,
347  sfp_rxn => sfp_rxn,
348  sfp_rxp => sfp_rxp,
349  sfp_txn => sfp_txn,
350  sfp_txp => sfp_txp
351  );
352 end generate g_10g;
353 g_5g : if (lsc_speed = 5) generate
354  i_DaqLSCXG: DaqLSCXG PORT MAP(
355  sys_reset => daq_resetSyncRegs(2),
356  sys_clk => sysclk,
357  sfp_pd => sfp_pd,
358  DRP_clk => DRPclk,
359  LinkWe => LinkWe,
360  LinkCtrl => LinkCtrl,
361  LinkData => LinkDatap,
362  srcID => src_ID,
363  LinkDown => LinkDown,
364  LinkFull => LinkFull_n,
365  sync_loss => sync_loss,
366  status_ce => "000",
367  status_addr => status_addr,
368  status_port => DaqLSC_status,
369  txusrclk_o => txusrclk,
370  rxusrclk_o => open,
371  gtx_reset => gtx_reset,
372  gtx_refclk => GbE_REFCLK,
373  sfp_rxn => sfp_rxn,
374  sfp_rxp => sfp_rxp,
375  sfp_txn => sfp_txn,
376  sfp_txp => sfp_txp
377  );
378 end generate g_5g;
379 status_addr <= x"000" & Cntr_ADDR(3 downto 0);
380 LinkDatap(0) <= LinkData(0)(63 downto 0);
381 LinkDatap(1) <= LinkData(1)(63 downto 0);
382 LinkDatap(2) <= LinkData(2)(63 downto 0);
383 src_ID(0) <= LSC_ID(15 downto 2) & "00";
384 src_ID(1) <= LSC_ID(15 downto 2) & "01";
385 src_ID(2) <= LSC_ID(15 downto 2) & "10";
386 sfp_rxn(0) <= SFP0_RXN;
387 sfp_rxp(0) <= SFP0_RXP;
388 SFP0_TXN <= sfp_txn(0);
389 SFP0_TXP <= sfp_txp(0);
390 sfp_rxn(1) <= SFP1_RXN;
391 sfp_rxp(1) <= SFP1_RXP;
392 SFP1_TXN <= sfp_txn(1);
393 SFP1_TXP <= sfp_txp(1);
394 sfp_rxn(2) <= SFP2_RXN;
395 sfp_rxp(2) <= SFP2_RXP;
396 SFP2_TXN <= sfp_txn(2);
397 SFP2_TXP <= sfp_txp(2);
398 process(sysclk,daq_reset)
399 begin
400  if(daq_reset = '1')then
401  daq_resetSyncRegs <= (others => '1');
402  elsif(sysclk'event and sysclk = '1')then
403  daq_resetSyncRegs <= daq_resetSyncRegs(1 downto 0) & '0';
404  end if;
405 end process;
406 process(sysclk,reset)
407 begin
408  if(reset = '1')then
409  resetSyncRegs <= (others => '1');
410  elsif(sysclk'event and sysclk = '1')then
411  resetSyncRegs <= resetSyncRegs(1 downto 0) & '0';
412  end if;
413 end process;
414 g_FirstBlkAddr: for j in 0 to 1 generate
415  g1_FirstBlkAddr: for i in 0 to 5 generate
416  i_FirstBlkAddr : RAM32M
417  port map (
418  DOA => FirstBlkAddrDo (j)(0)(i*2+1 downto i*2), -- Read port A 2-bit output
419  DOB => FirstBlkAddrDo (j)(1)(i*2+1 downto i*2), -- Read port B 2-bit output
420  DOC => FirstBlkAddrDo (j)(2)(i*2+1 downto i*2), -- Read port C 2-bit output
421  DOD => open, -- Read/Write port D 2-bit output
422  ADDRA => FirstBlkAddr_ra(j)(0), -- Read port A 5-bit address input
423  ADDRB => FirstBlkAddr_ra(j)(1), -- Read port B 5-bit address input
424  ADDRC => FirstBlkAddr_ra(j)(2), -- Read port C 5-bit address input
425  ADDRD => FirstBlkAddr_wa, -- Read/Write port D 5-bit address input
426  DIA => FirstBlkAddrDi (i*2+1 downto i*2), -- RAM 2-bit data write input addressed by ADDRD,
427  -- read addressed by ADDRA
428  DIB => FirstBlkAddrDi (i*2+1 downto i*2), -- RAM 2-bit data write input addressed by ADDRD,
429  -- read addressed by ADDRB
430  DIC => FirstBlkAddrDi (i*2+1 downto i*2), -- RAM 2-bit data write input addressed by ADDRD,
431  -- read addressed by ADDRC
432  DID => "00", -- RAM 2-bit data write input addressed by ADDRD,
433  -- read addressed by ADDRD
434  WCLK => sysclk, -- Write clock input
435  WE => FirstBlkAddr_we -- Write enable input
436  );
437  end generate;
438 end generate;
439 FirstBlkAddrDi <= '0' & MonBuf_wa;
440 process(sysclk)
441 begin
442  if(sysclk'event and sysclk = '1')then
443  if(resetSyncRegs(2) = '1')then
444  chk_MonBuf_avl <= '1';
445  elsif(buf_rqst(0) = '1')then
446  chk_MonBuf_avl <= buf_rqst(3);
447  end if;
448  if(resetSyncRegs(2) = '1')then
449  MonBuf_avl <= '1';
450  elsif(MonBufOverWrite = '1')then
451  MonBuf_avl <= not StopOverWrite;
452 -- elsif(WaitMonBuf = '1' or MonBufOverWrite = '1')then
453  elsif(WaitMonBuf = '1')then
454  if((MonBuf_wa(10) /= MonBuf_ra(10) and MonBuf_wa(9 downto 0) = MonBuf_ra(9 downto 0)))then
455  MonBuf_avl <= '0';
456  else
457  MonBuf_avl <= '1';
458  end if;
459  elsif(chk_MonBuf_avl = '1')then
460  if(MonBufUsed(9 downto 8) = "11")then
461  MonBuf_avl <= '0';
462  else
463  MonBuf_avl <= '1';
464  end if;
465  end if;
466  if(MonBufOverWrite = '1')then
467  mon_evt_cnt_i <= MonBuf_full & Written_MonBuf(3)(9 downto 0);
468  else
469  mon_evt_cnt_i <= Written_MonBuf(3) - MonBuf_ra;
470  end if;
471  if(MonBufOverWrite = '0')then
472  MonBuf_empty <= not or_reduce(mon_evt_cnt_i);
473  elsif(Written_MonBuf(3) /= MonBuf_ra or MonBuf_full = '1')then
474  MonBuf_empty <= '0';
475  else
476  MonBuf_empty <= '1';
477  end if;
478  if(resetSyncRegs(2) = '1')then
479  ReadBusy <= (others => '0');
480  EventData_re <= (others => '0');
481  EventBufAddr_we_i <= (others => '0');
482  MonBuf_wa <= (others => '0');
483  MonBuf_ra <= (others => '0');
484  MonBufUsed <= (others => '0');
485  Written_MonBufMatch <= (others => '1');
486  Written_MonBuf <= (others => (others => '0'));
487  NXT_MonBuf <= (others => (others => '0'));
488  inc_ddr_paSyncRegs <= (others => '0');
489  FirstBlkAddr_we <= '0';
490  FirstBlkAddr_re <= (others => (others => '0'));
491  FirstBlkAddrDoValid <= (others => (others => '0'));
492  WrtMonEvtDone_l <= (others => '0');
493  WrtMonEvtDoneCntr <= (others => (others => '0'));
494  MonEvtQueued <= (others => '0');
495  FirstBlkAddr_wa <= (others => '0');
496  FirstBlkAddr_ra <= (others => (others => (others => '0')));
497  MonBuf_full <= '0';
498  else
499  for i in 0 to 2 loop
500  if(EVENTdata_in(i)(64) = '1' and EVENTdata_we(i) = '1')then
501  ReadBusy(i) <= '0';
502  elsif(evt_data_rdy(i) = '1' and wport_rdy(i) = '1')then
503  ReadBusy(i) <= '1';
504  end if;
505  EventData_re(i) <= evt_data_rdy(i) and wport_rdy(i) and not ReadBusy(i);
506  if(EventData_in(i)(66) = '0' and evt_data_rdy(i) = '1' and wport_rdy(i) = '1' and ReadBusy(i) = '0')then
507  EventBufAddr_we_i(i) <= '1';
508  else
509  EventBufAddr_we_i(i) <= '0';
510  end if;
511  end loop;
512  if(MonBufOverWrite = '1' and Written_MonBuf(3)(10) = '1')then
513  MonBuf_full <= '1';
514  end if;
515  for j in 0 to 1 loop
516  for i in 0 to 2 loop
517  if(FirstBlkAddr_re(j)(i) = '1')then
518  FirstBlkAddr_ra(j)(i) <= FirstBlkAddr_ra(j)(i) + 1;
519  end if;
520  if(FirstBlkAddr_ra(j)(i) = FirstBlkAddr_wa)then
521  FirstBlkAddrDoValid(j)(i) <= '0';
522  else
523  FirstBlkAddrDoValid(j)(i) <= '1';
524  end if;
525  end loop;
526  end loop;
527  if(FirstBlkAddr_we = '1')then
528  FirstBlkAddr_wa <= FirstBlkAddr_wa + 1;
529  end if;
530  for i in 0 to 2 loop
531  if(WrtMonEvtDone(i) = '1')then
532  WrtMonEvtDoneCntr(i) <= WrtMonEvtDoneCntr(i) + 1;
533  end if;
534  if(WrtMonEvtDone(i) = '1')then
535  WrtMonEvtDone_l(i) <= '1';
536  elsif(FirstBlkAddrDoValid(0)(i) = '1')then
537  WrtMonEvtDone_l(i) <= '0';
538  end if;
539  FirstBlkAddr_re(0)(i) <= FirstBlkAddrDoValid(0)(i) and WrtMonEvtDone_l(i);
540  if(EventData_we(i) = '1' and EventData_in(i)(66 downto 65) = "01")then
541  MonEvtQueued(i) <= '1';
542  elsif(FirstBlkAddrDoValid(1)(i) = '1')then
543  MonEvtQueued(i) <= '0';
544  end if;
545  FirstBlkAddr_re(1)(i) <= FirstBlkAddrDoValid(1)(i) and MonEvtQueued(i);
546  end loop;
547 -- FirstBlkAddr_we <= buf_rqst(3) and buf_rqst(0) and MonBuf_avl_i;
548  FirstBlkAddr_we <= buf_rqst(3) and buf_rqst(0);
549 -- if(buf_rqst(0) = '1' and MonBuf_avl_i = '1')then
550  if(buf_rqst(0) = '1')then
551  MonBuf_wa <= MonBuf_wa + 1;
552  end if;
553  MonBufUsed <= MonBuf_wa(9 downto 0) - MonBuf_ra(9 downto 0);
554  if(inc_ddr_paSyncRegs(3 downto 2) = "10" or (MonBufOverWrite = '1' and StopOverWrite = '0' and and_reduce(MonBufUsed) = '1' and buf_rqst(0) = '1'))then
555  MonBuf_ra <= MonBuf_ra + 1;
556  end if;
557  if(Written_MonBuf(0) = Written_MonBuf(3) and WrtMonEvtDone_l(0) = '0')then
558  Written_MonBufMatch(0) <= '1';
559  else
560  Written_MonBufMatch(0) <= '0';
561  end if;
562  if((EnSFP(2 downto 0) = "111" or EnSFP(2 downto 0) = "011" or EnSFP(2 downto 0) = "110" or EnSFP(2 downto 0) = "101") and Written_MonBuf(1) = Written_MonBuf(3) and WrtMonEvtDone_l(1) = '0')then
563  Written_MonBufMatch(1) <= '1';
564  else
565  Written_MonBufMatch(1) <= '0';
566  end if;
567  if(EnSFP(2 downto 0) = "111" and Written_MonBuf(2) = Written_MonBuf(3) and WrtMonEvtDone_l(2) = '0')then
568  Written_MonBufMatch(2) <= '1';
569  else
570  Written_MonBufMatch(2) <= '0';
571  end if;
572  if(Written_MonBufMatch = "000" and sysDIV2 = '0')then
573  Written_MonBuf(3) <= Written_MonBuf(3) + 1;
574  end if;
575  for i in 0 to 2 loop
576  if(FirstBlkAddr_re(0)(i) = '1')then
577  Written_MonBuf(i) <= FirstBlkAddrDo(0)(i)(10 downto 0);
578  elsif(WrtMonBlkDone(i) = '1')then
579  Written_MonBuf(i) <= Written_MonBuf(i) + 1;
580  end if;
581  if(FirstBlkAddr_re(1)(i) = '1')then
582  NXT_MonBuf(i) <= FirstBlkAddrDo(1)(i)(10 downto 0);
583  elsif(EventBufAddr_we_i(i) = '1' and EventData_in(i)(66) = '0')then
584  NXT_MonBuf(i) <= NXT_MonBuf(i) + 1;
585  end if;
586  end loop;
587  inc_ddr_paSyncRegs <= inc_ddr_paSyncRegs(2 downto 0) & inc_ddr_pa;
588  end if;
589  case EnSFP(2 downto 0) is
590  when "011" | "101" | "110" => AddrOffset(0)(9 downto 6) <= x"8";
591  when "111" => AddrOffset(0)(9 downto 6) <= x"5";
592  when others => AddrOffset(0)(9 downto 6) <= x"0";
593  end case;
594  AddrOffset(1)(9 downto 6) <= x"0";
595  AddrOffset(2)(9 downto 6) <= x"a";
596  for i in 0 to 2 loop
597  EventBufAddr(i) <= NXT_MonBuf(i)(9 downto 0) & AddrOffset(i)(9 downto 6);
598  end loop;
599  end if;
600 end process;
601 process(sysclk)
602 begin
603  if(sysclk'event and sysclk = '1')then
604  sysDIV2 <= not sysDIV2;
605  for i in 0 to 2 loop
606  if(resetSyncRegs(2) = '1')then
607  header(i) <= '1';
608  header_q(i) <= '0';
609  elsif(EventData_we(i) = '1')then
610  header(i) <= EventData_in(i)(65) or (header(i) and not header_q(i));
611  header_q(i) <= header(i);
612  end if;
613  end loop;
614  if(EnSFP(2 downto 1) = "00")then
615  SFP_we(0) <= EventData_we(0);
616  EoB(0) <= EventData_in(0)(64);
617  else
618  SFP_we(0) <= EventData_we(1) and EnSFP(0);
619  EoB(0) <= EventData_in(1)(64);
620  end if;
621  if(EnSFP(2 downto 0) = "110")then
622  SFP_we(1) <= EventData_we(1);
623  EoB(1) <= EventData_in(1)(64);
624  else
625  SFP_we(1) <= EventData_we(0) and EnSFP(1);
626  EoB(1) <= EventData_in(0)(64);
627  end if;
628  if(EnSFP(2 downto 0) = "111")then
629  SFP_we(2) <= EventData_we(2);
630  EoB(2) <= EventData_in(2)(64);
631  else
632  SFP_we(2) <= EventData_we(0) and EnSFP(2);
633  EoB(2) <= EventData_in(0)(64);
634  end if;
635  if(EnSFP(2 downto 0) = "001")then
636  LinkData(0) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
637  LinkCtrl(0) <= not(header(0) or EventData_in(0)(65));
638  LinkWe(0) <= EventData_we(0) and not EnSFP(3);
639  else
640  LinkData(0) <= EventData_in(1)(65) & EventData_in(1)(63 downto 0);
641  LinkCtrl(0) <= not(header(1) or EventData_in(1)(65));
642  LinkWe(0) <= EventData_we(1) and EnSFP(0) and not EnSFP(3);
643  end if;
644  if(EnSFP(2 downto 0) = "110")then
645  LinkData(1) <= EventData_in(1)(65) & EventData_in(1)(63 downto 0);
646  LinkCtrl(1) <= not(header(1) or EventData_in(1)(65));
647  LinkWe(1) <= EventData_we(1) and not EnSFP(3);
648  else
649  LinkData(1) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
650  LinkCtrl(1) <= not(header(0) or EventData_in(0)(65));
651  LinkWe(1) <= EventData_we(0) and EnSFP(1) and not EnSFP(3);
652  end if;
653  if(EnSFP(2 downto 0) = "111")then
654  LinkData(2) <= EventData_in(2)(65) & EventData_in(2)(63 downto 0);
655  LinkCtrl(2) <= not(header(2) or EventData_in(2)(65));
656  LinkWe(2) <= EventData_we(2) and not EnSFP(3);
657  else
658  LinkData(2) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
659  LinkCtrl(2) <= not(header(0) or EventData_in(0)(65));
660  LinkWe(2) <= EventData_we(0) and EnSFP(2) and not EnSFP(3);
661  end if;
662  case EnSFP(2 downto 0) is
663  when "010" | "011" | "111" => SFP2bldr_sel(0) <= "01";
664  when "100" | "101" | "110" => SFP2bldr_sel(0) <= "10";
665  when others => SFP2bldr_sel(0) <= "00";
666  end case;
667  case EnSFP(2 downto 0) is
668  when "010" | "011" | "101" | "111" => SFP2bldr_sel(1) <= "00";
669  when others => SFP2bldr_sel(1) <= "01";
670  end case;
671  case EnSFP(2 downto 0) is
672  when "100" | "110" => SFP2bldr_sel(2) <= "00";
673  when "101" => SFP2bldr_sel(2) <= "01";
674  when others => SFP2bldr_sel(2) <= "10";
675  end case;
676  evt_buf_full(0) <= ((not LinkFull_n(conv_integer(SFP2bldr_sel(0))) or not LinkDown(conv_integer(SFP2bldr_sel(0)))) and EnSFP(conv_integer(SFP2bldr_sel(0))) and not EnSFP(3)) or wport_FIFO_full(0);
677  if(SFP2bldr_sel(1)(0) = '0')then
678  evt_buf_full(1) <= ((not LinkFull_n(0) or not LinkDown(0)) and EnSFP(0) and not EnSFP(3)) or wport_FIFO_full(1);
679  else
680  evt_buf_full(1) <= ((not LinkFull_n(1) or not LinkDown(1)) and EnSFP(1) and not EnSFP(3)) or wport_FIFO_full(1);
681  end if;
682  evt_buf_full(2) <= ((not LinkFull_n(conv_integer(SFP2bldr_sel(2))) or not LinkDown(conv_integer(SFP2bldr_sel(2)))) and EnSFP(conv_integer(SFP2bldr_sel(2))) and not EnSFP(3)) or wport_FIFO_full(2);
683  if(Cntr2ms(18 downto 17) = "11" and Cntr2ms(14) = '1')then
684  Cntr2ms <= (others => '0');
685  LiveTimeCntr <= (others => (others => '0'));
686  for i in 0 to 2 loop
687  LiveTime(i) <= '0' & LiveTimeCntr(i)(18 downto 12);
688  end loop;
689  else
690  Cntr2ms <= Cntr2ms + 1;
691  for i in 0 to 2 loop
692  if(LinkFull_n(i) = '1')then
693  LiveTimeCntr(i) <= LiveTimeCntr(i) + 1;
694  end if;
695  end loop;
696  end if;
697  end if;
698 end process;
699 process(sysclk,rstCntr)
700 begin
701  if(rstCntr = '1')then
702  sync_loss_cntr <= (others => (others => '0'));
703  sync_lossSync <= (others => (others => '0'));
704  elsif(sysclk'event and sysclk = '1')then
705  for i in 0 to 2 loop
706  sync_lossSync(i) <= sync_lossSync(i)(1 downto 0) & sync_loss(i);
707  if(sync_lossSync(i)(2) = '1')then
708  sync_loss_cntr(i)(9 downto 0) <= sync_loss_cntr(i)(9 downto 0) + 1;
709  end if;
710  end loop;
711  end if;
712 end process;
713 process(sysclk,rstCntr)
714 begin
715  if(rstCntr = '1')then
716  cmsCRC_errCntr <= (others => (others => '0'));
717  EvtLength_errCntr <= (others => (others => '0'));
718  AMCLength_errCntr <= (others => (others => '0'));
719  AMCvalid_errCntr <= (others => (others => '0'));
720  AMCcrc_errCntr <= (others => (others => '0'));
721  BackPressure31 <= (others => '0');
722  BackPressure31_q <= (others => '0');
723  BackPressureCntr <= (others => (others => '0'));
724  IsBackPressure <= '0';
725  StopOverWrite <= '0';
726  elsif(sysclk'event and sysclk = '1')then
727  for i in 0 to 2 loop
728  if(inc_err(i)(0) = '1')then
729  cmsCRC_errCntr(i)(9 downto 0) <= cmsCRC_errCntr(i)(9 downto 0) + 1;
730  end if;
731  if(inc_err(i)(1) = '1')then
732  EvtLength_errCntr(i)(9 downto 0) <= EvtLength_errCntr(i)(9 downto 0) + 1;
733  end if;
734  if(inc_err(i)(2) = '1')then
735  AMClength_errCntr(i)(9 downto 0) <= AMClength_errCntr(i)(9 downto 0) + 1;
736  end if;
737  if(inc_err(i)(3) = '1')then
738  AMCvalid_errCntr(i)(9 downto 0) <= AMCvalid_errCntr(i)(9 downto 0) + 1;
739  end if;
740  if(inc_err(i)(4) = '1')then
741  AMCcrc_errCntr(i)(9 downto 0) <= AMCcrc_errCntr(i)(9 downto 0) + 1;
742  end if;
743  if(inc_err(i)(4) = '1')then
744  AMCcrc_errCntr(i)(9 downto 0) <= AMCcrc_errCntr(i)(9 downto 0) + 1;
745  end if;
746  if(BackPressure31_q(i) = '1' and BackPressure31(i) = '0')then
747  BackPressureCntr(i)(9 downto 0) <= BackPressureCntr(i)(9 downto 0) + 1;
748  end if;
749  if(IsBackPressure = '1' and Cntr_ADDR(0) = '0')then
750  BackPressure31(i) <= DaqLSC_status(i)(31);
751  end if;
752  end loop;
753  if(Cntr_ADDR(3 downto 0) = x"9")then
754  IsBackPressure <= '1';
755  else
756  IsBackPressure <= '0';
757  end if;
758  BackPressure31_q <= BackPressure31;
759  if(stop = '1')then
760  StopOverWrite <= '1';
761  end if;
762  end if;
763 end process;
764 i_check_event: check_event PORT MAP(
765  clk => sysclk ,
766  reset => resetSyncRegs(2),
767  en_stop => en_stop,
768  cmsCRC_err => cmsCRC_err,
769  EventData_in => EventData_in,
770  EventData_we => EventData_we,
771  inc_err => inc_err,
772  stop => stop
773  );
774 process(ipb_clk)
775 begin
776  if(ipb_clk'event and ipb_clk = '1')then
777  if(ipb_addr(15 downto 7) = LSC_addr(15 downto 7) and ipb_addr(6 downto 0) = "1110000" and ipb_write = '1' and ipb_strobe = '1')then
778  en_stop <= ipb_wdata(4 downto 0);
779  end if;
780  end if;
781 end process;
782 process(Cntr_ADDR)
783 begin
784  case Cntr_ADDR(6 downto 4) is
785  when "000" =>
786  Cntr_DATA <= DaqLSC_status(0)(31 downto 0);
787  when "001" =>
788  Cntr_DATA <= DaqLSC_status(1)(31 downto 0);
789  when "010" =>
790  Cntr_DATA <= DaqLSC_status(2)(31 downto 0);
791  when "011" =>
792  case Cntr_ADDR(3 downto 0) is
793  when x"0" => Cntr_DATA <= sync_loss_cntr(0);
794  when x"1" => Cntr_DATA <= sync_loss_cntr(1);
795  when x"2" => Cntr_DATA <= sync_loss_cntr(2);
796  when x"3" => Cntr_DATA <= cmsCRC_errCntr(0);
797  when x"4" => Cntr_DATA <= cmsCRC_errCntr(1);
798  when x"5" => Cntr_DATA <= cmsCRC_errCntr(2);
799  when x"6" => Cntr_DATA <= EvtLength_errCntr(0);
800  when x"7" => Cntr_DATA <= EvtLength_errCntr(1);
801  when x"8" => Cntr_DATA <= EvtLength_errCntr(2);
802  when x"a" => Cntr_DATA <= TotalEvtLengthCntr(0);
803  when x"c" => Cntr_DATA <= TotalEvtLengthCntr(1);
804  when x"e" => Cntr_DATA <= TotalEvtLengthCntr(2);
805  when others => Cntr_DATA <= (others => '0');
806  end case;
807  when "100" =>
808  case Cntr_ADDR(3 downto 0) is
809  when x"0" => Cntr_DATA <= SFP_evt_cntr(0);
810  when x"1" => Cntr_DATA <= SFP_evt_cntr(1);
811  when x"2" => Cntr_DATA <= SFP_evt_cntr(2);
812  when x"4" => Cntr_DATA <= SFP_word_cntr(0);
813  when x"5" => Cntr_DATA <= SFP_word_cntr(1);
814  when x"6" => Cntr_DATA <= SFP_word_cntr(2);
815  when x"8" => Cntr_DATA <= SFP_blk_cntr(0);
816  when x"9" => Cntr_DATA <= SFP_blk_cntr(1);
817  when x"a" => Cntr_DATA <= SFP_blk_cntr(2);
818  when others => Cntr_DATA <= (others => '0');
819  end case;
820  when "101" =>
821  case Cntr_ADDR(3 downto 0) is
822  when x"0" => Cntr_DATA <= "00000" & Written_MonBuf(1) & "00000" & Written_MonBuf(0);
823  when x"1" => Cntr_DATA <= "00000" & Written_MonBuf(3) & "00000" & Written_MonBuf(2);
824  when x"2" => Cntr_DATA <= "00000" & NXT_MonBuf(1) & "00000" & NXT_MonBuf(0);
825  when x"3" => Cntr_DATA <= "00000" & MonBuf_wa & "00000" & NXT_MonBuf(2);
826  when x"4" => Cntr_DATA <= x"00" & '0' & header & '0' & LinkFull & '0' & ReadBusy & '0' & evt_data_rdy & '0' & wport_FIFO_full & '0' & wport_rdy;
827  when x"5" => Cntr_DATA <= event_cntr(0);
828  when x"6" => Cntr_DATA <= event_cntr(1);
829  when x"7" => Cntr_DATA <= event_cntr(2);
830  when x"8" => Cntr_DATA <= word_cntr(0);
831  when x"9" => Cntr_DATA <= word_cntr(1);
832  when x"a" => Cntr_DATA <= word_cntr(2);
833  when x"b" => Cntr_DATA <= EventBufAddr_we_cntr(0);
834  when x"c" => Cntr_DATA <= EventBufAddr_we_cntr(1);
835  when x"d" => Cntr_DATA <= EventBufAddr_we_cntr(2);
836  when others => Cntr_DATA <= (others => '0');
837  end case;
838  when "110" =>
839  case Cntr_ADDR(3 downto 0) is
840  when x"0" => Cntr_DATA <= AMClength_errCntr(0);
841  when x"1" => Cntr_DATA <= AMClength_errCntr(1);
842  when x"2" => Cntr_DATA <= AMClength_errCntr(2);
843  when x"4" => Cntr_DATA <= AMCvalid_errCntr(0);
844  when x"5" => Cntr_DATA <= AMCvalid_errCntr(1);
845  when x"6" => Cntr_DATA <= AMCvalid_errCntr(2);
846  when x"8" => Cntr_DATA <= AMCcrc_errCntr(0);
847  when x"9" => Cntr_DATA <= AMCcrc_errCntr(1);
848  when x"a" => Cntr_DATA <= AMCcrc_errCntr(2);
849  when x"c" => Cntr_DATA <= BackPressureCntr(0);
850  when x"d" => Cntr_DATA <= BackPressureCntr(1);
851  when x"e" => Cntr_DATA <= BackPressureCntr(2);
852  when others => Cntr_DATA <= (others => '0');
853  end case;
854  when others =>
855  case Cntr_ADDR(3 downto 0) is
856  when x"0" => Cntr_DATA <= x"000000" & "000" & en_stop;
857  when x"1" => Cntr_DATA <= "000" & FirstBlkAddr_ra(1)(1) & "000" & FirstBlkAddr_ra(0)(1) & "000" & FirstBlkAddr_ra(1)(0) & "000" & FirstBlkAddr_ra(0)(0);
858  when x"2" => Cntr_DATA <= x"00" & "000" & FirstBlkAddr_wa & "000" & FirstBlkAddr_ra(1)(2) & "000" & FirstBlkAddr_ra(0)(2);
859  when x"3" => Cntr_DATA <= x"0" & FirstBlkAddrDo(1)(0) & x"0" & FirstBlkAddrDo(0)(0);
860  when x"4" => Cntr_DATA <= x"0" & FirstBlkAddrDo(1)(1) & x"0" & FirstBlkAddrDo(0)(1);
861  when x"5" => Cntr_DATA <= x"0" & FirstBlkAddrDo(1)(2) & x"0" & FirstBlkAddrDo(0)(2);
862  when x"6" => Cntr_DATA <= x"0000" & '0' & MonEvtQueued & '0' & WrtMonEvtDone_l & '0' & FirstBlkAddrDoValid(1) & '0' & FirstBlkAddrDoValid(0);
863  when x"7" => Cntr_DATA <= x"00" & WrtMonEvtDoneCntr(2) & WrtMonEvtDoneCntr(1) & WrtMonEvtDoneCntr(0);
864  when x"8" => Cntr_DATA <= x"000000" & LiveTime(0);
865  when x"9" => Cntr_DATA <= x"000000" & LiveTime(1);
866  when x"a" => Cntr_DATA <= x"000000" & LiveTime(2);
867  when x"b" => Cntr_DATA <= "00000" & MonBuf_wa & "00000" & MonBuf_ra;
868  when others => Cntr_DATA <= (others => '0');
869  end case;
870  end case;
871 end process;
872 i_SFP_cntr: SFP_cntr PORT MAP(
873  sysclk => sysclk,
874  clk125 => clk125,
875  ipb_clk => ipb_clk,
876  resetCntr => rstCntr,
877  DB_cmd => DB_cmd,
878  Cntr_DATA => Cntr_DATA,
879  Cntr_ADDR => Cntr_ADDR,
880  ipb_addr => ipb_addr(15 downto 0),
881  ipb_rdata => ipb_rdata
882  );
883 g_cmsCRC : for i in 0 to 2 generate
884  i_cmsCRC: cmsCRC64 PORT MAP(
885  clk => sysclk ,
886  reset => '0',
887  crc_init => cmsCRC_init(i),
888  trailer => LinkData(i)(64),
889  crc_d => LinkData(i)(63 downto 0),
890  crc_ce => LinkWe(i),
891  crc => open,
892  crc_err => cmsCRC_err(i),
893  dout => open,
894  dout_vld => open
895  );
896 end generate;
897 process(sysclk)
898 begin
899  if(sysclk'event and sysclk = '1')then
900  if(resetSyncRegs(2) = '1')then
901  cmsCRC_initp <= "000";
902  cmsCRC_init <= "111";
903  SFP_blk_cntr <= (others => (others => '0'));
904  SFP_evt_cntr <= (others => (others => '0'));
905  SFP_word_cntr <= (others => (others => '0'));
906  event_cntr <= (others => (others => '0'));
907  word_cntr <= (others => (others => '0'));
908  EventBufAddr_we_cntr <= (others => (others => '0'));
909  TotalEvtLengthCntr <= (others => (others => '0'));
910  else
911  for i in 0 to 2 loop
912  cmsCRC_initp(i) <= LinkData(i)(64) and LinkWe(i);
913  if(LinkWe(i) = '1')then
914  word_cntr(i)(9 downto 0) <= word_cntr(i)(9 downto 0) + 1;
915  end if;
916  if(LinkWe(i) = '1' and LinkData(i)(64) = '1')then
917  event_cntr(i)(9 downto 0) <= event_cntr(i)(9 downto 0) + 1;
918  end if;
919  if(SFP_we(i) = '1' and EoB(i) = '1')then
920  SFP_blk_cntr(i)(9 downto 0) <= SFP_blk_cntr(i)(9 downto 0) + 1;
921  end if;
922  if(SFP_we(i) = '1' and LinkData(i)(64) = '1')then
923  SFP_evt_cntr(i)(9 downto 0) <= SFP_evt_cntr(i)(9 downto 0) + 1;
924  end if;
925  if(SFP_we(i) = '1')then
926  SFP_word_cntr(i)(9 downto 0) <= SFP_word_cntr(i)(9 downto 0) + 1;
927  end if;
928  if(EventBufAddr_we_i(i) = '1')then
929  EventBufAddr_we_cntr(i)(9 downto 0) <= EventBufAddr_we_cntr(i)(9 downto 0) + 1;
930  end if;
931  if(EventData_we(i) = '1')then
932  if(EventData_in(i)(65) = '1')then
933  TotalEvtLengthCntr(i)(24 downto 0) <= TotalEvtLengthCntr(i)(24 downto 0) + ('0' & EventData_in(i)(55 downto 32));
934  end if;
935  end if;
936  end loop;
937  cmsCRC_init <= cmsCRC_initp;
938  end if;
939  end if;
940 end process;
941 end Behavioral;
942