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 (1 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;
90 ipb_addr : in (31 downto 0);
91 ipb_wdata : in (31 downto 0);
92 ipb_rdata : out (31 downto 0);
99 Port ( sys_reset :
in ;
-- active high reset of all logic but GTX
101 sfp_pd :
in array2x2;
103 LinkWe :
in (
1 downto 0);
104 LinkCtrl :
in (
1 downto 0);
105 LinkData :
in array2x64;
106 srcID :
in array2x16;
107 LinkDown :
out (
1 downto 0);
108 LinkFull :
out (
1 downto 0);
110 sync_loss :
out (
1 downto 0);
-- goes to '1' (rxusrclk) when SERDES is out of synch
111 status_ce :
in (
1 downto 0);
-- not implemented yet
112 status_addr :
in (
15 downto 0);
-- not implemented yet
113 status_port :
out array2x64;
-- first 32 bits are hard-wired
115 txusrclk_o :
out ;
-- reconstructed tx clock, to be used to clock sending circuitry
116 rxusrclk_o :
out ;
-- reconstructed rx clock, to be used to clock receiving circuitry
118 gtx_reset :
in ;
-- full reset of GTX only
119 gtx_refclk_p :
in ;
-- iob for refclk neg
120 gtx_refclk_n :
in ;
-- iob for refclk neg
121 sfp_rxn :
in (
1 downto 0);
-- sfp iobs
122 sfp_rxp :
in (
1 downto 0);
123 sfp_txn :
out (
1 downto 0);
124 sfp_txp :
out (
1 downto 0)
133 crc_d :
IN (
63 downto 0);
135 crc :
OUT (
15 downto 0);
137 dout :
OUT (
63 downto 0);
145 en_stop :
IN (
4 downto 0);
146 cmsCRC_err :
IN (
2 downto 0);
147 EventData_in :
IN array3X67;
148 EventData_we :
IN (
2 downto 0);
149 inc_err :
OUT array3X5;
153 function A_GT_B (A, B : (
10 downto 0))
return is
154 variable tmp : (10 downto 0);
157 if(tmp(10) = '0' and or_reduce(tmp(9 downto 0)) = '1')then
163 function A_GE_B (A, B : (
10 downto 0))
return is
164 variable tmp : (10 downto 0);
167 if(tmp(10) = '0')then
173 signal resetSyncRegs : (2 downto 0) := (others => '0');
174 signal daq_resetSyncRegs : (2 downto 0) := (others => '0');
175 signal inc_ddr_paSyncRegs : (3 downto 0) := (others => '0');
176 signal bldr2SFP_sel : array3X2 := (others => (others => '0'));
177 signal SFP2bldr_sel : array3X2 := (others => (others => '0'));
178 signal EventBufAddr_we_i : (2 downto 0) := (others => '0');
179 signal ReadBusy : (1 downto 0) := (others => '0');
180 signal sysDIV2 : := '0';
181 signal MonBuf_wa : (10 downto 0) := (others => '0');
182 signal MonBuf_ra : (10 downto 0) := (others => '0');
183 signal MonBufUsed : (9 downto 0) := (others => '0');
184 signal NXT_MonBuf : array3X11 := (others => (others => '0'));
185 signal Written_MonBuf : array4X11 := (others => (others => '0'));
186 signal Written_MonBufMatch : (2 downto 0) := (others => '0');
187 signal AddrOffset : array3X10 := (others => (others => '0'));
188 signal header : (1 downto 0) := (others => '0');
189 signal header_q : (1 downto 0) := (others => '0');
190 signal sfp_rxn : (1 downto 0) := (others => '0');
191 signal sfp_rxp : (1 downto 0) := (others => '0');
192 signal sfp_txn : (1 downto 0) := (others => '0');
193 signal sfp_txp : (1 downto 0) := (others => '0');
194 signal sync_loss : (1 downto 0) := (others => '0');
195 signal LinkFull_n : (1 downto 0) := (others => '0');
196 signal LinkFull : (2 downto 0) := (others => '0');
197 signal LinkCtrl : (1 downto 0) := (others => '0');
198 signal LinkWe : (1 downto 0) := (others => '0');
199 signal LinkDown : (1 downto 0) := (others => '0');
200 signal DaqLSC_status : array2x64 := (others => (others => '0'));
201 signal LinkData : array2x65 := (others => (others => '0'));
202 signal sync_loss_cntr : array2x32 := (others => (others => '0'));
203 signal SFP_we : (1 downto 0) := (others => '0');
204 signal EoB : (1 downto 0) := (others => '0');
205 signal SFP_evt_cntr : array2X32 := (others => (others => '0'));
206 signal SFP_blk_cntr : array2X32 := (others => (others => '0'));
207 signal SFP_word_cntr : array2X32 := (others => (others => '0'));
208 signal event_cntr : array2x32 := (others => (others => '0'));
209 signal word_cntr : array2x32 := (others => (others => '0'));
210 signal EventBufAddr_we_cntr : array2x32 := (others => (others => '0'));
211 signal src_ID : array2x16 := (others => (others => '0'));
212 signal txusrclk : := '0';
213 signal LinkDatap : array2x64 := (others => (others => '0'));
214 signal sfp_pd : array2x2 := (others => (others => '0'));
215 signal chk_MonBuf_avl : := '0';
216 signal FirstBlkAddrDo : array2x3x12 := (others => (others => (others => '0')));
217 signal FirstBlkAddr_ra : array2x3x5 := (others => (others => (others => '0')));
218 signal FirstBlkAddr_re : array2X3 := (others => (others => '0'));
219 signal WrtMonEvtDone_l : (2 downto 0) := (others => '0');
220 signal MonEvtQueued : (2 downto 0) := (others => '0');
221 signal FirstBlkAddrDoValid : array2X3 := (others => (others => '0'));
222 signal FirstBlkAddr_wa : (4 downto 0) := (others => '0');
223 signal FirstBlkAddrDi : (11 downto 0) := (others => '0');
224 signal FirstBlkAddr_we : := '0';
225 signal MonBuf_full : := '0';
226 signal mon_evt_cnt_i : (10 downto 0) := (others => '0');
227 signal status_addr : (15 downto 0) := (others => '0');
228 signal cmsCRC_initp : (2 downto 0) := (others => '0');
229 signal cmsCRC_init : (2 downto 0) := (others => '0');
230 signal cmsCRC_err : (2 downto 0) := (others => '0');
231 signal cmsCRC_errCntr : array3X32 := (others => (others => '0'));
232 signal TotalEvtLengthCntr24q : (2 downto 0) := (others => '0');
233 signal EvtLength_errCntr : array3X32 := (others => (others => '0'));
234 signal AMClength_errCntr : array3X32 := (others => (others => '0'));
235 signal AMCvalid_errCntr : array3X32 := (others => (others => '0'));
236 signal AMCcrc_errCntr : array3X32 := (others => (others => '0'));
237 signal TotalEvtLengthCntr : array3X56 := (others => (others => '0'));
238 signal StopOverWrite : := '0';
239 signal inc_err : array3x5 := (others => (others => '0'));
240 signal en_stop : (4 downto 0) := (others => '1');
241 signal stop : := '0';
242 component chipscope1
is
245 Din :
in (
303 downto 0));
247 signal cs : (303 downto 0) := (others => '0');
250 EventBufAddr_we <= EventBufAddr_we_i;
251 mon_evt_cnt(31 downto 11) <= (others => '0');
252 mon_evt_cnt(10 downto 0) <= mon_evt_cnt_i;
254 sfp_pd(0) <= "00" when Dis_pd = '1' or SFP_ABS(0) = '0' else "11";
255 sfp_pd(1) <= "00" when Dis_pd = '1' or SFP_ABS(1) = '0' else "11";
256 EventBufAddr_we(2) <= '0';
257 EventBufAddr(2) <= (others => '0');
258 evt_buf_full(2) <= '1';
259 EventData_re(2) <= '0';
261 SFP_down(1) <= not LinkDown(1) and not enSFP(3) and enSFP(1);
262 SFP_down(0) <= not LinkDown(0) and not enSFP(3) and enSFP(0);
264 LinkFull(1) <= not LinkFull_n(1) and not enSFP(3) and enSFP(1);
265 LinkFull(0) <= not LinkFull_n(0) and not enSFP(3) and enSFP(0);
267 sys_reset => daq_resetSyncRegs
(2),
272 LinkCtrl => LinkCtrl,
273 LinkData => LinkDatap,
275 LinkDown => LinkDown,
276 LinkFull => LinkFull_n,
277 sync_loss => sync_loss,
279 status_addr => status_addr ,
280 status_port => DaqLSC_status ,
281 txusrclk_o => txusrclk,
283 gtx_reset => gtx_reset,
284 gtx_refclk_p => SFP_REFCLK_P ,
285 gtx_refclk_n => SFP_REFCLK_N ,
291 status_addr <= x"000" & ipb_addr(3 downto 0);
292 LinkDatap(0) <= LinkData(0)(63 downto 0);
293 LinkDatap(1) <= LinkData(1)(63 downto 0);
294 src_ID(0) <= LSC_ID(15 downto 2) & "00";
295 src_ID(1) <= LSC_ID(15 downto 2) & "01";
296 sfp_rxn(0) <= SFP0_RXN;
297 sfp_rxp(0) <= SFP0_RXP;
298 SFP0_TXN <= sfp_txn(0);
299 SFP0_TXP <= sfp_txp(0);
300 sfp_rxn(1) <= SFP1_RXN;
301 sfp_rxp(1) <= SFP1_RXP;
302 SFP1_TXN <= sfp_txn(1);
303 SFP1_TXP <= sfp_txp(1);
304 process(sysclk,daq_reset)
306 if(daq_reset = '1')then
307 daq_resetSyncRegs <= (others => '1');
308 elsif(sysclk'event and sysclk = '1')then
309 daq_resetSyncRegs <= daq_resetSyncRegs(1 downto 0) & '0';
312 process(sysclk,reset)
315 resetSyncRegs <= (others => '1');
316 elsif(sysclk'event and sysclk = '1')then
317 resetSyncRegs <= resetSyncRegs(1 downto 0) & '0';
320 g_FirstBlkAddr: for j in 0 to 1 generate
321 g1_FirstBlkAddr: for i in 0 to 5 generate
322 i_FirstBlkAddr : RAM32M
324 DOA => FirstBlkAddrDo
(j
)(0)(i*2+1
downto i*2
),
-- Read port A 2-bit output
325 DOB => FirstBlkAddrDo
(j
)(1)(i*2+1
downto i*2
),
-- Read port B 2-bit output
326 DOC => FirstBlkAddrDo
(j
)(2)(i*2+1
downto i*2
),
-- Read port C 2-bit output
327 DOD =>
open,
-- Read/Write port D 2-bit output
328 ADDRA => FirstBlkAddr_ra
(j
)(0),
-- Read port A 5-bit address input
329 ADDRB => FirstBlkAddr_ra
(j
)(1),
-- Read port B 5-bit address input
330 ADDRC => FirstBlkAddr_ra
(j
)(2),
-- Read port C 5-bit address input
331 ADDRD => FirstBlkAddr_wa,
-- Read/Write port D 5-bit address input
332 DIA => FirstBlkAddrDi
(i*2+1
downto i*2
),
-- RAM 2-bit data write input addressed by ADDRD,
333 -- read addressed by ADDRA
334 DIB => FirstBlkAddrDi
(i*2+1
downto i*2
),
-- RAM 2-bit data write input addressed by ADDRD,
335 -- read addressed by ADDRB
336 DIC => FirstBlkAddrDi
(i*2+1
downto i*2
),
-- RAM 2-bit data write input addressed by ADDRD,
337 -- read addressed by ADDRC
338 DID => "
00",
-- RAM 2-bit data write input addressed by ADDRD,
339 -- read addressed by ADDRD
340 WCLK => sysclk,
-- Write clock input
341 WE => FirstBlkAddr_we
-- Write enable input
345 FirstBlkAddrDi <= '0' & MonBuf_wa;
348 if(sysclk'event and sysclk = '1')then
349 if(resetSyncRegs(2) = '1')then
350 chk_MonBuf_avl <= '1';
351 elsif(buf_rqst(0) = '1')then
352 chk_MonBuf_avl <= buf_rqst(3);
354 if(resetSyncRegs(2) = '1')then
356 elsif(WaitMonBuf = '1' or MonBufOverWrite = '1')then
357 if((MonBuf_wa(10) /= MonBuf_ra(10) and MonBuf_wa(9 downto 0) = MonBuf_ra(9 downto 0)))then
362 elsif(chk_MonBuf_avl = '1')then
363 if(MonBufUsed(9 downto 8) = "11")then
369 if(MonBufOverWrite = '1')then
370 mon_evt_cnt_i <= '0' & Written_MonBuf(3)(9 downto 0);
372 mon_evt_cnt_i <= Written_MonBuf(3) - MonBuf_ra;
374 if(MonBufOverWrite = '0')then
375 MonBuf_empty <= not or_reduce(mon_evt_cnt_i);
376 elsif(Written_MonBuf(3) /= MonBuf_ra or MonBuf_full = '1')then
381 if(resetSyncRegs(2) = '1')then
382 ReadBusy <= (others => '0');
383 EventData_re <= (others => '0');
384 EventBufAddr_we_i <= (others => '0');
385 MonBuf_wa <= (others => '0');
386 MonBuf_ra <= (others => '0');
387 MonBufUsed <= (others => '0');
388 Written_MonBufMatch <= (others => '1');
389 Written_MonBuf <= (others => (others => '0'));
390 NXT_MonBuf <= (others => (others => '0'));
391 inc_ddr_paSyncRegs <= (others => '0');
392 FirstBlkAddr_we <= '0';
393 FirstBlkAddr_re <= (others => (others => '0'));
394 FirstBlkAddrDoValid <= (others => (others => '0'));
395 WrtMonEvtDone_l <= (others => '0');
396 MonEvtQueued <= (others => '0');
397 FirstBlkAddr_wa <= (others => '0');
398 FirstBlkAddr_ra <= (others => (others => (others => '0')));
402 if(EVENTdata_in(i)(64) = '1' and EVENTdata_we(i) = '1')then
404 elsif(evt_data_rdy(i) = '1' and wport_rdy(i) = '1')then
407 EventData_re(i) <= evt_data_rdy(i) and wport_rdy(i) and not ReadBusy(i);
408 if(EventData_in(i)(66) = '0' and evt_data_rdy(i) = '1' and wport_rdy(i) = '1' and ReadBusy(i) = '0')then
409 EventBufAddr_we_i(i) <= '1';
411 EventBufAddr_we_i(i) <= '0';
416 if(FirstBlkAddr_re(j)(i) = '1')then
417 FirstBlkAddr_ra(j)(i) <= FirstBlkAddr_ra(j)(i) + 1;
419 if(FirstBlkAddr_ra(j)(i) = FirstBlkAddr_wa)then
420 FirstBlkAddrDoValid(j)(i) <= '0';
422 FirstBlkAddrDoValid(j)(i) <= '1';
426 if(FirstBlkAddr_we = '1')then
427 FirstBlkAddr_wa <= FirstBlkAddr_wa + 1;
430 if(WrtMonEvtDone(i) = '1')then
431 WrtMonEvtDone_l(i) <= '1';
432 elsif(FirstBlkAddrDoValid(0)(i) = '1')then
433 WrtMonEvtDone_l(i) <= '0';
435 FirstBlkAddr_re(0)(i) <= FirstBlkAddrDoValid(0)(i) and WrtMonEvtDone_l(i);
436 if(EventData_we(i) = '1' and EventData_in(i)(66 downto 65) = "01")then
437 MonEvtQueued(i) <= '1';
438 elsif(FirstBlkAddrDoValid(1)(i) = '1')then
439 MonEvtQueued(i) <= '0';
441 FirstBlkAddr_re(1)(i) <= FirstBlkAddrDoValid(1)(i) and MonEvtQueued(i);
443 FirstBlkAddr_we <= buf_rqst(3) and buf_rqst(0);
444 if(MonBufOverWrite = '1' and Written_MonBuf(3)(10) = '1')then
447 if(buf_rqst(0) = '1')then
448 MonBuf_wa <= MonBuf_wa + 1;
450 MonBufUsed <= MonBuf_wa(9 downto 0) - MonBuf_ra(9 downto 0);
451 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
452 MonBuf_ra <= MonBuf_ra + 1;
454 if(Written_MonBuf(0) = Written_MonBuf(3) and WrtMonEvtDone_l(0) = '0')then
455 Written_MonBufMatch(0) <= '1';
457 Written_MonBufMatch(0) <= '0';
459 if(EnSFP(1 downto 0) = "11" and Written_MonBuf(1) = Written_MonBuf(3) and WrtMonEvtDone_l(1) = '0')then
460 Written_MonBufMatch(1) <= '1';
462 Written_MonBufMatch(1) <= '0';
464 Written_MonBufMatch(2) <= '0';
465 if(Written_MonBufMatch = "000" and sysDIV2 = '0')then
466 Written_MonBuf(3) <= Written_MonBuf(3) + 1;
469 if(FirstBlkAddr_re(0)(i) = '1')then
470 Written_MonBuf(i) <= FirstBlkAddrDo(0)(i)(10 downto 0);
471 elsif(WrtMonBlkDone(i) = '1')then
472 Written_MonBuf(i) <= Written_MonBuf(i) + 1;
474 if(FirstBlkAddr_re(1)(i) = '1')then
475 NXT_MonBuf(i) <= FirstBlkAddrDo(1)(i)(10 downto 0);
476 elsif(EventBufAddr_we_i(i) = '1' and EventData_in(i)(66) = '0')then
477 NXT_MonBuf(i) <= NXT_MonBuf(i) + 1;
480 inc_ddr_paSyncRegs <= inc_ddr_paSyncRegs(2 downto 0) & inc_ddr_pa;
482 case EnSFP(1 downto 0) is
483 when "11" => AddrOffset(0)(9 downto 6) <= x"8";
484 when others => AddrOffset(0)(9 downto 6) <= x"0";
486 AddrOffset(1)(9 downto 6) <= x"0";
488 EventBufAddr(i) <= NXT_MonBuf(i)(9 downto 0) & AddrOffset(i)(9 downto 6);
494 if(sysclk'event and sysclk = '1')then
495 sysDIV2 <= not sysDIV2;
497 if(resetSyncRegs(2) = '1')then
500 elsif(EventData_we(i) = '1')then
501 header(i) <= EventData_in(i)(65) or (header(i) and not header_q(i));
502 header_q(i) <= header(i);
505 if(EnSFP(1) = '0')then
506 SFP_we(0) <= EventData_we(0);
507 EoB(0) <= EventData_in(0)(64);
509 SFP_we(0) <= EventData_we(1) and EnSFP(0);
510 EoB(0) <= EventData_in(1)(64);
512 if(EnSFP(1 downto 0) = "10")then
513 SFP_we(1) <= EventData_we(1);
514 EoB(1) <= EventData_in(1)(64);
516 SFP_we(1) <= EventData_we(0) and EnSFP(1);
517 EoB(1) <= EventData_in(0)(64);
519 if(EnSFP(1 downto 0) = "01")then
520 LinkData(0) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
521 LinkCtrl(0) <= not(header(0) or EventData_in(0)(65));
522 LinkWe(0) <= EventData_we(0) and not EnSFP(3);
524 LinkData(0) <= EventData_in(1)(65) & EventData_in(1)(63 downto 0);
525 LinkCtrl(0) <= not(header(1) or EventData_in(1)(65));
526 LinkWe(0) <= EventData_we(1) and EnSFP(0) and not EnSFP(3);
528 LinkData(1) <= EventData_in(0)(65) & EventData_in(0)(63 downto 0);
529 LinkCtrl(1) <= not(header(0) or EventData_in(0)(65));
530 LinkWe(1) <= EventData_we(0) and EnSFP(1) and not EnSFP(3);
531 if(EnSFP(0) = '1')then
532 evt_buf_full(0) <= (not LinkFull_n(0) and not EnSFP(3)) or wport_FIFO_full(0);
534 evt_buf_full(0) <= (not LinkFull_n(1) and not EnSFP(3)) or wport_FIFO_full(0);
536 evt_buf_full(1) <= (not LinkFull_n(0) and not EnSFP(3)) or wport_FIFO_full(1);
539 process(txusrclk,rstCntr)
541 if(rstCntr = '1')then
542 sync_loss_cntr <= (others => (others => '0'));
543 elsif(txusrclk'event and txusrclk = '1')then
545 if(sync_loss(i) = '1')then
546 sync_loss_cntr(i) <= sync_loss_cntr(i) + 1;
551 process(sysclk,rstCntr)
553 if(rstCntr = '1')then
554 cmsCRC_errCntr <= (others => (others => '0'));
555 EvtLength_errCntr <= (others => (others => '0'));
556 AMCLength_errCntr <= (others => (others => '0'));
557 AMCvalid_errCntr <= (others => (others => '0'));
558 AMCcrc_errCntr <= (others => (others => '0'));
559 StopOverWrite <= '0';
560 elsif(sysclk'event and sysclk = '1')then
562 if(inc_err(i)(0) = '1')then
563 cmsCRC_errCntr(i) <= cmsCRC_errCntr(i) + 1;
565 if(inc_err(i)(1) = '1')then
566 EvtLength_errCntr(i) <= EvtLength_errCntr(i) + 1;
568 if(inc_err(i)(2) = '1')then
569 AMClength_errCntr(i) <= AMClength_errCntr(i) + 1;
571 if(inc_err(i)(3) = '1')then
572 AMCvalid_errCntr(i) <= AMCvalid_errCntr(i) + 1;
574 if(inc_err(i)(4) = '1')then
575 AMCcrc_errCntr(i) <= AMCcrc_errCntr(i) + 1;
579 StopOverWrite <= '1';
585 reset => resetSyncRegs
(2),
587 cmsCRC_err => cmsCRC_err,
588 EventData_in => EventData_in ,
589 EventData_we => EventData_we ,
595 if(ipb_clk'event and ipb_clk = '1')then
596 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
597 en_stop <= ipb_wdata(4 downto 0);
603 if(ipb_addr(15 downto 7) = LSC_addr(15 downto 7))then
604 case ipb_addr(6 downto 4) is
606 ipb_rdata <= DaqLSC_status(0)(31 downto 0);
608 ipb_rdata <= DaqLSC_status(1)(31 downto 0);
610 case ipb_addr(3 downto 0) is
611 when x"0" => ipb_rdata <= sync_loss_cntr(0);
612 when x"1" => ipb_rdata <= sync_loss_cntr(1);
613 when x"3" => ipb_rdata <= cmsCRC_errCntr(0);
614 when x"4" => ipb_rdata <= cmsCRC_errCntr(1);
615 when x"6" => ipb_rdata <= EvtLength_errCntr(0);
616 when x"7" => ipb_rdata <= EvtLength_errCntr(1);
617 when x"a" => ipb_rdata <= TotalEvtLengthCntr(0)(31 downto 0);
618 when x"b" => ipb_rdata <= x"00" & TotalEvtLengthCntr(0)(55 downto 32);
619 when x"c" => ipb_rdata <= TotalEvtLengthCntr(1)(31 downto 0);
620 when x"d" => ipb_rdata <= x"00" & TotalEvtLengthCntr(1)(55 downto 32);
621 when others => ipb_rdata <= (others => '0');
624 case ipb_addr(3 downto 0) is
625 when x"0" => ipb_rdata <= SFP_evt_cntr(0);
626 when x"1" => ipb_rdata <= SFP_evt_cntr(1);
627 when x"4" => ipb_rdata <= SFP_word_cntr(0);
628 when x"5" => ipb_rdata <= SFP_word_cntr(1);
629 when x"8" => ipb_rdata <= SFP_blk_cntr(0);
630 when x"9" => ipb_rdata <= SFP_blk_cntr(1);
631 when others => ipb_rdata <= (others => '0');
634 case ipb_addr(3 downto 0) is
635 when x"1" => ipb_rdata <= x"00000" & '0' & Written_MonBuf(3);
636 when x"2" => ipb_rdata <= "00000" & NXT_MonBuf(1) & "00000" & NXT_MonBuf(0);
637 when x"3" => ipb_rdata <= "00000" & MonBuf_wa & x"0000";
638 when x"4" => ipb_rdata <= x"00" & "00" & header & '0' & LinkFull & "00" & ReadBusy & '0' & evt_data_rdy & '0' & wport_FIFO_full & '0' & wport_rdy;
639 when x"5" => ipb_rdata <= event_cntr(0);
640 when x"6" => ipb_rdata <= event_cntr(1);
641 when x"8" => ipb_rdata <= word_cntr(0);
642 when x"9" => ipb_rdata <= word_cntr(1);
643 when x"b" => ipb_rdata <= EventBufAddr_we_cntr(0);
644 when x"c" => ipb_rdata <= EventBufAddr_we_cntr(1);
645 when others => ipb_rdata <= (others => '0');
648 case ipb_addr(3 downto 0) is
649 when x"0" => ipb_rdata <= AMClength_errCntr(0);
650 when x"1" => ipb_rdata <= AMClength_errCntr(1);
651 when x"4" => ipb_rdata <= AMCvalid_errCntr(0);
652 when x"5" => ipb_rdata <= AMCvalid_errCntr(1);
653 when x"8" => ipb_rdata <= AMCcrc_errCntr(0);
654 when x"9" => ipb_rdata <= AMCcrc_errCntr(1);
655 when others => ipb_rdata <= (others => '0');
658 case ipb_addr(3 downto 0) is
659 when x"0" => ipb_rdata <= x"000000" & "000" & en_stop;
660 when others => ipb_rdata <= (others => '0');
664 ipb_rdata <= (others => '0');
667 g_cmsCRC : for i in 0 to 1 generate
671 crc_init => cmsCRC_init
(i
),
672 trailer => LinkData
(i
)(64),
673 crc_d => LinkData
(i
)(63 downto 0),
676 crc_err => cmsCRC_err
(i
),
683 if(sysclk'event and sysclk = '1')then
684 if(resetSyncRegs(2) = '1')then
685 cmsCRC_initp <= "000";
686 cmsCRC_init <= "111";
687 SFP_blk_cntr <= (others => (others => '0'));
688 SFP_evt_cntr <= (others => (others => '0'));
689 SFP_word_cntr <= (others => (others => '0'));
690 event_cntr <= (others => (others => '0'));
691 word_cntr <= (others => (others => '0'));
692 EventBufAddr_we_cntr <= (others => (others => '0'));
693 TotalEvtLengthCntr <= (others => (others => '0'));
694 TotalEvtLengthCntr24q <= "000";
697 cmsCRC_initp(i) <= LinkData(i)(64) and LinkWe(i);
698 if(LinkWe(i) = '1')then
699 word_cntr(i) <= word_cntr(i) + 1;
701 if(LinkWe(i) = '1' and LinkData(i)(64) = '1')then
702 event_cntr(i) <= event_cntr(i) + 1;
704 if(SFP_we(i) = '1' and EoB(i) = '1')then
705 SFP_blk_cntr(i) <= SFP_blk_cntr(i) + 1;
707 if(SFP_we(i) = '1' and LinkData(i)(64) = '1')then
708 SFP_evt_cntr(i) <= SFP_evt_cntr(i) + 1;
710 if(SFP_we(i) = '1')then
711 SFP_word_cntr(i) <= SFP_word_cntr(i) + 1;
713 if(EventBufAddr_we_i(i) = '1')then
714 EventBufAddr_we_cntr(i) <= EventBufAddr_we_cntr(i) + 1;
716 if(EventData_we(i) = '1')then
717 if(EventData_in(i)(65) = '1')then
718 TotalEvtLengthCntr(i)(24 downto 0) <= TotalEvtLengthCntr(i)(24 downto 0) + ('0' & EventData_in(i)(55 downto 32));
721 TotalEvtLengthCntr24q(i) <= TotalEvtLengthCntr(i)(24);
722 if(TotalEvtLengthCntr24q(i) = '1' and TotalEvtLengthCntr(i)(24) = '0')then
723 TotalEvtLengthCntr(i)(55 downto 25) <= TotalEvtLengthCntr(i)(55 downto 25) + 1;
726 cmsCRC_init <= cmsCRC_initp;