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;
49 enSFP : IN (3 downto 0);
50 SFP_ABS : IN (2 downto 0);
51 LSC_ID : IN (15 downto 0);
52 SFP_down : OUT (2 downto 0);
55 evt_data_rdy : in (2 downto 0);
56 EventData_in : in array3X67;
57 EventData_we : in (2 downto 0);
58 EventData_re : out (2 downto 0);
--
59 evt_buf_full : out (2 downto 0);
60 buf_rqst : in (3 downto 0);
62 MonBufOverWrite : in ;
66 mon_evt_cnt : out (31 downto 0);
67 WrtMonBlkDone : in (2 downto 0);
68 WrtMonEvtDone : in (2 downto 0);
70 wport_rdy : in (2 downto 0);
71 wport_FIFO_full : in (2 downto 0);
72 -- signal to ddr_if, AMC_if to start moving data
73 EventBufAddr_we : out (2 downto 0);
74 EventBufAddr : out array3X14;
94 ipb_addr : in (31 downto 0);
95 ipb_wdata : in (31 downto 0);
96 ipb_rdata : out (31 downto 0);
103 Port ( sys_reset :
in ;
-- active high reset of all logic but GTX
105 sfp_pd :
in array3x2;
107 LinkWe :
in (
2 downto 0);
108 LinkCtrl :
in (
2 downto 0);
109 LinkData :
in array3x64;
110 srcID :
in array3x16;
111 LinkDown :
out (
2 downto 0);
112 LinkFull :
out (
2 downto 0);
113 sync_loss :
out (
2 downto 0);
-- goes to '1' (rxusrclk) when SERDES is out of synch
114 status_ce :
in (
2 downto 0);
-- not implemented yet
115 status_addr :
in (
15 downto 0);
-- not implemented yet
116 status_port :
out array3x64;
-- first 32 bits are hard-wired
118 txusrclk_o :
out ;
-- reconstructed tx clock, to be used to clock sending circuitry
119 rxusrclk_o :
out ;
-- reconstructed rx clock, to be used to clock receiving circuitry
121 gtx_reset :
in ;
-- full reset of GTX only
122 gtx_refclk_p :
in ;
-- iob for refclk neg
123 gtx_refclk_n :
in ;
-- iob for refclk neg
124 sfp_rxn :
in (
2 downto 0);
-- sfp iobs
125 sfp_rxp :
in (
2 downto 0);
126 sfp_txn :
out (
2 downto 0);
127 sfp_txp :
out (
2 downto 0)
136 crc_d :
IN (
63 downto 0);
138 crc :
OUT (
15 downto 0);
140 dout :
OUT (
63 downto 0);
148 en_stop :
IN (
4 downto 0);
149 cmsCRC_err :
IN (
2 downto 0);
150 EventData_in :
IN array3X67;
151 EventData_we :
IN (
2 downto 0);
152 inc_err :
OUT array3X5;
156 function A_GT_B (A, B : (
10 downto 0))
return is
157 variable tmp : (10 downto 0);
160 if(tmp(10) = '0' and or_reduce(tmp(9 downto 0)) = '1')then
166 function A_GE_B (A, B : (
10 downto 0))
return is
167 variable tmp : (10 downto 0);
170 if(tmp(10) = '0')then
176 signal resetSyncRegs : (2 downto 0) := (others => '0');
177 signal daq_resetSyncRegs : (2 downto 0) := (others => '0');
178 signal inc_ddr_paSyncRegs : (3 downto 0) := (others => '0');
179 signal bldr2SFP_sel : array3X2 := (others => (others => '0'));
180 signal SFP2bldr_sel : array3X2 := (others => (others => '0'));
181 signal EventBufAddr_we_i : (2 downto 0) := (others => '0');
182 signal ReadBusy : (2 downto 0) := (others => '0');
183 signal sysDIV2 : := '0';
184 --signal MonBuf_avl_i : := '0';
185 signal MonBuf_wa : (10 downto 0) := (others => '0');
186 signal MonBuf_ra : (10 downto 0) := (others => '0');
187 signal MonBufUsed : (9 downto 0) := (others => '0');
188 signal NXT_MonBuf : array3X11 := (others => (others => '0'));
189 signal Written_MonBuf : array4X11 := (others => (others => '0'));
190 signal Written_MonBufMatch : (2 downto 0) := (others => '0');
191 signal AddrOffset : array3X10 := (others => (others => '0'));
192 signal header : (2 downto 0) := (others => '0');
193 signal header_q : (2 downto 0) := (others => '0');
194 signal sfp_rxn : (2 downto 0) := (others => '0');
195 signal sfp_rxp : (2 downto 0) := (others => '0');
196 signal sfp_txn : (2 downto 0) := (others => '0');
197 signal sfp_txp : (2 downto 0) := (others => '0');
198 signal sync_loss : (2 downto 0) := (others => '0');
199 signal LinkFull_n : (2 downto 0) := (others => '0');
200 signal LinkFull : (2 downto 0) := (others => '0');
201 signal LinkCtrl : (2 downto 0) := (others => '0');
202 signal LinkWe : (2 downto 0) := (others => '0');
203 signal LinkDown : (2 downto 0) := (others => '0');
204 signal DaqLSC_status : array3X64 := (others => (others => '0'));
205 signal LinkData : array3X65 := (others => (others => '0'));
206 signal sync_loss_cntr : array3X32 := (others => (others => '0'));
207 signal SFP_we : (2 downto 0) := (others => '0');
208 signal EoB : (2 downto 0) := (others => '0');
209 signal SFP_evt_cntr : array3X32 := (others => (others => '0'));
210 signal SFP_blk_cntr : array3X32 := (others => (others => '0'));
211 signal SFP_word_cntr : array3X32 := (others => (others => '0'));
212 signal event_cntr : array3X32 := (others => (others => '0'));
213 signal word_cntr : array3X32 := (others => (others => '0'));
214 signal EventBufAddr_we_cntr : array3X32 := (others => (others => '0'));
215 signal src_ID : array3X16 := (others => (others => '0'));
216 signal txusrclk : := '0';
217 signal LinkDatap : array3X64 := (others => (others => '0'));
218 signal sfp_pd : array3X2 := (others => (others => '0'));
219 signal WrtMonEvtDoneCntr : array3X8 := (others => (others => '0'));
220 signal chk_MonBuf_avl : := '0';
221 signal FirstBlkAddrDo : array2x3x12 := (others => (others => (others => '0')));
222 signal FirstBlkAddr_ra : array2x3x5 := (others => (others => (others => '0')));
223 signal FirstBlkAddr_re : array2X3 := (others => (others => '0'));
224 signal WrtMonEvtDone_l : (2 downto 0) := (others => '0');
225 signal MonEvtQueued : (2 downto 0) := (others => '0');
226 signal FirstBlkAddrDoValid : array2X3 := (others => (others => '0'));
227 signal FirstBlkAddr_wa : (4 downto 0) := (others => '0');
228 signal FirstBlkAddrDi : (11 downto 0) := (others => '0');
229 signal FirstBlkAddr_we : := '0';
230 signal MonBuf_full : := '0';
231 signal mon_evt_cnt_i : (10 downto 0) := (others => '0');
232 signal status_addr : (15 downto 0) := (others => '0');
233 signal cmsCRC_initp : (2 downto 0) := (others => '0');
234 signal cmsCRC_init : (2 downto 0) := (others => '0');
235 signal cmsCRC_err : (2 downto 0) := (others => '0');
236 signal cmsCRC_errCntr : array3X32 := (others => (others => '0'));
237 signal TotalEvtLengthCntr24q : (2 downto 0) := (others => '0');
238 signal EvtLength_errCntr : array3X32 := (others => (others => '0'));
239 signal AMClength_errCntr : array3X32 := (others => (others => '0'));
240 signal AMCvalid_errCntr : array3X32 := (others => (others => '0'));
241 signal AMCcrc_errCntr : array3X32 := (others => (others => '0'));
242 signal TotalEvtLengthCntr : array3X56 := (others => (others => '0'));
243 signal StopOverWrite : := '0';
244 signal en_stop : (4 downto 0) := (others => '1');
245 signal stop : := '0';
246 signal inc_err : array3x5 := (others => (others => '0'));
247 component chipscope1
is
250 Din :
in (
303 downto 0));
252 signal cs : (303 downto 0) := (others => '0');
254 --i_chipscope: chipscope1
255 -- Port map( clk => sysclk, Din => cs);
257 EventBufAddr_we <= EventBufAddr_we_i;
258 mon_evt_cnt(31 downto 11) <= (others => '0');
259 mon_evt_cnt(10 downto 0) <= mon_evt_cnt_i;
261 sfp_pd(0) <= "00" when Dis_pd = '1' or SFP_ABS(0) = '0' else "11";
262 sfp_pd(1) <= "00" when Dis_pd = '1' or SFP_ABS(1) = '0' else "11";
263 sfp_pd(2) <= "00" when Dis_pd = '1' or SFP_ABS(2) = '0' else "11";
264 SFP_down(2) <= not LinkDown(2) and not enSFP(3) and enSFP(2);
265 SFP_down(1) <= not LinkDown(1) and not enSFP(3) and enSFP(1);
266 SFP_down(0) <= not LinkDown(0) and not enSFP(3) and enSFP(0);
267 LinkFull(2) <= not LinkFull_n(2) and not enSFP(3) and enSFP(2);
268 LinkFull(1) <= not LinkFull_n(1) and not enSFP(3) and enSFP(1);
269 LinkFull(0) <= not LinkFull_n(0) and not enSFP(3) and enSFP(0);
271 sys_reset => daq_resetSyncRegs
(2),
276 LinkCtrl => LinkCtrl,
277 LinkData => LinkDatap,
279 LinkDown => LinkDown,
280 LinkFull => LinkFull_n,
281 sync_loss => sync_loss,
283 status_addr => status_addr ,
284 status_port => DaqLSC_status ,
285 txusrclk_o => txusrclk,
287 gtx_reset => gtx_reset,
288 gtx_refclk_p => SFP_REFCLK_P ,
289 gtx_refclk_n => SFP_REFCLK_N ,
295 status_addr <= x"000" & ipb_addr(3 downto 0);
296 LinkDatap(0) <= LinkData(0)(63 downto 0);
297 LinkDatap(1) <= LinkData(1)(63 downto 0);
298 LinkDatap(2) <= LinkData(2)(63 downto 0);
299 src_ID(0) <= LSC_ID(15 downto 2) & "00";
300 src_ID(1) <= LSC_ID(15 downto 2) & "01";
301 src_ID(2) <= LSC_ID(15 downto 2) & "10";
302 sfp_rxn(0) <= SFP0_RXN;
303 sfp_rxp(0) <= SFP0_RXP;
304 SFP0_TXN <= sfp_txn(0);
305 SFP0_TXP <= sfp_txp(0);
306 sfp_rxn(1) <= SFP1_RXN;
307 sfp_rxp(1) <= SFP1_RXP;
308 SFP1_TXN <= sfp_txn(1);
309 SFP1_TXP <= sfp_txp(1);
310 sfp_rxn(2) <= SFP2_RXN;
311 sfp_rxp(2) <= SFP2_RXP;
312 SFP2_TXN <= sfp_txn(2);
313 SFP2_TXP <= sfp_txp(2);
314 process(sysclk,daq_reset)
316 if(daq_reset = '1')then
317 daq_resetSyncRegs <= (others => '1');
318 elsif(sysclk'event and sysclk = '1')then
319 daq_resetSyncRegs <= daq_resetSyncRegs(1 downto 0) & '0';
322 process(sysclk,reset)
325 resetSyncRegs <= (others => '1');
326 elsif(sysclk'event and sysclk = '1')then
327 resetSyncRegs <= resetSyncRegs(1 downto 0) & '0';
330 g_FirstBlkAddr: for j in 0 to 1 generate
331 g1_FirstBlkAddr: for i in 0 to 5 generate
332 i_FirstBlkAddr : RAM32M
334 DOA => FirstBlkAddrDo
(j
)(0)(i*2+1
downto i*2
),
-- Read port A 2-bit output
335 DOB => FirstBlkAddrDo
(j
)(1)(i*2+1
downto i*2
),
-- Read port B 2-bit output
336 DOC => FirstBlkAddrDo
(j
)(2)(i*2+1
downto i*2
),
-- Read port C 2-bit output
337 DOD =>
open,
-- Read/Write port D 2-bit output
338 ADDRA => FirstBlkAddr_ra
(j
)(0),
-- Read port A 5-bit address input
339 ADDRB => FirstBlkAddr_ra
(j
)(1),
-- Read port B 5-bit address input
340 ADDRC => FirstBlkAddr_ra
(j
)(2),
-- Read port C 5-bit address input
341 ADDRD => FirstBlkAddr_wa,
-- Read/Write port D 5-bit address input
342 DIA => FirstBlkAddrDi
(i*2+1
downto i*2
),
-- RAM 2-bit data write input addressed by ADDRD,
343 -- read addressed by ADDRA
344 DIB => FirstBlkAddrDi
(i*2+1
downto i*2
),
-- RAM 2-bit data write input addressed by ADDRD,
345 -- read addressed by ADDRB
346 DIC => FirstBlkAddrDi
(i*2+1
downto i*2
),
-- RAM 2-bit data write input addressed by ADDRD,
347 -- read addressed by ADDRC
348 DID => "
00",
-- RAM 2-bit data write input addressed by ADDRD,
349 -- read addressed by ADDRD
350 WCLK => sysclk,
-- Write clock input
351 WE => FirstBlkAddr_we
-- Write enable input
355 FirstBlkAddrDi <= '0' & MonBuf_wa;
358 if(sysclk'event and sysclk = '1')then
359 if(resetSyncRegs(2) = '1')then
360 chk_MonBuf_avl <= '1';
361 elsif(buf_rqst(0) = '1')then
362 chk_MonBuf_avl <= buf_rqst(3);
364 if(resetSyncRegs(2) = '1')then
366 elsif(WaitMonBuf = '1' or MonBufOverWrite = '1')then
367 if((MonBuf_wa(10) /= MonBuf_ra(10) and MonBuf_wa(9 downto 0) = MonBuf_ra(9 downto 0)))then
372 elsif(chk_MonBuf_avl = '1')then
373 if(MonBufUsed(9 downto 8) = "11")then
379 if(MonBufOverWrite = '1')then
380 mon_evt_cnt_i <= '0' & Written_MonBuf(3)(9 downto 0);
382 mon_evt_cnt_i <= Written_MonBuf(3) - MonBuf_ra;
384 if(MonBufOverWrite = '0')then
385 MonBuf_empty <= not or_reduce(mon_evt_cnt_i);
386 elsif(Written_MonBuf(3) /= MonBuf_ra or MonBuf_full = '1')then
391 if(resetSyncRegs(2) = '1')then
392 ReadBusy <= (others => '0');
393 EventData_re <= (others => '0');
394 EventBufAddr_we_i <= (others => '0');
395 MonBuf_wa <= (others => '0');
396 MonBuf_ra <= (others => '0');
397 MonBufUsed <= (others => '0');
398 Written_MonBufMatch <= (others => '1');
399 Written_MonBuf <= (others => (others => '0'));
400 NXT_MonBuf <= (others => (others => '0'));
401 inc_ddr_paSyncRegs <= (others => '0');
402 FirstBlkAddr_we <= '0';
403 FirstBlkAddr_re <= (others => (others => '0'));
404 FirstBlkAddrDoValid <= (others => (others => '0'));
405 WrtMonEvtDone_l <= (others => '0');
406 WrtMonEvtDoneCntr <= (others => (others => '0'));
407 MonEvtQueued <= (others => '0');
408 FirstBlkAddr_wa <= (others => '0');
409 FirstBlkAddr_ra <= (others => (others => (others => '0')));
413 if(EVENTdata_in(i)(64) = '1' and EVENTdata_we(i) = '1')then
415 elsif(evt_data_rdy(i) = '1' and wport_rdy(i) = '1')then
418 EventData_re(i) <= evt_data_rdy(i) and wport_rdy(i) and not ReadBusy(i);
419 if(EventData_in(i)(66) = '0' and evt_data_rdy(i) = '1' and wport_rdy(i) = '1' and ReadBusy(i) = '0')then
420 EventBufAddr_we_i(i) <= '1';
422 EventBufAddr_we_i(i) <= '0';
425 if(MonBufOverWrite = '1' and Written_MonBuf(3)(10) = '1')then
430 if(FirstBlkAddr_re(j)(i) = '1')then
431 FirstBlkAddr_ra(j)(i) <= FirstBlkAddr_ra(j)(i) + 1;
433 if(FirstBlkAddr_ra(j)(i) = FirstBlkAddr_wa)then
434 FirstBlkAddrDoValid(j)(i) <= '0';
436 FirstBlkAddrDoValid(j)(i) <= '1';
440 if(FirstBlkAddr_we = '1')then
441 FirstBlkAddr_wa <= FirstBlkAddr_wa + 1;
444 if(WrtMonEvtDone(i) = '1')then
445 WrtMonEvtDoneCntr(i) <= WrtMonEvtDoneCntr(i) + 1;
447 if(WrtMonEvtDone(i) = '1')then
448 WrtMonEvtDone_l(i) <= '1';
449 elsif(FirstBlkAddrDoValid(0)(i) = '1')then
450 WrtMonEvtDone_l(i) <= '0';
452 FirstBlkAddr_re(0)(i) <= FirstBlkAddrDoValid(0)(i) and WrtMonEvtDone_l(i);
453 if(EventData_we(i) = '1' and EventData_in(i)(66 downto 65) = "01")then
454 MonEvtQueued(i) <= '1';
455 elsif(FirstBlkAddrDoValid(1)(i) = '1')then
456 MonEvtQueued(i) <= '0';
458 FirstBlkAddr_re(1)(i) <= FirstBlkAddrDoValid(1)(i) and MonEvtQueued(i);
460 -- FirstBlkAddr_we <= buf_rqst(3)
and buf_rqst(
0)
and MonBuf_avl_i;
461 FirstBlkAddr_we <= buf_rqst(3) and buf_rqst(0);
462 -- if(buf_rqst(0) = '1'
and MonBuf_avl_i = '1')
then
463 if(buf_rqst(0) = '1')then
464 MonBuf_wa <= MonBuf_wa + 1;
466 MonBufUsed <= MonBuf_wa(9 downto 0) - MonBuf_ra(9 downto 0);
467 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
468 MonBuf_ra <= MonBuf_ra + 1;
470 if(Written_MonBuf(0) = Written_MonBuf(3) and WrtMonEvtDone_l(0) = '0')then
471 Written_MonBufMatch(0) <= '1';
473 Written_MonBufMatch(0) <= '0';
475 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
476 Written_MonBufMatch(1) <= '1';
478 Written_MonBufMatch(1) <= '0';
480 if(EnSFP(2 downto 0) = "111" and Written_MonBuf(2) = Written_MonBuf(3) and WrtMonEvtDone_l(2) = '0')then
481 Written_MonBufMatch(2) <= '1';
483 Written_MonBufMatch(2) <= '0';
485 if(Written_MonBufMatch = "000" and sysDIV2 = '0')then
486 Written_MonBuf(3) <= Written_MonBuf(3) + 1;
489 if(FirstBlkAddr_re(0)(i) = '1')then
490 Written_MonBuf(i) <= FirstBlkAddrDo(0)(i)(10 downto 0);
491 elsif(WrtMonBlkDone(i) = '1')then
492 Written_MonBuf(i) <= Written_MonBuf(i) + 1;
494 if(FirstBlkAddr_re(1)(i) = '1')then
495 NXT_MonBuf(i) <= FirstBlkAddrDo(1)(i)(10 downto 0);
496 elsif(EventBufAddr_we_i(i) = '1' and EventData_in(i)(66) = '0')then
497 NXT_MonBuf(i) <= NXT_MonBuf(i) + 1;
500 inc_ddr_paSyncRegs <= inc_ddr_paSyncRegs(2 downto 0) & inc_ddr_pa;
502 case EnSFP(2 downto 0) is
503 when "011" | "101" | "110" => AddrOffset(0)(9 downto 6) <= x"8";
504 when "111" => AddrOffset(0)(9 downto 6) <= x"5";
505 when others => AddrOffset(0)(9 downto 6) <= x"0";
507 AddrOffset(1)(9 downto 6) <= x"0";
508 AddrOffset(2)(9 downto 6) <= x"a";
510 EventBufAddr(i) <= NXT_MonBuf(i)(9 downto 0) & AddrOffset(i)(9 downto 6);
516 if(sysclk'event and sysclk = '1')then
517 sysDIV2 <= not sysDIV2;
519 if(resetSyncRegs(2) = '1')then
522 elsif(EventData_we(i) = '1')then
523 header(i) <= EventData_in(i)(65) or (header(i) and not header_q(i));
524 header_q(i) <= header(i);
527 if(EnSFP(2 downto 1) = "00")then
528 SFP_we(0) <= EventData_we(0);
529 EoB(0) <= EventData_in(0)(64);
531 SFP_we(0) <= EventData_we(1) and EnSFP(0);
532 EoB(0) <= EventData_in(1)(64);
534 if(EnSFP(2 downto 0) = "110")then
535 SFP_we(1) <= EventData_we(1);
536 EoB(1) <= EventData_in(1)(64);
538 SFP_we(1) <= EventData_we(0) and EnSFP(1);
539 EoB(1) <= EventData_in(0)(64);
541 if(EnSFP(2 downto 0) = "111")then
542 SFP_we(2) <= EventData_we(2);
543 EoB(2) <= EventData_in(2)(64);
545 SFP_we(2) <= EventData_we(0) and EnSFP(2);
546 EoB(2) <= EventData_in(0)(64);
548 if(EnSFP(2 downto 0) = "001")then
549 LinkData(0) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
550 LinkCtrl(0) <= not(header(0) or EventData_in(0)(65));
551 LinkWe(0) <= EventData_we(0) and not EnSFP(3);
553 LinkData(0) <= EventData_in(1)(65) & EventData_in(1)(63 downto 0);
554 LinkCtrl(0) <= not(header(1) or EventData_in(1)(65));
555 LinkWe(0) <= EventData_we(1) and EnSFP(0) and not EnSFP(3);
557 if(EnSFP(2 downto 0) = "110")then
558 LinkData(1) <= EventData_in(1)(65) & EventData_in(1)(63 downto 0);
559 LinkCtrl(1) <= not(header(1) or EventData_in(1)(65));
560 LinkWe(1) <= EventData_we(1) and not EnSFP(3);
562 LinkData(1) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
563 LinkCtrl(1) <= not(header(0) or EventData_in(0)(65));
564 LinkWe(1) <= EventData_we(0) and EnSFP(1) and not EnSFP(3);
566 if(EnSFP(2 downto 0) = "111")then
567 LinkData(2) <= EventData_in(2)(65) & EventData_in(2)(63 downto 0);
568 LinkCtrl(2) <= not(header(2) or EventData_in(2)(65));
569 LinkWe(2) <= EventData_we(2) and not EnSFP(3);
571 LinkData(2) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
572 LinkCtrl(2) <= not(header(0) or EventData_in(0)(65));
573 LinkWe(2) <= EventData_we(0) and EnSFP(2) and not EnSFP(3);
575 case EnSFP(2 downto 0) is
576 when "010" | "011" | "111" => SFP2bldr_sel(0) <= "01";
577 when "100" | "101" | "110" => SFP2bldr_sel(0) <= "10";
578 when others => SFP2bldr_sel(0) <= "00";
580 case EnSFP(2 downto 0) is
581 when "010" | "011" | "101" | "111" => SFP2bldr_sel(1) <= "00";
582 when others => SFP2bldr_sel(1) <= "01";
584 case EnSFP(2 downto 0) is
585 when "100" | "110" => SFP2bldr_sel(2) <= "00";
586 when "101" => SFP2bldr_sel(2) <= "01";
587 when others => SFP2bldr_sel(2) <= "10";
589 evt_buf_full(0) <= (not LinkFull_n(conv_integer(SFP2bldr_sel(0))) and EnSFP(conv_integer(SFP2bldr_sel(0))) and not EnSFP(3)) or wport_FIFO_full(0);
590 if(SFP2bldr_sel(1)(0) = '0')then
591 evt_buf_full(1) <= (not LinkFull_n(0) and EnSFP(0) and not EnSFP(3)) or wport_FIFO_full(1);
593 evt_buf_full(1) <= (not LinkFull_n(1) and EnSFP(1) and not EnSFP(3)) or wport_FIFO_full(1);
595 evt_buf_full(2) <= (not LinkFull_n(conv_integer(SFP2bldr_sel(2))) and EnSFP(conv_integer(SFP2bldr_sel(2))) and not EnSFP(3)) or wport_FIFO_full(2);
598 process(txusrclk,rstCntr)
600 if(rstCntr = '1')then
601 sync_loss_cntr <= (others => (others => '0'));
602 elsif(txusrclk'event and txusrclk = '1')then
604 if(sync_loss(i) = '1')then
605 sync_loss_cntr(i) <= sync_loss_cntr(i) + 1;
610 process(sysclk,rstCntr)
612 if(rstCntr = '1')then
613 cmsCRC_errCntr <= (others => (others => '0'));
614 EvtLength_errCntr <= (others => (others => '0'));
615 AMCLength_errCntr <= (others => (others => '0'));
616 AMCvalid_errCntr <= (others => (others => '0'));
617 AMCcrc_errCntr <= (others => (others => '0'));
618 StopOverWrite <= '0';
619 elsif(sysclk'event and sysclk = '1')then
621 if(inc_err(i)(0) = '1')then
622 cmsCRC_errCntr(i) <= cmsCRC_errCntr(i) + 1;
624 if(inc_err(i)(1) = '1')then
625 EvtLength_errCntr(i) <= EvtLength_errCntr(i) + 1;
627 if(inc_err(i)(2) = '1')then
628 AMClength_errCntr(i) <= AMClength_errCntr(i) + 1;
630 if(inc_err(i)(3) = '1')then
631 AMCvalid_errCntr(i) <= AMCvalid_errCntr(i) + 1;
633 if(inc_err(i)(4) = '1')then
634 AMCcrc_errCntr(i) <= AMCcrc_errCntr(i) + 1;
638 StopOverWrite <= '1';
644 reset => resetSyncRegs
(2),
646 cmsCRC_err => cmsCRC_err,
647 EventData_in => EventData_in ,
648 EventData_we => EventData_we ,
654 if(ipb_clk'event and ipb_clk = '1')then
655 if(ipb_addr(15 downto 7) = LSC_addr(15 downto 7) and ipb_addr(6 downto 0) = "1110001" and ipb_write = '1' and ipb_strobe = '1')then
656 en_stop <= ipb_wdata(4 downto 0);
662 if(ipb_addr(15 downto 7) = LSC_addr(15 downto 7))then
663 case ipb_addr(6 downto 4) is
665 ipb_rdata <= DaqLSC_status(0)(31 downto 0);
667 ipb_rdata <= DaqLSC_status(1)(31 downto 0);
669 ipb_rdata <= DaqLSC_status(2)(31 downto 0);
671 case ipb_addr(3 downto 0) is
672 when x"0" => ipb_rdata <= sync_loss_cntr(0);
673 when x"1" => ipb_rdata <= sync_loss_cntr(1);
674 when x"2" => ipb_rdata <= sync_loss_cntr(2);
675 when x"3" => ipb_rdata <= cmsCRC_errCntr(0);
676 when x"4" => ipb_rdata <= cmsCRC_errCntr(1);
677 when x"5" => ipb_rdata <= cmsCRC_errCntr(2);
678 when x"6" => ipb_rdata <= EvtLength_errCntr(0);
679 when x"7" => ipb_rdata <= EvtLength_errCntr(1);
680 when x"8" => ipb_rdata <= EvtLength_errCntr(2);
681 when x"a" => ipb_rdata <= TotalEvtLengthCntr(0)(31 downto 0);
682 when x"b" => ipb_rdata <= x"00" & TotalEvtLengthCntr(0)(55 downto 32);
683 when x"c" => ipb_rdata <= TotalEvtLengthCntr(1)(31 downto 0);
684 when x"d" => ipb_rdata <= x"00" & TotalEvtLengthCntr(1)(55 downto 32);
685 when x"e" => ipb_rdata <= TotalEvtLengthCntr(2)(31 downto 0);
686 when x"f" => ipb_rdata <= x"00" & TotalEvtLengthCntr(2)(55 downto 32);
687 when others => ipb_rdata <= (others => '0');
690 case ipb_addr(3 downto 0) is
691 when x"0" => ipb_rdata <= SFP_evt_cntr(0);
692 when x"1" => ipb_rdata <= SFP_evt_cntr(1);
693 when x"2" => ipb_rdata <= SFP_evt_cntr(2);
694 when x"4" => ipb_rdata <= SFP_word_cntr(0);
695 when x"5" => ipb_rdata <= SFP_word_cntr(1);
696 when x"6" => ipb_rdata <= SFP_word_cntr(2);
697 when x"8" => ipb_rdata <= SFP_blk_cntr(0);
698 when x"9" => ipb_rdata <= SFP_blk_cntr(1);
699 when x"a" => ipb_rdata <= SFP_blk_cntr(2);
700 when others => ipb_rdata <= (others => '0');
703 case ipb_addr(3 downto 0) is
704 when x"0" => ipb_rdata <= "00000" & Written_MonBuf(1) & "00000" & Written_MonBuf(0);
705 when x"1" => ipb_rdata <= "00000" & Written_MonBuf(3) & "00000" & Written_MonBuf(2);
706 when x"2" => ipb_rdata <= "00000" & NXT_MonBuf(1) & "00000" & NXT_MonBuf(0);
707 when x"3" => ipb_rdata <= "00000" & MonBuf_wa & "00000" & NXT_MonBuf(2);
708 when x"4" => ipb_rdata <= x"00" & '0' & header & '0' & LinkFull & '0' & ReadBusy & '0' & evt_data_rdy & '0' & wport_FIFO_full & '0' & wport_rdy;
709 when x"5" => ipb_rdata <= event_cntr(0);
710 when x"6" => ipb_rdata <= event_cntr(1);
711 when x"7" => ipb_rdata <= event_cntr(2);
712 when x"8" => ipb_rdata <= word_cntr(0);
713 when x"9" => ipb_rdata <= word_cntr(1);
714 when x"a" => ipb_rdata <= word_cntr(2);
715 when x"b" => ipb_rdata <= EventBufAddr_we_cntr(0);
716 when x"c" => ipb_rdata <= EventBufAddr_we_cntr(1);
717 when x"d" => ipb_rdata <= EventBufAddr_we_cntr(2);
718 when others => ipb_rdata <= (others => '0');
721 case ipb_addr(3 downto 0) is
722 when x"0" => ipb_rdata <= AMClength_errCntr(0);
723 when x"1" => ipb_rdata <= AMClength_errCntr(1);
724 when x"2" => ipb_rdata <= AMClength_errCntr(2);
725 when x"4" => ipb_rdata <= AMCvalid_errCntr(0);
726 when x"5" => ipb_rdata <= AMCvalid_errCntr(1);
727 when x"6" => ipb_rdata <= AMCvalid_errCntr(2);
728 when x"8" => ipb_rdata <= AMCcrc_errCntr(0);
729 when x"9" => ipb_rdata <= AMCcrc_errCntr(1);
730 when x"a" => ipb_rdata <= AMCcrc_errCntr(2);
731 when others => ipb_rdata <= (others => '0');
734 case ipb_addr(3 downto 0) is
735 when x"0" => ipb_rdata <= x"000000" & "000" & en_stop;
736 when x"1" => ipb_rdata <= "000" & FirstBlkAddr_ra(1)(1) & "000" & FirstBlkAddr_ra(0)(1) & "000" & FirstBlkAddr_ra(1)(0) & "000" & FirstBlkAddr_ra(0)(0);
737 when x"2" => ipb_rdata <= x"00" & "000" & FirstBlkAddr_wa & "000" & FirstBlkAddr_ra(1)(2) & "000" & FirstBlkAddr_ra(0)(2);
738 when x"3" => ipb_rdata <= x"0" & FirstBlkAddrDo(1)(0) & x"0" & FirstBlkAddrDo(0)(0);
739 when x"4" => ipb_rdata <= x"0" & FirstBlkAddrDo(1)(1) & x"0" & FirstBlkAddrDo(0)(1);
740 when x"5" => ipb_rdata <= x"0" & FirstBlkAddrDo(1)(2) & x"0" & FirstBlkAddrDo(0)(2);
741 when x"6" => ipb_rdata <= x"0000" & '0' & MonEvtQueued & '0' & WrtMonEvtDone_l & '0' & FirstBlkAddrDoValid(1) & '0' & FirstBlkAddrDoValid(0);
742 when x"7" => ipb_rdata <= x"00" & WrtMonEvtDoneCntr(2) & WrtMonEvtDoneCntr(1) & WrtMonEvtDoneCntr(0);
743 when others => ipb_rdata <= (others => '0');
747 ipb_rdata <= (others => '0');
750 g_cmsCRC : for i in 0 to 2 generate
754 crc_init => cmsCRC_init
(i
),
755 trailer => LinkData
(i
)(64),
756 crc_d => LinkData
(i
)(63 downto 0),
759 crc_err => cmsCRC_err
(i
),
766 if(sysclk'event and sysclk = '1')then
767 if(resetSyncRegs(2) = '1')then
768 cmsCRC_initp <= "000";
769 cmsCRC_init <= "111";
770 SFP_blk_cntr <= (others => (others => '0'));
771 SFP_evt_cntr <= (others => (others => '0'));
772 SFP_word_cntr <= (others => (others => '0'));
773 event_cntr <= (others => (others => '0'));
774 word_cntr <= (others => (others => '0'));
775 EventBufAddr_we_cntr <= (others => (others => '0'));
776 TotalEvtLengthCntr <= (others => (others => '0'));
777 TotalEvtLengthCntr24q <= "000";
780 cmsCRC_initp(i) <= LinkData(i)(64) and LinkWe(i);
781 if(LinkWe(i) = '1')then
782 word_cntr(i) <= word_cntr(i) + 1;
784 if(LinkWe(i) = '1' and LinkData(i)(64) = '1')then
785 event_cntr(i) <= event_cntr(i) + 1;
787 if(SFP_we(i) = '1' and EoB(i) = '1')then
788 SFP_blk_cntr(i) <= SFP_blk_cntr(i) + 1;
790 if(SFP_we(i) = '1' and LinkData(i)(64) = '1')then
791 SFP_evt_cntr(i) <= SFP_evt_cntr(i) + 1;
793 if(SFP_we(i) = '1')then
794 SFP_word_cntr(i) <= SFP_word_cntr(i) + 1;
796 if(EventBufAddr_we_i(i) = '1')then
797 EventBufAddr_we_cntr(i) <= EventBufAddr_we_cntr(i) + 1;
799 if(EventData_we(i) = '1')then
800 if(EventData_in(i)(65) = '1')then
801 TotalEvtLengthCntr(i)(24 downto 0) <= TotalEvtLengthCntr(i)(24 downto 0) + ('0' & EventData_in(i)(55 downto 32));
804 TotalEvtLengthCntr24q(i) <= TotalEvtLengthCntr(i)(24);
805 if(TotalEvtLengthCntr24q(i) = '1' and TotalEvtLengthCntr(i)(24) = '0')then
806 TotalEvtLengthCntr(i)(55 downto 25) <= TotalEvtLengthCntr(i)(55 downto 25) + 1;
809 cmsCRC_init <= cmsCRC_initp;