1 ----------------------------------------------------------------------------------
5 -- Create Date: 14:
07:
47 10/07/2013
7 -- Module Name: TCPIP_if - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
19 ----------------------------------------------------------------------------------
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;
28 -- Uncomment the following library declaration if using
29 -- arithmetic functions with or values
30 --use IEEE.NUMERIC_STD.ALL;
32 -- Uncomment the following library declaration if instantiating
33 -- any Xilinx primitives in this code.
35 use UNISIM.VComponents.
all;
37 use UNIMACRO.vcomponents.
all;
40 generic(N_SFP : := 1);
51 enSFP : IN (3 downto 0);
52 SFP_ABS : IN (2 downto 0);
53 LSC_ID : IN (15 downto 0);
54 SFP_down : OUT (2 downto 0);
57 evt_data_rdy : in (2 downto 0);
58 EventData_in : in array3X67;
59 EventData_we : in (2 downto 0);
60 EventData_re : out (2 downto 0);
--
61 evt_buf_full : out (2 downto 0);
62 buf_rqst : in (3 downto 0);
64 MonBufOverWrite : in ;
69 mon_evt_cnt : out (31 downto 0);
70 WrtMonBlkDone : in (2 downto 0);
71 WrtMonEvtDone : in (2 downto 0);
73 wport_rdy : in (2 downto 0);
74 wport_FIFO_full : in (2 downto 0);
75 -- signal to ddr_if, AMC_if to start moving data
76 EventBufAddr_we : out (2 downto 0);
77 EventBufAddr : out array3X14;
98 ipb_addr : in (31 downto 0);
99 ipb_wdata : in (31 downto 0);
100 ipb_rdata : out (31 downto 0);
107 generic(N_SFP : :=
1);
108 Port ( sys_reset :
in ;
-- active high reset of all logic but GTX
110 sfp_pd :
in array3x2;
112 LinkWe :
in (
2 downto 0);
113 LinkCtrl :
in (
2 downto 0);
114 LinkData :
in array3x64;
115 srcID :
in array3x16;
116 LinkDown :
out (
2 downto 0);
117 LinkFull :
out (
2 downto 0);
118 sync_loss :
out (
2 downto 0);
-- goes to '1' (rxusrclk) when SERDES is out of synch
119 status_ce :
in (
2 downto 0);
-- not implemented yet
120 status_addr :
in (
15 downto 0);
-- not implemented yet
121 status_port :
out array3x64;
-- first 32 bits are hard-wired
123 txusrclk_o :
out ;
-- reconstructed tx clock, to be used to clock sending circuitry
124 rxusrclk_o :
out ;
-- reconstructed rx clock, to be used to clock receiving circuitry
126 gtx_reset :
in ;
-- full reset of GTX only
127 gtx_refclk_p :
in ;
-- iob for refclk neg
128 gtx_refclk_n :
in ;
-- iob for refclk neg
129 sfp_rxn :
in (
2 downto 0);
-- sfp iobs
130 sfp_rxp :
in (
2 downto 0);
131 sfp_txn :
out (
2 downto 0);
132 sfp_txp :
out (
2 downto 0)
136 generic(N_SFP : :=
1);
137 Port ( sys_reset :
in ;
-- active high reset of all logic but GTX
139 sfp_pd :
in array3x2;
141 LinkWe :
in (
2 downto 0);
142 LinkCtrl :
in (
2 downto 0);
143 LinkData :
in array3x64;
144 srcID :
in array3x16;
145 LinkDown :
out (
2 downto 0);
146 LinkFull :
out (
2 downto 0);
147 sync_loss :
out (
2 downto 0);
-- goes to '1' (rxusrclk) when SERDES is out of synch
148 status_ce :
in (
2 downto 0);
-- not implemented yet
149 status_addr :
in (
15 downto 0);
-- not implemented yet
150 status_port :
out array3x64;
-- first 32 bits are hard-wired
152 txusrclk_o :
out ;
-- reconstructed tx clock, to be used to clock sending circuitry
153 rxusrclk_o :
out ;
-- reconstructed rx clock, to be used to clock receiving circuitry
155 gtx_reset :
in ;
-- full reset of GTX only
156 gtx_refclk :
in ;
-- iob for refclk neg
157 sfp_rxn :
in (
2 downto 0);
-- sfp iobs
158 sfp_rxp :
in (
2 downto 0);
159 sfp_txn :
out (
2 downto 0);
160 sfp_txp :
out (
2 downto 0)
169 crc_d :
IN (
63 downto 0);
171 crc :
OUT (
15 downto 0);
173 dout :
OUT (
63 downto 0);
181 en_stop :
IN (
4 downto 0);
182 cmsCRC_err :
IN (
2 downto 0);
183 EventData_in :
IN array3X67;
184 EventData_we :
IN (
2 downto 0);
185 inc_err :
OUT array3X5;
196 Cntr_DATA :
IN (
31 downto 0);
197 ipb_addr :
IN (
15 downto 0);
198 Cntr_ADDR :
OUT (
6 downto 0);
199 ipb_rdata :
OUT (
31 downto 0)
202 function A_GT_B (A, B : (
10 downto 0))
return is
203 variable tmp : (10 downto 0);
206 if(tmp(10) = '0' and or_reduce(tmp(9 downto 0)) = '1')then
212 function A_GE_B (A, B : (
10 downto 0))
return is
213 variable tmp : (10 downto 0);
216 if(tmp(10) = '0')then
222 signal resetSyncRegs : (2 downto 0) := (others => '0');
223 signal daq_resetSyncRegs : (2 downto 0) := (others => '0');
224 signal inc_ddr_paSyncRegs : (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 : (2 downto 0) := (others => '0');
228 signal ReadBusy : (2 downto 0) := (others => '0');
229 signal sysDIV2 : := '0';
230 --signal MonBuf_avl_i : := '0';
231 signal MonBuf_wa : (10 downto 0) := (others => '0');
232 signal MonBuf_ra : (10 downto 0) := (others => '0');
233 signal MonBufUsed : (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 : (2 downto 0) := (others => '0');
237 signal AddrOffset : array3X10 := (others => (others => '0'));
238 signal header : (2 downto 0) := (others => '0');
239 signal header_q : (2 downto 0) := (others => '0');
240 signal sfp_rxn : (2 downto 0) := (others => '0');
241 signal sfp_rxp : (2 downto 0) := (others => '0');
242 signal sfp_txn : (2 downto 0) := (others => '0');
243 signal sfp_txp : (2 downto 0) := (others => '0');
244 signal sync_loss : (2 downto 0) := (others => '0');
245 signal LinkFull_n : (2 downto 0) := (others => '0');
246 signal LinkFull : (2 downto 0) := (others => '0');
247 signal LinkCtrl : (2 downto 0) := (others => '0');
248 signal LinkWe : (2 downto 0) := (others => '0');
249 signal LinkDown : (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 : (2 downto 0) := (others => '0');
255 signal EoB : (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 : := '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 : := '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 : (2 downto 0) := (others => '0');
272 signal MonEvtQueued : (2 downto 0) := (others => '0');
273 signal FirstBlkAddrDoValid : array2X3 := (others => (others => '0'));
274 signal FirstBlkAddr_wa : (4 downto 0) := (others => '0');
275 signal FirstBlkAddrDi : (11 downto 0) := (others => '0');
276 signal FirstBlkAddr_we : := '0';
277 signal MonBuf_full : := '0';
278 signal mon_evt_cnt_i : (10 downto 0) := (others => '0');
279 signal status_addr : (15 downto 0) := (others => '0');
280 signal cmsCRC_initp : (2 downto 0) := (others => '0');
281 signal cmsCRC_init : (2 downto 0) := (others => '0');
282 signal cmsCRC_err : (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 : (2 downto 0) := (others => '1');
291 signal BackPressure31_q : (2 downto 0) := (others => '1');
292 signal IsBackPressure : := '0';
293 signal StopOverWrite : := '0';
294 signal en_stop : (4 downto 0) := (others => '1');
295 signal stop : := '0';
296 signal Cntr2ms : (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 : (31 downto 0) := (others => '0');
301 signal Cntr_ADDR : (6 downto 0) := (others => '0');
302 component chipscope1
is
305 Din :
in (
303 downto 0));
307 signal cs : (303 downto 0) := (others => '0');
309 --i_chipscope: chipscope1
310 -- Port map( clk => sysclk, Din => cs);
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;
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);
328 sys_reset => daq_resetSyncRegs
(2),
333 LinkCtrl => LinkCtrl,
334 LinkData => LinkDatap,
336 LinkDown => LinkDown,
337 LinkFull => LinkFull_n,
338 sync_loss => sync_loss,
340 status_addr => status_addr,
341 status_port => DaqLSC_status,
342 txusrclk_o => txusrclk,
344 gtx_reset => gtx_reset,
345 gtx_refclk_p => SFP_REFCLK_P,
346 gtx_refclk_n => SFP_REFCLK_N,
355 sys_reset => daq_resetSyncRegs
(2),
360 LinkCtrl => LinkCtrl,
361 LinkData => LinkDatap,
363 LinkDown => LinkDown,
364 LinkFull => LinkFull_n,
365 sync_loss => sync_loss,
367 status_addr => status_addr,
368 status_port => DaqLSC_status,
369 txusrclk_o => txusrclk,
371 gtx_reset => gtx_reset,
372 gtx_refclk => GbE_REFCLK,
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)
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';
406 process(sysclk,reset)
409 resetSyncRegs <= (others => '1');
410 elsif(sysclk'event and sysclk = '1')then
411 resetSyncRegs <= resetSyncRegs(1 downto 0) & '0';
414 g_FirstBlkAddr: for j in 0 to 1 generate
415 g1_FirstBlkAddr: for i in 0 to 5 generate
416 i_FirstBlkAddr : RAM32M
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
439 FirstBlkAddrDi <= '0' & MonBuf_wa;
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);
448 if(resetSyncRegs(2) = '1')then
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
459 elsif(chk_MonBuf_avl = '1')then
460 if(MonBufUsed(9 downto 8) = "11")then
466 if(MonBufOverWrite = '1')then
467 mon_evt_cnt_i <= MonBuf_full & Written_MonBuf(3)(9 downto 0);
469 mon_evt_cnt_i <= Written_MonBuf(3) - MonBuf_ra;
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
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')));
500 if(EVENTdata_in(i)(64) = '1' and EVENTdata_we(i) = '1')then
502 elsif(evt_data_rdy(i) = '1' and wport_rdy(i) = '1')then
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';
509 EventBufAddr_we_i(i) <= '0';
512 if(MonBufOverWrite = '1' and Written_MonBuf(3)(10) = '1')then
517 if(FirstBlkAddr_re(j)(i) = '1')then
518 FirstBlkAddr_ra(j)(i) <= FirstBlkAddr_ra(j)(i) + 1;
520 if(FirstBlkAddr_ra(j)(i) = FirstBlkAddr_wa)then
521 FirstBlkAddrDoValid(j)(i) <= '0';
523 FirstBlkAddrDoValid(j)(i) <= '1';
527 if(FirstBlkAddr_we = '1')then
528 FirstBlkAddr_wa <= FirstBlkAddr_wa + 1;
531 if(WrtMonEvtDone(i) = '1')then
532 WrtMonEvtDoneCntr(i) <= WrtMonEvtDoneCntr(i) + 1;
534 if(WrtMonEvtDone(i) = '1')then
535 WrtMonEvtDone_l(i) <= '1';
536 elsif(FirstBlkAddrDoValid(0)(i) = '1')then
537 WrtMonEvtDone_l(i) <= '0';
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';
545 FirstBlkAddr_re(1)(i) <= FirstBlkAddrDoValid(1)(i) and MonEvtQueued(i);
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;
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;
557 if(Written_MonBuf(0) = Written_MonBuf(3) and WrtMonEvtDone_l(0) = '0')then
558 Written_MonBufMatch(0) <= '1';
560 Written_MonBufMatch(0) <= '0';
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';
565 Written_MonBufMatch(1) <= '0';
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';
570 Written_MonBufMatch(2) <= '0';
572 if(Written_MonBufMatch = "000" and sysDIV2 = '0')then
573 Written_MonBuf(3) <= Written_MonBuf(3) + 1;
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;
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;
587 inc_ddr_paSyncRegs <= inc_ddr_paSyncRegs(2 downto 0) & inc_ddr_pa;
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";
594 AddrOffset(1)(9 downto 6) <= x"0";
595 AddrOffset(2)(9 downto 6) <= x"a";
597 EventBufAddr(i) <= NXT_MonBuf(i)(9 downto 0) & AddrOffset(i)(9 downto 6);
603 if(sysclk'event and sysclk = '1')then
604 sysDIV2 <= not sysDIV2;
606 if(resetSyncRegs(2) = '1')then
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);
614 if(EnSFP(2 downto 1) = "00")then
615 SFP_we(0) <= EventData_we(0);
616 EoB(0) <= EventData_in(0)(64);
618 SFP_we(0) <= EventData_we(1) and EnSFP(0);
619 EoB(0) <= EventData_in(1)(64);
621 if(EnSFP(2 downto 0) = "110")then
622 SFP_we(1) <= EventData_we(1);
623 EoB(1) <= EventData_in(1)(64);
625 SFP_we(1) <= EventData_we(0) and EnSFP(1);
626 EoB(1) <= EventData_in(0)(64);
628 if(EnSFP(2 downto 0) = "111")then
629 SFP_we(2) <= EventData_we(2);
630 EoB(2) <= EventData_in(2)(64);
632 SFP_we(2) <= EventData_we(0) and EnSFP(2);
633 EoB(2) <= EventData_in(0)(64);
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);
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);
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);
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);
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);
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);
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";
667 case EnSFP(2 downto 0) is
668 when "010" | "011" | "101" | "111" => SFP2bldr_sel(1) <= "00";
669 when others => SFP2bldr_sel(1) <= "01";
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";
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);
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);
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'));
687 LiveTime(i) <= '0' & LiveTimeCntr(i)(18 downto 12);
690 Cntr2ms <= Cntr2ms + 1;
692 if(LinkFull_n(i) = '1')then
693 LiveTimeCntr(i) <= LiveTimeCntr(i) + 1;
699 process(sysclk,rstCntr)
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
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;
713 process(sysclk,rstCntr)
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
728 if(inc_err(i)(0) = '1')then
729 cmsCRC_errCntr(i)(9 downto 0) <= cmsCRC_errCntr(i)(9 downto 0) + 1;
731 if(inc_err(i)(1) = '1')then
732 EvtLength_errCntr(i)(9 downto 0) <= EvtLength_errCntr(i)(9 downto 0) + 1;
734 if(inc_err(i)(2) = '1')then
735 AMClength_errCntr(i)(9 downto 0) <= AMClength_errCntr(i)(9 downto 0) + 1;
737 if(inc_err(i)(3) = '1')then
738 AMCvalid_errCntr(i)(9 downto 0) <= AMCvalid_errCntr(i)(9 downto 0) + 1;
740 if(inc_err(i)(4) = '1')then
741 AMCcrc_errCntr(i)(9 downto 0) <= AMCcrc_errCntr(i)(9 downto 0) + 1;
743 if(inc_err(i)(4) = '1')then
744 AMCcrc_errCntr(i)(9 downto 0) <= AMCcrc_errCntr(i)(9 downto 0) + 1;
746 if(BackPressure31_q(i) = '1' and BackPressure31(i) = '0')then
747 BackPressureCntr(i)(9 downto 0) <= BackPressureCntr(i)(9 downto 0) + 1;
749 if(IsBackPressure = '1' and Cntr_ADDR(0) = '0')then
750 BackPressure31(i) <= DaqLSC_status(i)(31);
753 if(Cntr_ADDR(3 downto 0) = x"9")then
754 IsBackPressure <= '1';
756 IsBackPressure <= '0';
758 BackPressure31_q <= BackPressure31;
760 StopOverWrite <= '1';
766 reset => resetSyncRegs
(2),
768 cmsCRC_err => cmsCRC_err,
769 EventData_in => EventData_in,
770 EventData_we => EventData_we,
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);
784 case Cntr_ADDR(6 downto 4) is
786 Cntr_DATA <= DaqLSC_status(0)(31 downto 0);
788 Cntr_DATA <= DaqLSC_status(1)(31 downto 0);
790 Cntr_DATA <= DaqLSC_status(2)(31 downto 0);
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');
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');
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');
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');
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');
876 resetCntr => rstCntr,
878 Cntr_DATA => Cntr_DATA,
879 Cntr_ADDR => Cntr_ADDR,
880 ipb_addr => ipb_addr
(15 downto 0),
881 ipb_rdata => ipb_rdata
883 g_cmsCRC : for i in 0 to 2 generate
887 crc_init => cmsCRC_init
(i
),
888 trailer => LinkData
(i
)(64),
889 crc_d => LinkData
(i
)(63 downto 0),
892 crc_err => cmsCRC_err
(i
),
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'));
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;
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;
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;
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;
925 if(SFP_we(i) = '1')then
926 SFP_word_cntr(i)(9 downto 0) <= SFP_word_cntr(i)(9 downto 0) + 1;
928 if(EventBufAddr_we_i(i) = '1')then
929 EventBufAddr_we_cntr(i)(9 downto 0) <= EventBufAddr_we_cntr(i)(9 downto 0) + 1;
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));
937 cmsCRC_init <= cmsCRC_initp;