1 ----------------------------------------------------------------------------------
5 -- Create Date: 15:
55:
15 07/09/2010
7 -- Module Name: AMC_if - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
18 ----------------------------------------------------------------------------------
20 use IEEE.STD_LOGIC_1164.
ALL;
21 use IEEE.STD_LOGIC_ARITH.
ALL;
22 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
23 use IEEE.std_logic_misc.
all;
26 -- Uncomment the following library declaration if using
27 -- arithmetic functions with or values
28 --use IEEE.NUMERIC_STD.ALL;
30 -- Uncomment the following library declaration if instantiating
31 -- any Xilinx primitives in this code.
33 use UNISIM.VComponents.
all;
35 use UNIMACRO.vcomponents.
all;
38 Generic (simulation : := false);
52 enSFP : IN (3 downto 0);
57 fake_length : in (19 downto 0);
58 T1_version : in (7 downto 0);
59 Source_ID : in array3x12;
60 AMC_en : in (11 downto 0);
61 AMC_Ready : out (11 downto 0);
62 BC0_lock : out (11 downto 0);
66 AMC_RXN : in (12 downto 1);
67 AMC_RXP : in (12 downto 1);
68 AMC_TXN : out (12 downto 1);
69 AMC_TXP : out (12 downto 1);
70 AMC_status : out (31 downto 0);
71 evt_data : out array3X67;
-- 66 is TCP/mon space,
65 is end_of_event
and 64 is end_of_block
72 evt_data_re : in (2 downto 0);
73 evt_buf_full : in (2 downto 0);
74 evt_data_we : out (2 downto 0);
75 evt_data_rdy : out (2 downto 0);
76 ddr_pa : in (9 downto 0);
78 mon_evt_wc : out (47 downto 0);
79 mon_ctrl : out (31 downto 0);
83 buf_rqst : out (3 downto 0);
87 ipb_addr : in (31 downto 0);
88 ipb_wdata : in (31 downto 0);
89 ipb_rdata : out (31 downto 0);
95 TTS_disable : in (11 downto 0);
96 ttc_evcnt_reset : in ;
97 event_number_avl : in ;
98 event_number : in (59 downto 0);
101 TrigData : out array12x8;
102 TTS_RQST : out (2 downto 0);
103 TTS_coded : out (4 downto 0)
119 fake_length :
in (
19 downto 0);
120 L1A_DATA :
IN (
15 downto 0);
124 empty_event_flag :
out ;
125 fake_DATA :
OUT (
15 downto 0);
130 generic(N : :=
14; simulation : := false);
-- M controls FIFO size, N controls timeout
141 AMC_ID :
IN (
3 downto 0);
142 txfsmresetdone :
in ;
145 rxcommaalignen :
out ;
147 RXDATA :
in (
15 downto 0);
148 RXCHARISCOMMA :
in (
1 downto 0);
149 RXCHARISK :
in (
1 downto 0);
150 RXNOTINTABLE :
in (
1 downto 0);
151 TXDATA :
out (
15 downto 0);
152 TXCHARISK :
out (
1 downto 0);
156 EventInfoRdDone :
IN ;
157 L1A_DATA :
IN (
15 downto 0);
161 fake_DATA :
IN (
15 downto 0);
164 Cntr_ADDR :
IN (
11 downto 0);
169 AMCinfo :
OUT (
15 downto 0);
170 EventInfo :
OUT (
31 downto 0);
171 EventInfo_dav :
OUT ;
172 AMC_DATA :
OUT (
63 downto 0);
175 Cntr_DATA :
OUT (
15 downto 0);
176 debug_out :
OUT (
255 downto 0);
177 TTC_status :
OUT (
127 downto 0);
178 TrigData :
OUT (
7 downto 0);
179 TTS_RQST :
OUT (
2 downto 0);
180 TTS_coded :
OUT (
4 downto 0)
189 AMC_en :
in (
11 downto 0);
190 RXDATA :
out array12X16;
191 RxBufOvf :
out (
11 downto 0);
192 RxBufUdf :
out (
11 downto 0);
195 RxClkRatio :
out array12x21;
196 rxprbserr :
out (
11 downto 0);
197 rxprbssel :
in array12X3;
198 RXNOTINTABLE :
out array12X2;
199 rxcommaalignen :
in (
11 downto 0);
200 rxchariscomma :
out array12X2;
201 rxcharisk :
out array12X2;
202 rxresetdone :
out (
11 downto 0);
203 txdiffctrl :
in array12X4;
204 TXDATA :
in array12X16;
205 txoutclk :
out (
11 downto 0);
206 txcharisk :
in array12X2;
207 txresetdone :
out (
11 downto 0);
208 txprbssel :
in array12X3;
209 qpll_lock :
out (
2 downto 0);
210 txfsmresetdone :
out (
11 downto 0);
211 rxfsmresetdone :
out (
11 downto 0);
212 data_valid :
in (
11 downto 0);
214 RXN :
in (
11 downto 0);
215 RXP :
in (
11 downto 0);
216 TXN :
out (
11 downto 0);
217 TXP :
out (
11 downto 0)
228 Source_ID :
IN (
7 downto 0);
229 block_wc :
in (
15 downto 0);
231 AMC_wc :
IN (
17 downto 0);
234 AMC_header :
IN (
65 downto 0);
236 AMC_DATA :
IN array12X64;
239 bldr_fifo_full :
OUT ;
240 AMC_DATA_re :
OUT (
11 downto 0);
241 AMCCRC_bad :
OUT (
11 downto 0);
242 evt_data :
OUT (
66 downto 0);
245 debug :
out (
255 downto 0);
257 AMC_if_data :
IN (
15 downto 0);
258 Cntr_DATA :
IN array12x16;
259 Cntr_ADDR :
OUT (
11 downto 0);
260 ipb_addr :
IN (
15 downto 0);
261 ipb_rdata :
OUT (
31 downto 0)
268 data_in :
IN (
63 downto 0);
271 crc :
OUT (
15 downto 0);
273 data_out :
OUT (
63 downto 0);
289 di :
IN (
5 downto 0);
291 wa :
IN (
4 downto 0);
292 ra :
IN (
4 downto 0);
293 do :
OUT (
5 downto 0)
299 di :
IN (
7 downto 0);
301 wa :
IN (
4 downto 0);
302 ra :
IN (
4 downto 0);
303 do :
OUT (
7 downto 0)
306 type array_x12y256 is array(11 downto 0) of (255 downto 0);
307 type array_x12y16 is array(11 downto 0) of (15 downto 0);
308 type array_x12y32 is array(11 downto 0) of (31 downto 0);
309 type array_x12y8 is array(11 downto 0) of (7 downto 0);
310 type array_x12y5 is array(11 downto 0) of (4 downto 0);
311 type array_x12y128 is array(11 downto 0) of (127 downto 0);
312 constant AMC_ID : array12x4 := (x"0",x"1",x"2",x"3",x"4",x"5",x"6",x"7",x"8",x"9",x"a",x"b");
313 constant AMC_txdiffctrl : array12x4 := (others => x"b");
314 constant uFOV : (3 downto 0) := x"1";
315 signal kAMC : array2x4 := (others => (others => '0'));
316 signal mAMC : array3x4 := (others => (others => '0'));
317 signal nAMC : array3x4 := (others => (others => '0'));
318 signal EventInfo : array_x12y32 := (others => (others => '0'));
319 signal AMCinfo : array12X16 := (others => (others => '0'));
320 signal AMC_DATA : array12X64 := (others => (others => '0'));
321 signal AMC_DATA1 : array12X64 := (others => (others => '0'));
322 signal AMC_DATA2 : array12X64 := (others => (others => '0'));
323 signal Cntr_DATA : array12x16 := (others => (others => '0'));
324 signal AMCCRC_bad : array3X12 := (others => (others => '0'));
325 signal AMC_TTS : array_x12y8 := (others => (others => '0'));
326 signal AMC_TTS_RQST : array12X3 := (others => (others => '0'));
327 signal AMC_debug : array_x12y256 := (others => (others => '0'));
328 signal TTC_status : array_x12y128 := (others => (others => '0'));
329 signal badEventCRC_cntr : array12X16 := (others => (others => '0'));
330 signal ReSyncFakeEvent_cntr : array12X16 := (others => (others => '0'));
331 signal EventInfo_dav : (11 downto 0);
332 --signal EventInfo_dav_n : (11 downto 0);
333 signal EventInfoRdDone : (12 downto 0) := (others => '0');
334 signal AMC_DATA_RdEn : (11 downto 0) := (others => '0');
335 signal Cntr_ADDR : (11 downto 0) := (others => '0');
336 signal AMC_if_ADDR : (7 downto 0) := (others => '0');
337 signal ipb_strobe_q : := '0';
338 signal UsrClk : := '0';
339 signal UsrClk_out : (11 downto 0) := (others => '0');
340 signal resetCntr_SyncRegs : (2 downto 0) := (others => '0');
341 signal resetSyncRegs : (2 downto 0) := (others => '0');
342 signal CntrRst : := '0';
343 signal rst_AMC_cntr : := '0';
344 signal evn_out : (59 downto 0) := (others => '0');
345 signal evn_wa : (8 downto 0) := (others => '0');
346 signal evn_ra : (8 downto 0) := (others => '0');
347 signal evt_cnt : array3x8 := (others => (others => '0'));
348 signal evn : (23 downto 0) := (others => '0');
349 signal CDF_in : (71 downto 0) := (others => '0');
350 signal CDF_out : (71 downto 0) := (others => '0');
351 signal CDF_wa : (8 downto 0) := (others => '0');
352 signal CDF_ra : (8 downto 0) := (others => '0');
353 signal CDF_cnt : (7 downto 0) := (others => '0');
354 signal empty_event_flag : := '0';
355 signal evn_buf_full_i : (2 downto 0) := (others => '0');
356 signal ovfl_warning_i : (3 downto 0) := (others => '0');
357 signal ovfl_warning_p : := '0';
358 signal header : := '0';
359 signal init_bldr : := '0';
360 signal CDF_header : := '0';
361 signal CDF_empty : := '0';
362 signal BlockHeader : := '0';
363 signal ec_sel_AMC : := '0';
364 signal sel_AMC : (3 downto 0) := (others => '0');
365 signal LastBlock : := '0';
366 signal FirstBlock : (2 downto 0) := (others => '0');
367 signal sel_CDF : := '0';
368 signal evn_empty : := '0';
369 signal sel_evn : (1 downto 0) := (others => '0');
370 signal L1A_WrEn : := '0';
371 signal L1A_DATA : (15 downto 0) := (others => '0');
372 signal EvtTy : (3 downto 0) := (others => '0');
373 signal CalTy : (3 downto 0) := (others => '0');
374 signal EventInfo_avl : := '0';
375 signal rst_init_bldr : := '0';
376 signal Builder_busy : (2 downto 0) := (others => '0');
377 signal ec_CDF_ra : := '0';
378 signal summary : (63 downto 0) := (others => '0');
379 signal AMC_TTC_status : (31 downto 0) := (others => '0');
380 signal fake_en: := '0';
381 signal fake_DATA : (15 downto 0) := (others => '0');
382 signal fake_header : := '0';
383 signal fake_CRC : := '0';
384 signal fake_WrEn : := '0';
385 signal fake_word_cnt : (15 downto 0) := (others => '0');
386 signal fake_evt_cnt : (15 downto 0) := (others => '0');
387 signal empty_evt_cnt : (15 downto 0) := (others => '0');
388 signal fake_header_cnt: (15 downto 0) := (others => '0');
389 signal EventBuilt : (2 downto 0) := (others => '0');
390 signal badEventCRCToggle : (11 downto 0) := (others => '0');
391 signal ReSyncFakeEventToggle : (11 downto 0) := (others => '0');
392 signal EventBuiltToggle : (2 downto 0) := (others => '0');
393 signal badEventCRCToggleSyncRegs : array12x4 := (others => (others => '0'));
394 signal ReSyncFakeEventToggleSyncRegs : array12x4 := (others => (others => '0'));
395 signal EventBuiltToggleSyncRegs : array3x4 := (others => (others => '0'));
396 signal EventBuiltCnt : array3x16 := (others => (others => '0'));
397 signal next_bldr : (1 downto 0) := (others => '0');
398 signal AMC_wcp : array12x13 := (others => (others => '0'));
399 signal AMC_wc : (17 downto 0) := (others => '0');
400 signal AMC_wc_we : (2 downto 0) := (others => '0');
401 signal en_block_wc : (2 downto 0) := (others => '0');
402 signal block_wc_we : (2 downto 0) := (others => '0');
403 signal AMC_wc_mask : (2 downto 0) := (others => '0');
404 signal AMC_header : array3x66 := (others => (others => '0'));
405 signal AMC_header_we : (2 downto 0) := (others => '0');
406 signal bldr_fifo_full : (2 downto 0) := (others => '0');
407 type array3X12 is array(0 to 2) of (11 downto 0);
408 signal AMC_DATA_re : array3X12 := (others => (others => '0'));
409 signal AMC_hasData : (11 downto 0) := (others =>'0');
410 signal Mbit_word : (11 downto 0) := (others =>'0');
411 --signal AMC_hasData_l : (11 downto 0) := (
others =>'0');
412 signal AMC_REFCLK : := '0';
413 signal AMC_TTS_OR : (7 downto 0) := (others =>'0');
414 signal AMC_TTS_RQST_OR : (2 downto 0) := (others =>'0');
415 signal AMC_qpll_lock : (2 downto 0) := (others =>'0');
416 signal AMC_rxprbserr : (11 downto 0) := (others =>'0');
417 signal AMC_rxcommaalignen : (11 downto 0) := (others =>'0');
418 signal AMC_rxresetdone : (11 downto 0) := (others =>'0');
419 signal AMC_txfsmresetdone : (11 downto 0) := (others =>'0');
420 signal AMC_rxfsmresetdone : (11 downto 0) := (others =>'0');
421 signal AMC_data_valid : (11 downto 0) := (others =>'0');
422 signal AMC_RXDATA : array12x16 := (others => (others => '0'));
423 signal AMC_TXDATA : array12x16 := (others => (others => '0'));
424 signal AMC_RXNOTINTABLE : array12x2 := (others => (others => '0'));
425 signal AMC_rxchariscomma : array12x2 := (others => (others => '0'));
426 signal AMC_rxcharisk : array12x2 := (others => (others => '0'));
427 signal AMC_txcharisk : array12x2 := (others => (others => '0'));
428 signal AMC_rxprbssel : array12x3 := (others => (others => '0'));
429 signal AMC_txprbssel : array12x3 := (others => (others => '0'));
430 type array3X4 is array(0 to 2) of (3 downto 0);
431 --signal AMC_rdata : array12x32 := (others => (others => '0'));
432 signal channel : array3X4 := (others => (others => '0'));
434 signal mon_wc: array3X16 := (others => (others => '0'));
435 signal mon_evt_wcp : (47 downto 0) := (others => '0');
436 signal zero_wc : (2 downto 0) := (others => '0');
437 signal more_wc : (2 downto 0) := (others => '0');
438 signal mon_en: := '0';
439 signal scale_cntr : (15 downto 0) := (others => '0');
440 signal ce_scale : := '0';
441 signal ld_scale : := '0';
442 --signal MonBufAbort: := '0';
443 signal rst_mon_wc: := '0';
444 signal ce_wc_reg_wa: := '0';
445 signal wc_reg_wa: (9 downto 0) := (others => '0');
446 --signal start_wc_reg_wa: (9 downto 0) := (
others => '0');
447 signal down_count : := '0';
448 signal mon_mask: (19 downto 0) := (others => '0');
449 signal sample_event: := '0';
450 signal scale : (31 downto 0) := (others => '0');
451 signal pending : := '0';
452 signal AMC_Ready_i : (11 downto 0);
453 signal AMC_OK : (11 downto 0);
454 signal block_num : (11 downto 0) := (others => '0');
455 signal resetFIFO : := '0';
456 signal fifo_rst : := '0';
457 signal fifo_en : := '0';
458 signal resetFIFO_AMC : := '0';
459 signal fifo_rst_AMC : := '0';
460 signal fifo_en_AMC : := '0';
461 signal OneSFP : := '0';
462 signal TwoSFP : := '0';
463 signal ThreeSFP : := '0';
464 signal fake_full : (11 downto 0) := (others => '0');
465 signal LinkFull : := '0';
466 signal EventInSlink : array3x4 := (others => (others => '0'));
467 signal TTS_FIFO_do : (7 downto 0) := (others => '0');
468 signal TTS_FIFO_di : (7 downto 0) := (others => '0');
469 signal TTS_FIFO_wa : (4 downto 0) := (others => '0');
470 signal TTS_FIFO_ra : (4 downto 0) := (others => '0');
471 signal TTS_FIFO_waSyncRegs : (2 downto 0) := (others => '0');
472 signal TTS_FIFO_waSyncRegs2 : (2 downto 0) := (others => '0');
473 signal TTS_FIFO_waSyncRegs3 : (2 downto 0) := (others => '0');
474 signal evt_bldr_debug : (255 DOWNTO 0);
475 signal stop_mon : := '0';
476 signal errors : (7 downto 0) := (others => '0');
477 signal err_TTS : (7 downto 0) := (others => '0');
478 signal AMC_wc_sum_we : := '0';
479 signal rst_AMC_wc_sum : := '0';
480 signal wr_AMC_wc_sum : := '0';
481 signal sel_AMC_q : (3 downto 0) := (others => '0');
482 signal AMC_wc_sum_di : (5 downto 0) := (others => '0');
483 signal AMC_wc_sum_do : (5 downto 0) := (others => '0');
484 signal AMC_wc_sum_a : (4 downto 0) := (others => '0');
485 signal enRstAMC_link : := '0';
486 signal RstAMC_link : := '0';
487 signal RstAMC_link_dl : := '0';
488 signal RstAMC_linkSync : (3 downto 0) := (others => '0');
489 signal AllEventBuilt_i : := '0';
490 signal event_number_avl_q : (2 downto 0) := (others => '0');
491 signal bcnt : (11 downto 0) := (others => '0');
492 signal event_cnt : (23 downto 0) := (others => '0');
493 signal event_status : (19 downto 0) := (others => '0');
494 signal L1A_buf_we : := '0';
495 signal L1A_buf_do : (31 downto 0) := (others => '0');
496 signal L1A_buf_di : (31 downto 0) := (others => '0');
497 signal L1A_buf_wa : (8 downto 0) := (others => '0');
498 signal RxBufUdfErr : (11 downto 0) := (others => '0');
499 signal RxBufOvfErr : (11 downto 0) := (others => '0');
500 signal RxBufOvf : (11 downto 0) := (others => '0');
501 signal RxBufUdf : (11 downto 0) := (others => '0');
502 signal RxClkCntr : (19 downto 0) := (others => '0');
503 signal RxClkCntr19_q : := '0';
504 signal updateRatio : := '0';
505 signal RxClkRatio : array12x21 := (others => (others => '0'));
506 signal AMC_if_RdEn : := '0';
507 signal AMC_if_data : (15 downto 0) := (others => '0');
508 signal AMC_cntr_data : (31 downto 0) := (others => '0');
509 signal strobe2ms : := '0';
510 signal Cntr2ms : (18 downto 0) := (others => '0');
513 CONTROL0 :
INOUT (
35 DOWNTO 0);
514 CONTROL1 :
INOUT (
35 DOWNTO 0));
517 component ila128x4096
519 CONTROL :
INOUT (
35 DOWNTO 0);
521 DATA :
IN (
143 DOWNTO 0);
522 TRIG0 :
IN (
7 DOWNTO 0);
523 TRIG1 :
IN (
7 DOWNTO 0);
524 TRIG2 :
IN (
7 DOWNTO 0));
527 signal CONTROL0 : (35 DOWNTO 0);
528 signal CONTROL1 : (35 DOWNTO 0);
529 signal DATA0 : (143 DOWNTO 0);
530 signal TRIG0 : (7 DOWNTO 0);
531 signal TRIG1 : (7 DOWNTO 0);
532 signal TRIG2 : (7 DOWNTO 0);
533 signal DATA1 : (143 DOWNTO 0);
534 signal TRIG0b : (7 DOWNTO 0);
535 signal TRIG1b : (7 DOWNTO 0);
536 signal TRIG2b : (7 DOWNTO 0);
540 Din :
in (
303 downto 0));
542 signal CS : (303 DOWNTO 0) := (others => '0');
544 --i_chipscope : chipscope1 port map(clk => UsrClk, Din => cs);
545 --cs(61 downto 0) <= AMC_debug(
3)(
61 downto 0);
546 --cs(289) <= AMC_debug(
3)(
44);
547 --cs(288) <= AMC_debug(
3)(
40);
548 --i_chipscope : chipscope1 port map(clk => UsrClk, Din => cs);
549 --cs(288) <= AMC_debug(
1)(
48);
550 --cs(48 downto 0) <= AMC_debug(
1)(
48 downto 0);
551 --cs(303 downto 296) <= cs(
212) & cs(
210 downto 204);
552 --cs(295 downto 288) <= cs(
147) & cs(
145 downto 139);
553 --cs(295 downto 288) <= AMC_debug(
0)(
80) & AMC_debug(
0)(
62 downto 56);
554 --cs(288) <= AMC_debug(
4)(
82);
555 --cs(287) <= sel_CDF;
556 --cs(264 downto 183) <= AMC_debug(
4)(
81 downto 0);
557 --cs(182 downto 0) <= evt_bldr_debug(
182 downto 0);
560 -- CONTROL0 => CONTROL0,
561 -- CONTROL1 => CONTROL1);
562 --i_ila : ila128x4096
564 -- CONTROL => CONTROL0,
570 --DATA0(3 downto 0) <= TTC_status(
10)(
84 downto 81);
571 --DATA0(16 downto 4) <= TTC_status(
10)(
18 downto 6);
572 --DATA0(44 downto 17) <= TTC_status(
10)(
118 downto 91);
573 --DATA0(46 downto 45) <= AMC_rxchariscomma(
10);
574 --DATA0(48 downto 47) <= AMC_rxcharisk(
10);
575 --DATA0(64 downto 49) <= AMC_RXDATA(
10);
576 --DATA0(66 downto 65) <= TTC_status(
10)(
53 downto 52);
577 --DATA0(70 downto 67) <= TTC_status(
9)(
84 downto 81);
578 --DATA0(83 downto 71) <= TTC_status(
9)(
18 downto 6);
579 --DATA0(85 downto 84) <= TTC_status(
9)(
53 downto 52);
580 --DATA0(87 downto 86) <= AMC_rxchariscomma(
9);
581 --DATA0(89 downto 88) <= AMC_rxcharisk(
9);
582 --DATA0(105 downto 90) <= AMC_RXDATA(
9);
583 --DATA0(109 downto 106) <= TTC_status(
1)(
84 downto 81);
584 --DATA0(122 downto 110) <= TTC_status(
1)(
18 downto 6);
585 --DATA0(124 downto 123) <= TTC_status(
1)(
53 downto 52);
586 --DATA0(125) <= AMC_rxchariscomma(
1)(
0);
587 --DATA0(127 downto 126) <= AMC_rxcharisk(
1);
588 --DATA0(143 downto 128) <= AMC_RXDATA(
1);
589 --TRIG0(1 downto 0) <= TTC_status(
10)(
53 downto 52) ;
590 --TRIG0(3 downto 2) <= TTC_status(
9)(
53 downto 52) ;
591 --TRIG0(5 downto 4) <= TTC_status(
1)(
53 downto 52) ;
592 --TRIG0(7 downto 6) <= "
00" ;
593 --i_ila_b : ila128x4096
595 -- CONTROL => CONTROL1,
602 --DATA1(9 downto 1) <= TTC_status(
10)(
35 downto 27);
603 --DATA1(46 downto 10) <= TTC_status(
10)(
90 downto 54);
604 --DATA1(55 downto 47) <= TTC_status(
9)(
35 downto 27);
605 --DATA1(92 downto 56) <= TTC_status(
9)(
90 downto 54);
606 --DATA1(101 downto 93) <= TTC_status(
1)(
35 downto 27);
607 --DATA1(138 downto 102) <= TTC_status(
1)(
90 downto 54);
608 --DATA1(142 downto 139) <= bcnt;
610 --TRIG1(2 downto 1) <= TTC_status(
10)(
31 downto 30);
611 --TRIG1(4 downto 3) <= TTC_status(
9)(
31 downto 30);
612 --TRIG1(6 downto 5) <= TTC_status(
1)(
31 downto 30);
614 AllEventBuilt <= AllEventBuilt_i;
615 AMC_Ready <= AMC_Ready_i;
617 process(sysclk,reset)
620 resetSyncRegs <= (others => '1');
622 elsif(sysclk'event and sysclk = '1')then
623 resetSyncRegs <= resetSyncRegs(1 downto 0) & '0';
624 if(enRstAMC_link = '1' and AllEventBuilt_i = '1')then
627 RstAMC_link <= resetSyncRegs(1);
633 if(sysclk'event and sysclk = '1')then
634 if(resetSyncRegs(2) = '1')then
635 L1A_buf_wa <= (others => '0');
636 elsif(L1A_buf_we = '1')then
637 L1A_buf_wa <= L1A_buf_wa + 1;
639 if(resetSyncRegs(2) = '1' or ttc_evcnt_reset = '1')then
640 event_cnt <= (others => '0');
641 elsif(event_number_avl = '1')then
642 event_cnt <= event_cnt + 1;
644 event_number_avl_q <= event_number_avl_q(1 downto 0) & event_number_avl;
645 if(resetSyncRegs(2) = '1')then
648 L1A_buf_we <= event_number_avl or or_reduce(event_number_avl_q);
650 if(event_number_avl = '1')then
651 L1A_buf_di <= event_number(43 downto 12);
-- OcN
652 bcnt <= event_number(11 downto 0);
-- OcN
653 event_status <= event_number(59 downto 44) &"00" & event_number(45) & not event_number(45);
654 elsif(event_number_avl_q(0) = '1')then
655 L1A_buf_di <= x"00000" & bcnt;
-- bcnt
656 elsif(event_number_avl_q(1) = '1')then
657 L1A_buf_di <= x"00" & event_cnt;
-- bcnt
659 L1A_buf_di <= x"000" & event_status;
-- bcnt
663 -- if(en_cal_win = '0')then
664 -- event_number(51 downto 48) <= x"0";
665 -- event_number(44) <= '0';
667 -- event_number(51) <= cal_win
and brcst_GapTrig
and cal_type(
3)
and not brcst_GapPed;
668 -- event_number(50) <= cal_win
and brcst_GapTrig
and cal_type(
2)
and not brcst_GapPed;
669 -- event_number(49) <= cal_win
and brcst_GapTrig
and cal_type(
1)
and not brcst_GapPed;
670 -- event_number(48) <= cal_win
and ((brcst_GapTrig
and cal_type(
0))
or brcst_GapPed);
671 -- event_number(44) <= cal_win
and (brcst_GapTrig
or brcst_GapPed);
673 -- event_number(59 downto 56) <= cal_type;
674 -- event_number(55 downto 52) <= state;
675 -- event_number(47) <= brcst_GapTrig;
676 -- event_number(46) <= brcst_GapPed;
677 -- event_number(45) <= cal_win;
678 -- event_number(43 downto 0) <= oc & bcnt;
679 -- receiving L1 information
680 i_L1A_buf : BRAM_SDP_MACRO
682 BRAM_SIZE =>
"18Kb",
-- Target BRAM, "18Kb" or "36Kb"
683 DEVICE =>
"7SERIES",
-- Target device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
684 WRITE_WIDTH =>
32,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
685 READ_WIDTH =>
32) -- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
687 DO => L1A_buf_do,
-- Output read data port, width defined by READ_WIDTH parameter
688 DI => L1A_buf_di,
-- Input write data port, width defined by WRITE_WIDTH parameter
689 RDADDR => ipb_addr
(8 downto 0),
-- Input read address, width defined by read port depth
690 RDCLK => sysclk,
-- 1-bit input read clock
691 RDEN => '1',
-- 1-bit input read port enable
692 REGCE => '1',
-- 1-bit input read output register enable
693 RST => '0',
-- 1-bit input reset
694 WE => x"f",
-- Input write enable, width defined by write port depth
695 WRADDR => L1A_buf_wa,
-- Input write address, width defined by write port depth
696 WRCLK => sysclk,
-- 1-bit input write clock
697 WREN => L1A_buf_we
-- 1-bit input write port enable
699 ovfl_warning <= ovfl_warning_i(3);
700 i_evn : BRAM_SDP_MACRO
702 BRAM_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
703 DEVICE =>
"7SERIES",
-- Target device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
704 WRITE_WIDTH =>
60,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
705 READ_WIDTH =>
60,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
706 DO_REG =>
0,
-- Optional output register (0 or 1)
707 SIM_COLLISION_CHECK =>
"NONE",
-- Collision check enable "ALL",
"WARNING_ONLY",
708 -- "GENERATE_X_ONLY" or "NONE"
709 WRITE_MODE =>
"WRITE_FIRST",
-- Specify "READ_FIRST" for same clock
or synchronous clocks
710 -- Specify "WRITE_FIRST for asynchrononous clocks on ports
711 INIT => X"000000000000000000"
) -- Initial values on output port
713 DO => evn_out,
-- Output read data port, width defined by READ_WIDTH parameter
714 DI => event_number,
-- Input write data port, width defined by WRITE_WIDTH parameter
715 RDADDR => evn_ra,
-- Input read address, width defined by read port depth
716 RDCLK => sysclk,
-- 1-bit input read clock
717 RDEN => '1',
-- 1-bit input read port enable
718 REGCE => '1',
-- 1-bit input read output register enable
719 RST => '0',
-- 1-bit input reset
720 WE => x"ff",
-- Input write enable, width defined by write port depth
721 WRADDR => evn_wa,
-- Input write address, width defined by write port depth
722 WRCLK => sysclk,
-- 1-bit input write clock
723 WREN => event_number_avl
-- 1-bit input write port enable
726 variable enable : (2 downto 0);
728 if(ThreeSFP = '1')then
730 elsif(TwoSFP = '1')then
735 if(sysclk'event and sysclk = '1')then
736 if(resetSyncRegs(2) = '1')then
737 evn_wa <= (others => '0');
738 elsif(event_number_avl = '1')then
739 evn_wa <= evn_wa + 1;
741 if(resetSyncRegs(2) = '1')then
742 evn_ra <= (others => '0');
743 elsif(sel_evn = "10")then
744 evn_ra <= evn_ra + 1;
746 if(ttc_evcnt_reset = '1' or resetSyncRegs(2) = '1')then
748 elsif(sel_evn = "10")then
752 if(resetSyncRegs(2) = '1' or enable(i) = '0')then
753 evt_cnt(i) <= (others => '0');
754 elsif(event_number_avl = '1' and EventBuilt(i) = '0')then
755 evt_cnt(i) <= evt_cnt(i) + 1;
756 elsif(event_number_avl = '0' and EventBuilt(i) = '1')then
757 evt_cnt(i) <= evt_cnt(i) - 1;
759 if(and_reduce(evt_cnt(i)(7 downto 5)) = '1')then
760 evn_buf_full_i(i) <= '1';
762 evn_buf_full_i(i) <= '0';
764 -- when reached 0x60, throttle L1A.
Return only
after go below
0x40
765 if(or_reduce(evt_cnt(i)(7 downto 6)) = '0')then
766 ovfl_warning_i(i) <= '0';
767 elsif(evt_cnt(i)(5) = '1')then
768 ovfl_warning_i(i) <= '1';
771 evn_buf_full <= or_reduce(evn_buf_full_i);
772 ovfl_warning_i(3) <= or_reduce(ovfl_warning_i(2 downto 0)) or (or_reduce(TTS_FIFO_do(4 downto 0)) and en_localL1A);
775 -- send L1info to AMC_Link
778 if(sysclk'event and sysclk = '1')then
779 if(resetSyncRegs(2) = '1' or evn_wa = evn_ra)then
784 L1A_WrEn <= not evn_empty;
785 if(resetSyncRegs(2) = '1' or evn_empty = '1')then
788 sel_evn(1) <= sel_evn(1) xor sel_evn(0);
789 sel_evn(0) <= not sel_evn(0);
792 when "00" => L1A_DATA <= evn_out(11 downto 0) & x"0";
-- BX
793 when "01" => L1A_DATA <= evn(15 downto 0);
794 when "10" => L1A_DATA <= x"00" & evn(23 downto 16);
795 when others => L1A_DATA <= evn_out(27 downto 12);
-- OrN
799 i_CDF : BRAM_SDP_MACRO
801 BRAM_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
802 DEVICE =>
"7SERIES",
-- Target device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
803 WRITE_WIDTH =>
72,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
804 READ_WIDTH =>
72,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
805 DO_REG =>
0,
-- Optional output register (0 or 1)
806 SIM_COLLISION_CHECK =>
"NONE",
-- Collision check enable "ALL",
"WARNING_ONLY",
807 -- "GENERATE_X_ONLY" or "NONE"
808 WRITE_MODE =>
"WRITE_FIRST",
-- Specify "READ_FIRST" for same clock
or synchronous clocks
809 -- Specify "WRITE_FIRST for asynchrononous clocks on ports
810 INIT => X"000000000000000000"
) -- Initial values on output port
812 DO => CDF_out,
-- Output read data port, width defined by READ_WIDTH parameter
813 DI => CDF_in,
-- Input write data port, width defined by WRITE_WIDTH parameter
814 RDADDR => CDF_ra,
-- Input read address, width defined by read port depth
815 RDCLK => sysclk,
-- 1-bit input read clock
816 RDEN => '1',
-- 1-bit input read port enable
817 REGCE => '1',
-- 1-bit input read output register enable
818 RST => '0',
-- 1-bit input reset
819 WE => x"ff",
-- Input write enable, width defined by write port depth
820 WRADDR => CDF_wa,
-- Input write address, width defined by write port depth
821 WRCLK => sysclk,
-- 1-bit input write clock
822 WREN => sel_evn
(0) -- 1-bit input write port enable
826 if(sysclk'event and sysclk = '1')then
827 if(resetSyncRegs(2) = '1')then
828 CDF_wa <= (others => '0');
829 elsif(sel_evn(0) = '1')then
830 CDF_wa <= CDF_wa + 1;
832 if(resetSyncRegs(2) = '1')then
833 CDF_ra <= (others => '0');
834 elsif(ec_CDF_ra = '1')then
835 CDF_ra <= CDF_ra + 1;
837 if(resetSyncRegs(2) = '1')then
838 CDF_cnt <= (others => '0');
839 elsif(sel_evn(0) = '1' and CDF_wa(0) = '1' and (ec_CDF_ra = '0' or CDF_ra(0) = '1'))then
840 CDF_cnt <= CDF_cnt + 1;
841 elsif((sel_evn(0) = '0' or CDF_wa(0) = '0') and ec_CDF_ra = '1' and CDF_ra(0) = '0')then
842 CDF_cnt <= CDF_cnt - 1;
844 if(resetSyncRegs(2) = '1')then
846 elsif(or_reduce(CDF_cnt(7 downto 1)) = '0' and (CDF_cnt(0) = '0' or ec_CDF_ra = '1'))then
848 elsif(or_reduce(CDF_cnt) = '1')then
851 if(sel_evn(1) = '0')then
852 -- CDF_in <= x"005" & EvtTy & evn & evn_out(11 downto 0) & Source_ID(
11 downto 0) & x"08"; -- header1
853 CDF_in <= x"005" & EvtTy & evn & evn_out(11 downto 0) & x"00008";
-- header1
855 CDF_in <= x"00" & uFOV & CalTy & x"00000" & evn_out(43 downto 12) & x"0";
-- header2
859 EvtTy <= "00" & evn_out(45) & not evn_out(45);
860 CalTy <= evn_out(51 downto 48);
861 process(sysclk, ThreeSFP, TwoSFP, sel_AMC)
862 variable bldr_mask_sel : (4 downto 0);
863 variable bldr_mask : (2 downto 0);
864 --variable Mbit_word : (11 downto 0);
866 bldr_mask_sel(4) := ThreeSFP;
867 bldr_mask_sel(3) := TwoSFP;
868 bldr_mask_sel(2 downto 0) := sel_AMC(3 downto 1);
869 case bldr_mask_sel is
870 when "10100" | "10101" => bldr_mask := "100";
871 when "10000" | "10001" | "01000" | "01001" | "01010" => bldr_mask := "010";
872 when others => bldr_mask := "001";
874 -- for i in 0 to 11 loop
875 -- Mbit_word(i) := EventInfo(i)(25);
877 if(sysclk'event and sysclk = '1')then
878 if(resetSyncRegs(2) = '1')then
882 EventInfo_avl <= '0';
885 AMC_wc_sum_we <= '0';
888 AMC_header_we <= "000";
893 if((and_reduce(not AMC_hasData or EventInfo_dav) = '1' and or_reduce(AMC_hasData) = '1') or (or_reduce(amc_en) = '0' and CDF_empty = '0'))then
894 EventInfo_avl <= '1';
896 EventInfo_avl <= '0';
898 -- LastBlock <= not or_reduce(AMC_hasData and Mbit_word);
900 for i in 0 to 11 loop
901 if(AMC_hasData(i) = '1' and EventInfo(i)(25) = '1')then
905 if(EventInfo_avl = '1' and init_bldr = '0' and bldr_fifo_full = "000" and ((mon_en = '0' and TCPbuf_avl = '1') or (mon_en = '1' and mon_buf_avl = '1')))then
906 if(CDF_header = '1')then
908 zero_wc <= not ThreeSFP & OneSFP & '0';
914 buf_rqst <= LastBlock & CDF_header & not mon_en & mon_en;
915 AMC_header(0)(64) <= mon_en and mon_buf_avl;
916 AMC_header(1)(64) <= mon_en and mon_buf_avl;
917 AMC_header(2)(64) <= mon_en and mon_buf_avl;
919 for i in 0 to 11 loop
920 Mbit_word(i) <= AMC_hasData(i) and EventInfo(i)(25);
922 elsif(rst_init_bldr = '1')then
924 -- zero_wc <= zero_wc or not more_wc;
925 zero_wc <= not more_wc;
926 if(LastBlock = '1')then
934 if(init_bldr = '1')then
936 BlockHeader <= CDF_header;
938 if(ec_sel_AMC = '1' and Mbit_word(conv_integer(sel_AMC)) = '1')then
939 more_wc <= more_wc or bldr_mask;
942 sel_CDF <= (CDF_header and init_bldr) or BlockHeader;
943 -- if(BlockHeader = '1')then
944 -- AMC_hasData_l <= AMC_hasData;
946 if(BlockHeader = '1')then
948 elsif(sel_AMC = x"b")then
951 if(AMC_hasData(conv_integer(sel_AMC)) = '1' and ec_sel_AMC = '1')then
952 AMC_wc_we <= bldr_mask;
953 AMC_wc_sum_we <= or_reduce(bldr_mask);
956 AMC_wc_sum_we <= '0';
959 if((sel_CDF = '1' and (FirstBlock(i) = '1' or nAMC(i) /= x"0")) or AMC_wc_we(i) = '1')then
960 AMC_header_we(i) <= '1';
962 AMC_header_we(i) <= '0';
965 if(ec_sel_AMC = '0' or sel_AMC = x"b")then
968 sel_AMC <= sel_AMC + 1;
972 case AMC_hasData(i*4+3 downto i*4) is
973 when x"1" | x"2" | x"4" | x"8" => mAMC(i) <= x"1";
974 when x"3" | x"5" | x"6" | x"9" | x"a" | x"c" => mAMC(i) <= x"2";
975 when x"7" | x"b" | x"d" | x"e" => mAMC(i) <= x"3";
976 when x"f" => mAMC(i) <= x"4";
977 when others => mAMC(i) <= x"0";
980 kAMC(0)(1) <= AMC_hasData(5) and AMC_hasData(4);
981 kAMC(0)(0) <= AMC_hasData(5) xor AMC_hasData(4);
982 kAMC(1)(1) <= AMC_hasData(7) and AMC_hasData(6);
983 kAMC(1)(0) <= AMC_hasData(7) xor AMC_hasData(6);
984 if(ThreeSFP = '1')then
986 elsif(TwoSFP = '1')then
987 nAMC(0) <= mAMC(2) + kAMC(1);
989 nAMC(0) <= mAMC(0) + mAMC(1) + mAMC(2);
991 if(ThreeSFP = '1')then
993 elsif(TwoSFP = '1')then
994 nAMC(1) <= mAMC(0) + kAMC(0);
998 if(ThreeSFP = '1')then
1003 summary <= '0' & EventInfo(conv_integer(sel_AMC))(26 downto 20) & x"0" & EventInfo(conv_integer(sel_AMC))(19 downto 0) & block_num & (sel_AMC+1) & AMCinfo(conv_integer(sel_AMC));
1004 for i in 0 to 2 loop
1005 AMC_header(i)(65) <= not BlockHeader and sel_CDF;
1006 if(sel_CDF = '0')then
1007 AMC_header(i)(55 downto 52) <= summary(55 downto 52);
1008 elsif(BlockHeader = '1')then
1009 AMC_header(i)(55 downto 52) <= CDF_out(55 downto 52);
1011 AMC_header(i)(55 downto 52) <= nAMC(i);
1013 if(sel_CDF = '1')then
1014 AMC_header(i)(63 downto 56) <= CDF_out(63 downto 56);
1015 AMC_header(i)(51 downto 20) <= CDF_out(51 downto 20);
1016 AMC_header(i)(7 downto 0) <= CDF_out(7 downto 0);
1018 AMC_header(i)(63 downto 56) <= summary(63 downto 56);
1019 AMC_header(i)(51 downto 20) <= summary(51 downto 20);
1020 AMC_header(i)(7 downto 0) <= summary(7 downto 0);
1023 if(sel_CDF = '0')then
1024 AMC_header(0)(19 downto 8) <= summary(19 downto 8);
1025 AMC_header(1)(19 downto 8) <= summary(19 downto 8);
1026 AMC_header(2)(19 downto 8) <= summary(19 downto 8);
1027 elsif(BlockHeader = '1')then
1028 if(OneSFP = '1')then
1029 AMC_header(0)(19 downto 8) <= source_ID(0);
1031 AMC_header(0)(19 downto 8) <= source_ID(1);
1033 AMC_header(1)(19 downto 8) <= source_ID(0);
1034 AMC_header(2)(19 downto 8) <= source_ID(2);
1036 AMC_header(0)(19 downto 8) <= CDF_out(19 downto 8);
1037 AMC_header(1)(19 downto 8) <= CDF_out(19 downto 8);
1038 AMC_header(2)(19 downto 8) <= CDF_out(19 downto 8);
1040 if(CDF_header = '1')then
1041 FirstBlock(0) <= '1';
1042 FirstBlock(1) <= not OneSFP;
1043 FirstBlock(2) <= ThreeSFP;
1044 block_num <= (others => '0');
1045 elsif(rst_init_bldr = '1')then
1046 FirstBlock <= "000";
1047 block_num <= block_num + 1;
1049 if(fifo_en = '0' or (EventInfoRdDone(12) = '1' and LastBlock = '1'))then
1050 AMC_hasData <= AMC_en;
1051 -- elsif(ec_sel_AMC = '1' and EventInfo(conv_integer(sel_AMC))(25) = '0')
then -- More
is '0'
1052 -- AMC_hasData(conv_integer(sel_AMC)) <= '0';
1053 elsif(EventInfoRdDone(12) = '1')then
1054 AMC_hasData <= Mbit_word;
1056 for i in 0 to 11 loop
1057 if(Mbit_word(i) = '1')then
1058 AMC_wcp(i) <= "1000000000000";
1060 AMC_wcp(i) <= EventInfo(i)(12 downto 0);
1063 if(OneSFP = '1')then
1064 -- AMC_wc(17) <=
not or_reduce(AMC_hasData
and Mbit_word);
1065 AMC_wc(17) <= not or_reduce(Mbit_word);
1066 elsif(TwoSFP = '1')then
1067 if(sel_AMC = x"0")then
1068 AMC_wc(17) <= not or_reduce(Mbit_word(5 downto 0));
1069 elsif(sel_AMC = x"6")then
1070 AMC_wc(17) <= not or_reduce(Mbit_word(11 downto 6));
1073 if(sel_AMC = x"0")then
1074 AMC_wc(17) <= not or_reduce(Mbit_word(3 downto 0));
1075 elsif(sel_AMC = x"4")then
1076 AMC_wc(17) <= not or_reduce(Mbit_word(7 downto 4));
1077 elsif(sel_AMC = x"8")then
1078 AMC_wc(17) <= not or_reduce(Mbit_word(11 downto 8));
1081 AMC_wc(16 downto 0) <= sel_AMC & AMC_wcp(conv_integer(sel_AMC));
1084 kAMC(1)(3 downto 2) <= "00";
1085 kAMC(0)(3 downto 2) <= "00";
1086 --AMC_header(1)(
64 downto 56) <= AMC_header(
0)(
64 downto 56);
1087 --AMC_header(1)(
51 downto 0) <= AMC_header(
0)(
51 downto 0);
1088 --AMC_header(2)(
64 downto 56) <= AMC_header(
0)(
64 downto 56);
1089 --AMC_header(2)(
51 downto 0) <= AMC_header(
0)(
51 downto 0);
1092 reset => resetSyncRegs
(2),
1093 fifo_rst => fifo_rst,
1095 en_inject_err => en_inject_err,
1098 block_wc => mon_wc
(0),
1099 block_wc_we => block_wc_we
(0),
1101 AMC_wc_we => AMC_wc_we
(0),
1102 AMC_wc_end => rst_init_bldr,
1103 bldr_fifo_full => bldr_fifo_full
(0),
1104 AMC_header => AMC_header
(0),
1105 AMC_header_we => AMC_header_we
(0),
1106 AMC_DATA => AMC_DATA,
1107 AMC_DATA_re => AMC_DATA_re
(0),
1108 AMCCRC_bad => AMCCRC_bad
(0),
1109 evt_data => evt_data
(0),
1110 evt_data_we => evt_data_we
(0),
1111 evt_buf_full => evt_buf_full
(0),
1112 evt_data_re => evt_data_re
(0),
1113 evt_data_rdy => evt_data_rdy
(0),
1114 debug => evt_bldr_debug ,
1115 EventBuilt => EventBuilt
(0)
1119 reset => resetSyncRegs
(2),
1120 fifo_rst => fifo_rst,
1122 en_inject_err => en_inject_err,
1125 block_wc => mon_wc
(1),
1126 block_wc_we => block_wc_we
(1),
1128 AMC_wc_we => AMC_wc_we
(1),
1129 AMC_wc_end => rst_init_bldr,
1130 bldr_fifo_full => bldr_fifo_full
(1),
1131 AMC_header => AMC_header
(1),
1132 AMC_header_we => AMC_header_we
(1),
1133 AMC_DATA => AMC_DATA1,
1134 AMC_DATA_re => AMC_DATA_re
(1),
1135 AMCCRC_bad => AMCCRC_bad
(1),
1136 evt_data => evt_data
(1),
1137 evt_data_we => evt_data_we
(1),
1138 evt_buf_full => evt_buf_full
(1),
1139 evt_data_re => evt_data_re
(1),
1140 evt_data_rdy => evt_data_rdy
(1),
1142 EventBuilt => EventBuilt
(1)
1144 g_AMC_DATA1: for i in 0 to 5 generate
1145 AMC_DATA1(i) <= AMC_DATA(i);
1146 AMC_DATA1(i+6) <= (others => '0');
1150 reset => resetSyncRegs
(2),
1151 fifo_rst => fifo_rst,
1153 en_inject_err => en_inject_err,
1156 block_wc => mon_wc
(2),
1157 block_wc_we => block_wc_we
(2),
1159 AMC_wc_we => AMC_wc_we
(2),
1160 AMC_wc_end => rst_init_bldr,
1161 bldr_fifo_full => bldr_fifo_full
(2),
1162 AMC_header => AMC_header
(2),
1163 AMC_header_we => AMC_header_we
(2),
1164 AMC_DATA => AMC_DATA2,
1165 AMC_DATA_re => AMC_DATA_re
(2),
1166 AMCCRC_bad => AMCCRC_bad
(2),
1167 evt_data => evt_data
(2),
1168 evt_data_we => evt_data_we
(2),
1169 evt_buf_full => evt_buf_full
(2),
1170 evt_data_re => evt_data_re
(2),
1171 evt_data_rdy => evt_data_rdy
(2),
1173 EventBuilt => EventBuilt
(2)
1175 g_AMC_DATA2: for i in 0 to 3 generate
1176 AMC_DATA2(i) <= AMC_DATA(i+8);
1177 AMC_DATA2(i+4) <= AMC_DATA(i+8);
1178 AMC_DATA2(i+8) <= AMC_DATA(i+8);
1180 AMC_DATA_RdEn <= AMC_DATA_re(0) or AMC_DATA_re(1) or AMC_DATA_re(2);
1183 if(sysclk'event and sysclk = '1')then
1184 for i in 0 to 11 loop
1185 if(AMCCRC_bad(0)(i) = '1' or AMCCRC_bad(1)(i) = '1' or AMCCRC_bad(2)(i) = '1')then
1186 badEventCRCToggle(i) <= not badEventCRCToggle(i);
1188 if(EventInfo(i)(31) = '1' and EventInfo(i)(25) = '0' and EventInfoRdDone(i) = '1')then
1189 ReSyncFakeEventToggle(i) <= not ReSyncFakeEventToggle(i);
1195 reset => resetFIFO_AMC,
1197 fifo_rst => fifo_rst_AMC,
1198 fifo_en => fifo_en_AMC
1200 resetFIFO_AMC <= reset or or_reduce(not AMC_txfsmresetdone and AMC_en) or RstAMC_link;
1201 g_AMC_Link : for i in 0 to 11 generate
1205 reset => RstAMC_link,
1206 resetCntr => CntrRst,
1207 fifo_rst => fifo_rst_AMC,
1208 fifo_en => fifo_en_AMC,
1210 strobe2ms => strobe2ms,
1211 NoReSyncFake => NoReSyncFake,
1213 RXNOTINTABLE => AMC_RXNOTINTABLE
(i
),
1214 rxcommaalignen => AMC_rxcommaalignen
(i
),
1215 rxchariscomma => AMC_rxchariscomma
(i
),
1216 rxcharisk => AMC_rxcharisk
(i
),
1217 rxresetdone => AMC_rxresetdone
(i
),
1218 qpll_lock => AMC_qpll_lock
(i/4
),
1219 txfsmresetdone => AMC_txfsmresetdone
(i
),
1220 data_valid => AMC_data_valid
(i
),
1221 RXDATA => AMC_RXDATA
(i
),
1222 txcharisk => AMC_txcharisk
(i
),
1223 TXDATA => AMC_TXDATA
(i
),
1224 Ready => AMC_Ready_i
(i
),
1225 AMC_ID => AMC_ID
(i
),
1226 AMCinfo => AMCinfo
(i
),
1227 EventInfo => EventInfo
(i
),
1228 EventInfo_dav => EventInfo_dav
(i
),
1229 AMC_DATA_RdEn => AMC_DATA_RdEn
(i
),
1230 EventInfoRdDone => EventInfoRdDone
(i
),
1231 AMC_DATA => AMC_DATA
(i
),
1232 bad_AMC => AMC_status
(i
),
1233 AMC_OK => AMC_OK
(i
),
1234 L1A_DATA => L1A_DATA,
1235 L1A_WrEn => L1A_WrEn,
1236 fake_header => fake_header,
1237 fake_CRC => fake_CRC,
1238 fake_DATA => fake_DATA,
1239 fake_WrEn => fake_WrEn,
1240 fake_full => fake_full
(i
),
1241 Cntr_ADDR => Cntr_ADDR,
1242 Cntr_DATA => Cntr_DATA
(i
),
1243 debug_out => AMC_debug
(i
),
1247 AMC_en => AMC_en
(i
),
1248 TTS_disable => TTS_disable
(i
),
1249 TTC_status => TTC_status
(i
),
1250 TrigData => TrigData
(i
),
1251 TTS_RQST => AMC_TTS_RQST
(i
),
1252 TTS_coded => AMC_TTS
(i
)(4 downto 0)
1257 SOFT_RESET => GTXreset,
1262 RXDATA => AMC_RXDATA,
1263 RxBufOvf => RxBufOvf,
1264 RxBufUdf => RxBufUdf,
1265 sampleRatio => RxClkCntr19_q,
1266 updateRatio => updateRatio,
1267 RxClkRatio => RxClkRatio,
1268 rxprbserr => AMC_rxprbserr,
1269 rxprbssel => AMC_rxprbssel,
1270 RXNOTINTABLE => AMC_RXNOTINTABLE,
1271 rxcommaalignen => AMC_rxcommaalignen,
1272 rxchariscomma => AMC_rxchariscomma,
1273 rxcharisk => AMC_rxcharisk,
1274 rxresetdone => AMC_rxresetdone,
1275 txdiffctrl => AMC_txdiffctrl,
1276 TXDATA => AMC_TXDATA,
1277 txoutclk => UsrClk_out,
1278 txcharisk => AMC_txcharisk,
1279 txresetdone =>
open,
1280 txprbssel => AMC_txprbssel,
1281 qpll_lock => AMC_qpll_lock,
1282 txfsmresetdone => AMC_txfsmresetdone,
1283 rxfsmresetdone => AMC_rxfsmresetdone,
1284 data_valid => AMC_data_valid,
1285 AMC_REFCLK => AMC_REFCLK,
1293 if(sysclk'event and sysclk = '1')then
1294 ovfl_warning_p <= ovfl_warning_i(3) and not en_localL1A;
1295 if(resetSyncRegs(2) = '1')then
1296 AllEventBuilt_i <= '1';
1298 for i in 0 to 2 loop
1299 if(EventBuilt(i) = '1')then
1300 EventBuiltToggle(i) <= not EventBuiltToggle(i);
1303 if(evt_cnt(0) = x"00" and evt_cnt(1) = x"00" and evt_cnt(2) = x"00")then
1304 AllEventBuilt_i <= '1';
1306 AllEventBuilt_i <= '0';
1309 if(RstAMC_link_dl = '1')then
1310 enRstAMC_link <= '0';
1311 elsif(ReSync = '1')then
1312 enRstAMC_link <= '1';
1316 i_RstAMC_link_dl : SRL16E
1318 Q => RstAMC_link_dl ,
-- SRL data output
1319 A0 => '1',
-- Select[0] input
1320 A1 => '1',
-- Select[1] input
1321 A2 => '1',
-- Select[2] input
1322 A3 => '1',
-- Select[3] input
1323 CE => '1',
-- Clock enable input
1324 CLK => sysclk,
-- Clock input
1325 D => RstAMC_link
-- SRL data input
1329 if(UsrClk'event and UsrClk = '1')then
1330 LinkFull <= or_reduce(fake_full);
1331 if(Cntr2ms(18 downto 17) = "11" and Cntr2ms(14) = '1')then
1332 Cntr2ms <= (others => '0');
1335 Cntr2ms <= Cntr2ms + 1;
1340 fake_en <= '0' when test = '0' or AMC_en = x"000" else '1';
1344 reset => resetSyncRegs
(2),
1345 fifo_rst => fifo_rst,
1349 fake_length => fake_length,
1350 ovfl_warning => ovfl_warning_p ,
1351 LinkFull => LinkFull,
1352 L1A_DATA => L1A_DATA,
1353 L1A_WrEn => L1A_WrEn,
1354 fake_header => fake_header,
1355 fake_CRC => fake_CRC,
1356 empty_event_flag => empty_event_flag,
1357 fake_DATA => fake_DATA,
1358 fake_WrEn => fake_WrEn
1360 process(UsrClk,reset)
1363 for i in 0 to 11 loop
1364 AMC_TTS(i)(7 downto 5) <= "000";
1366 elsif(UsrClk'event and UsrClk = '1')then
1367 for i in 0 to 11 loop
1368 if(AMC_TTS(i)(2) = '1' and AMC_Ready_i(i) = '1')then -- Out of Sync
1369 AMC_TTS(i)(5) <= '1';
1371 if(AMC_TTS(i)(3) = '1' and AMC_Ready_i(i) = '1')then -- error
1372 AMC_TTS(i)(6) <= '1';
1374 if(AMC_TTS(i)(4) = '1' and AMC_Ready_i(i) = '1')then -- disconnected
1375 AMC_TTS(i)(7) <= '1';
1382 if(UsrClk'event and UsrClk = '1')then
1383 AMC_TTS_OR <= AMC_TTS(0) or AMC_TTS(1) or AMC_TTS(2) or AMC_TTS(3) or AMC_TTS(4) or AMC_TTS(5) or
1384 AMC_TTS(6) or AMC_TTS(7) or AMC_TTS(8) or AMC_TTS(9) or AMC_TTS(10) or AMC_TTS(11) or err_TTS;
1385 AMC_TTS_RQST_OR <= AMC_TTS_RQST(0) or AMC_TTS_RQST(1) or AMC_TTS_RQST(2) or AMC_TTS_RQST(3) or AMC_TTS_RQST(4) or AMC_TTS_RQST(5) or
1386 AMC_TTS_RQST(6) or AMC_TTS_RQST(7) or AMC_TTS_RQST(8) or AMC_TTS_RQST(9) or AMC_TTS_RQST(10) or AMC_TTS_RQST(11);
1389 err_TTS <= "000000" & stop_mon & '0';
1390 process(UsrClk,reset)
1393 TTS_FIFO_wa <= (others => '0');
1394 elsif(UsrClk'event and UsrClk = '1')then
1395 case TTS_FIFO_wa(2 downto 0) is
1396 when "000" => TTS_FIFO_wa(2 downto 0) <= "001";
1397 when "001" => TTS_FIFO_wa(2 downto 0) <= "011";
1398 when "011" => TTS_FIFO_wa(2 downto 0) <= "010";
1399 when "010" => TTS_FIFO_wa(2 downto 0) <= "110";
1400 when "110" => TTS_FIFO_wa(2 downto 0) <= "111";
1401 when "111" => TTS_FIFO_wa(2 downto 0) <= "101";
1402 when "101" => TTS_FIFO_wa(2 downto 0) <= "100";
1403 when others => TTS_FIFO_wa(2 downto 0) <= "000";
1415 TTS_FIFO_di <= AMC_TTS_RQST_OR & AMC_TTS_OR(4 downto 0);
1416 TTS_FIFO_ra <= "00" & TTS_FIFO_waSyncRegs3;
1419 if(sysclk'event and sysclk = '1')then
1420 TTS_FIFO_waSyncRegs <= TTS_FIFO_wa(2 downto 0);
1421 TTS_FIFO_waSyncRegs2 <= TTS_FIFO_waSyncRegs;
1422 TTS_FIFO_waSyncRegs3 <= TTS_FIFO_waSyncRegs2;
1423 if(enRstAMC_link = '1' or AMC_en /= AMC_Ready_i)then
1424 TTS_coded <= "00010";
1426 TTS_coded <= TTS_FIFO_do(4 downto 0);
1428 TTS_RQST <= TTS_FIFO_do(7 downto 5);
1431 i_UsrClk_buf: bufg
port map(i => UsrClk_out
(6), o => UsrClk
);
1434 if(UsrClk'event and UsrClk = '1')then
1435 RxClkCntr <= RxClkCntr + 1;
1436 RXClkCntr19_q <= RXClkCntr(19);
1437 if(RXClkCntr19_q = '1' and RXClkCntr(19) = '0')then
1438 if(Cntr_ADDR(11 downto 5) = "1110001")then
1444 if(Cntr_ADDR(11 downto 7) = "11000" or Cntr_ADDR(11 downto 6) = "111000")then
1449 if(Cntr_ADDR(11 downto 7) = "11000" or Cntr_ADDR(11 downto 6) = "111000")then
1450 AMC_if_ADDR <= Cntr_ADDR(9) & Cntr_ADDR(6 downto 0);
1452 AMC_if_ADDR <= (others => '0');
1454 if(AMC_if_RdEn = '0')then
1455 AMC_if_data <= (others => '0');
1456 elsif(AMC_if_ADDR(7) = '0')then
1457 case AMC_if_ADDR(6 downto 4) is
1459 case AMC_if_ADDR(3 downto 0) is
1460 when x"0" => AMC_if_data <= EventInfo(0)(15 downto 0);
1461 when x"1" => AMC_if_data <= EventInfo(0)(31 downto 16);
1462 when x"2" => AMC_if_data <= EventInfo(1)(15 downto 0);
1463 when x"3" => AMC_if_data <= EventInfo(1)(31 downto 16);
1464 when x"4" => AMC_if_data <= EventInfo(2)(15 downto 0);
1465 when x"5" => AMC_if_data <= EventInfo(2)(31 downto 16);
1466 when x"6" => AMC_if_data <= EventInfo(3)(15 downto 0);
1467 when x"7" => AMC_if_data <= EventInfo(3)(31 downto 16);
1468 when x"8" => AMC_if_data <= EventInfo(4)(15 downto 0);
1469 when x"9" => AMC_if_data <= EventInfo(4)(31 downto 16);
1470 when x"a" => AMC_if_data <= EventInfo(5)(15 downto 0);
1471 when x"b" => AMC_if_data <= EventInfo(5)(31 downto 16);
1472 when x"c" => AMC_if_data <= EventInfo(6)(15 downto 0);
1473 when x"d" => AMC_if_data <= EventInfo(6)(31 downto 16);
1474 when x"e" => AMC_if_data <= EventInfo(7)(15 downto 0);
1475 when others => AMC_if_data <= EventInfo(7)(31 downto 16);
1478 case AMC_if_ADDR(3 downto 0) is
1479 when x"0" => AMC_if_data <= EventInfo(8)(15 downto 0);
1480 when x"1" => AMC_if_data <= EventInfo(8)(31 downto 16);
1481 when x"2" => AMC_if_data <= EventInfo(9)(15 downto 0);
1482 when x"3" => AMC_if_data <= EventInfo(9)(31 downto 16);
1483 when x"4" => AMC_if_data <= EventInfo(10)(15 downto 0);
1484 when x"5" => AMC_if_data <= EventInfo(10)(31 downto 16);
1485 when x"6" => AMC_if_data <= EventInfo(11)(15 downto 0);
1486 when x"7" => AMC_if_data <= EventInfo(11)(31 downto 16);
1487 when x"8" => AMC_if_data <= LinkFull & not AMC_qpll_lock & EventInfo_dav;
1488 when x"9" => AMC_if_data <= x"0" & fake_full;
1489 when x"a" => AMC_if_data <= AMC_TTC_status(15 downto 0);
1490 when x"b" => AMC_if_data <= AMC_TTC_status(31 downto 16);
1491 when x"c" => AMC_if_data <= x"0" & AMC_rxfsmresetdone;
1492 when x"d" => AMC_if_data <= x"0" & AMC_txfsmresetdone;
1493 when x"e" => AMC_if_data <= "0000000" & CDF_empty & CDF_cnt;
1494 when others => AMC_if_data <= errors & x"00";
1497 case AMC_if_ADDR(3 downto 0) is
1498 when x"0" => AMC_if_data <= "0000000" & evn_wa;
1499 when x"1" => AMC_if_data <= "0000000" & evn_ra;
1500 when x"2" => AMC_if_data <= evn(15 downto 0);
1501 when x"3" => AMC_if_data <= x"00" & evn(23 downto 16);
1502 when x"4" => AMC_if_data <= "0000000" & CDF_wa;
1503 when x"5" => AMC_if_data <= "0000000" & CDF_ra;
1504 when x"6" => AMC_if_data <= ec_CDF_ra & AMC_wc_we & sel_CDF & AMC_header_we & sel_evn & "00" & sel_AMC;
1505 when x"7" => AMC_if_data <= "000" & evt_buf_full & mon_en & WaitMonBuF & TCPbuf_avl & mon_buf_avl & init_bldr & evn_empty & EventInfo_avl & bldr_fifo_full;
1506 when x"8" => AMC_if_data <= fake_word_cnt;
1507 when x"a" => AMC_if_data <= fake_header_cnt;
1508 when x"c" => AMC_if_data <= fake_evt_cnt;
1509 when x"e" => AMC_if_data <= empty_evt_cnt;
1510 when others => AMC_if_data <= (others => '0');
1513 case AMC_if_ADDR(3 downto 0) is
1514 when x"0" => AMC_if_data <= TTC_status(3)(5 downto 2) & TTC_status(2)(5 downto 2) & TTC_status(1)(5 downto 2) & TTC_status(0)(5 downto 2);
1515 when x"1" => AMC_if_data <= TTC_status(7)(5 downto 2) & TTC_status(6)(5 downto 2) & TTC_status(5)(5 downto 2) & TTC_status(4)(5 downto 2);
1516 when x"2" => AMC_if_data <= TTC_status(11)(5 downto 2) & TTC_status(10)(5 downto 2) & TTC_status(9)(5 downto 2) & TTC_status(8)(5 downto 2);
1517 when x"4" => AMC_if_data <= AMC_TTS(1) & AMC_TTS(0);
1518 when x"5" => AMC_if_data <= AMC_TTS(3) & AMC_TTS(2);
1519 when x"6" => AMC_if_data <= AMC_TTS(5) & AMC_TTS(4);
1520 when x"7" => AMC_if_data <= AMC_TTS(7) & AMC_TTS(6);
1521 when x"8" => AMC_if_data <= AMC_TTS(9) & AMC_TTS(8);
1522 when x"9" => AMC_if_data <= AMC_TTS(11) & AMC_TTS(10);
1523 when x"a" => AMC_if_data <= evt_cnt(1) & evt_cnt(0);
1524 when x"b" => AMC_if_data <= enRstAMC_link & "00000" & AllEventBuilt_i & AllEventBuilt_i & evt_cnt(2);
1525 when x"c" => AMC_if_data <= x"0" & AMC_TTS_RQST(3) & AMC_TTS_RQST(2) & AMC_TTS_RQST(1) & AMC_TTS_RQST(0);
1526 when x"d" => AMC_if_data <= x"0" & AMC_TTS_RQST(7) & AMC_TTS_RQST(6) & AMC_TTS_RQST(5) & AMC_TTS_RQST(4);
1527 when x"e" => AMC_if_data <= x"0" & AMC_TTS_RQST(11) & AMC_TTS_RQST(10) & AMC_TTS_RQST(9) & AMC_TTS_RQST(8);
1528 when others => AMC_if_data <= (others => '0');
1531 case AMC_if_ADDR(3 downto 0) is
1532 when x"0" => AMC_if_data <= badEventCRC_cntr(0);
1533 when x"2" => AMC_if_data <= badEventCRC_cntr(1);
1534 when x"4" => AMC_if_data <= badEventCRC_cntr(2);
1535 when x"6" => AMC_if_data <= badEventCRC_cntr(3);
1536 when x"8" => AMC_if_data <= badEventCRC_cntr(4);
1537 when x"a" => AMC_if_data <= badEventCRC_cntr(5);
1538 when x"c" => AMC_if_data <= badEventCRC_cntr(6);
1539 when x"e" => AMC_if_data <= badEventCRC_cntr(7);
1540 when others => AMC_if_data <= (others => '0');
1543 case AMC_if_ADDR(3 downto 0) is
1544 when x"0" => AMC_if_data <= badEventCRC_cntr(8);
1545 when x"2" => AMC_if_data <= badEventCRC_cntr(9);
1546 when x"4" => AMC_if_data <= badEventCRC_cntr(10);
1547 when x"6" => AMC_if_data <= badEventCRC_cntr(11);
1548 when x"8" => AMC_if_data <= EventBuiltCnt(0);
1549 when x"a" => AMC_if_data <= EventBuiltCnt(1);
1550 when x"c" => AMC_if_data <= EventBuiltCnt(2);
1551 when others => AMC_if_data <= (others => '0');
1553 when "110" | "111" =>
1554 if(AMC_if_ADDR(0) = '0')then
1555 AMC_if_data <= x"00" & "00" & AMC_wc_sum_do;
1557 AMC_if_data <= (others => '0');
1559 when others => AMC_if_data <= (others => '0');
1562 case AMC_if_ADDR(5 downto 4) is
1564 case AMC_if_ADDR(3 downto 0) is
1565 when x"0" => AMC_if_data <= ReSyncFakeEvent_cntr(0);
1566 when x"2" => AMC_if_data <= ReSyncFakeEvent_cntr(1);
1567 when x"4" => AMC_if_data <= ReSyncFakeEvent_cntr(2);
1568 when x"6" => AMC_if_data <= ReSyncFakeEvent_cntr(3);
1569 when x"8" => AMC_if_data <= ReSyncFakeEvent_cntr(4);
1570 when x"a" => AMC_if_data <= ReSyncFakeEvent_cntr(5);
1571 when x"c" => AMC_if_data <= ReSyncFakeEvent_cntr(6);
1572 when x"e" => AMC_if_data <= ReSyncFakeEvent_cntr(7);
1573 when others => AMC_if_data <= (others => '0');
1576 case AMC_if_ADDR(3 downto 0) is
1577 when x"0" => AMC_if_data <= ReSyncFakeEvent_cntr(8);
1578 when x"2" => AMC_if_data <= ReSyncFakeEvent_cntr(9);
1579 when x"4" => AMC_if_data <= ReSyncFakeEvent_cntr(10);
1580 when x"6" => AMC_if_data <= ReSyncFakeEvent_cntr(11);
1581 when others => AMC_if_data <= (others => '0');
1584 case AMC_if_ADDR(3 downto 0) is
1585 when x"0" => AMC_if_data <= RxClkRatio(0)(15 downto 0);
1586 when x"1" => AMC_if_data <= x"00" & "000" & RxClkRatio(0)(20 downto 16);
1587 when x"2" => AMC_if_data <= RxClkRatio(1)(15 downto 0);
1588 when x"3" => AMC_if_data <= x"00" & "000" & RxClkRatio(1)(20 downto 16);
1589 when x"4" => AMC_if_data <= RxClkRatio(2)(15 downto 0);
1590 when x"5" => AMC_if_data <= x"00" & "000" & RxClkRatio(2)(20 downto 16);
1591 when x"6" => AMC_if_data <= RxClkRatio(3)(15 downto 0);
1592 when x"7" => AMC_if_data <= x"00" & "000" & RxClkRatio(3)(20 downto 16);
1593 when x"8" => AMC_if_data <= RxClkRatio(4)(15 downto 0);
1594 when x"9" => AMC_if_data <= x"00" & "000" & RxClkRatio(4)(20 downto 16);
1595 when x"a" => AMC_if_data <= RxClkRatio(5)(15 downto 0);
1596 when x"b" => AMC_if_data <= x"00" & "000" & RxClkRatio(5)(20 downto 16);
1597 when x"c" => AMC_if_data <= RxClkRatio(6)(15 downto 0);
1598 when x"d" => AMC_if_data <= x"00" & "000" & RxClkRatio(6)(20 downto 16);
1599 when x"e" => AMC_if_data <= RxClkRatio(7)(15 downto 0);
1600 when others => AMC_if_data <= x"00" & "000" & RxClkRatio(7)(20 downto 16);
1603 case AMC_if_ADDR(3 downto 0) is
1604 when x"0" => AMC_if_data <= RxClkRatio(8)(15 downto 0);
1605 when x"1" => AMC_if_data <= x"00" & "000" & RxClkRatio(8)(20 downto 16);
1606 when x"2" => AMC_if_data <= RxClkRatio(9)(15 downto 0);
1607 when x"3" => AMC_if_data <= x"00" & "000" & RxClkRatio(9)(20 downto 16);
1608 when x"4" => AMC_if_data <= RxClkRatio(10)(15 downto 0);
1609 when x"5" => AMC_if_data <= x"00" & "000" & RxClkRatio(10)(20 downto 16);
1610 when x"6" => AMC_if_data <= RxClkRatio(11)(15 downto 0);
1611 when x"7" => AMC_if_data <= x"00" & "000" & RxClkRatio(11)(20 downto 16);
1612 when x"8" => AMC_if_data <= x"0" & RxBufUdfErr;
1613 when x"9" => AMC_if_data <= x"0" & RxBufOvfErr;
1614 when others => AMC_if_data <= (others => '0');
1620 process(clk125, RstAMC_link)
1622 if(RstAMC_link = '1')then
1623 rst_AMC_cntr <= '1';
1624 RstAMC_linkSync <= (others => '1');
1625 elsif(clk125'event and clk125 = '1')then
1626 rst_AMC_cntr <= resetCntr or RstAMC_linkSync(3);
1627 RstAMC_linkSync <= RstAMC_linkSync(2 downto 0) & '0';
1635 resetCntr => rst_AMC_cntr,
1637 AMC_if_data => AMC_if_data,
1638 Cntr_DATA => Cntr_DATA,
1639 Cntr_ADDR => Cntr_ADDR,
1640 ipb_addr => ipb_addr
(15 downto 0),
1641 ipb_rdata => AMC_cntr_data
1643 process(UsrClk,reset)
1646 RxBufOvfErr <= (others => '0');
1647 RxBufUdfErr <= (others => '0');
1648 elsif(UsrClk'event and UsrClk = '1')then
1649 for i in 0 to 11 loop
1650 RxBufOvfErr(i) <= (RxBufOvfErr(i) or RxBufOvf(i)) and AMC_en(i) and not test;
1651 RxBufUdfErr(i) <= (RxBufUdfErr(i) or RxBufUdf(i)) and AMC_en(i) and not test;
1655 process(TTC_status, AMC_en)
1657 for i in 0 to 11 loop
1658 AMC_TTC_status(i) <= TTC_status(i)(0) and AMC_en(i);
1659 AMC_TTC_status(i+16) <= TTC_status(i)(1) and AMC_en(i);
1662 TTC_lock <= and_reduce(AMC_TTC_status(27 downto 16) or not AMC_en);
1663 BC0_lock <= AMC_TTC_status(11 downto 0);
1664 AMC_TTC_status(31 downto 28) <= x"0";
1665 AMC_TTC_status(15 downto 12) <= x"0";
1668 if(ipb_clk'event and ipb_clk = '1')then
1669 if(ipb_strobe = '1' and ipb_write = '1' and ipb_addr(14 downto 0) = MON_ctrl_addr(14 downto 0) and ipb_addr(27) = '0')then
1672 ipb_strobe_q <= ipb_strobe;
1675 ipb_ack <= '0' when ipb_addr(27) = '1' or ipb_addr(15 downto 11) /= AMC_reg_addr(15 downto 11) or ipb_write = '1' else ipb_strobe;
1678 if(ipb_addr(15 downto 9) = L1A_buf_addr(15 downto 9))then
1679 ipb_rdata <= L1A_buf_do;
1680 elsif(ipb_addr(14 downto 11) /= AMC_reg_addr(14 downto 11))then
1681 ipb_rdata <= (others => '0');
1683 ipb_rdata <= AMC_cntr_data;
1686 AMC_status(31 downto 28) <= (others => '0');
1687 AMC_status(27 downto 16) <= AMC_data_valid or not AMC_en;
1688 AMC_status(15 downto 12) <= (others => '0');
1691 if(UsrClk'event and UsrClk = '1')then
1692 for i in 0 to 2 loop
1693 EventBuiltToggleSyncRegs(i) <= EventBuiltToggleSyncRegs(i)(2 downto 0) & EventBuiltToggle(i);
1695 for i in 0 to 11 loop
1696 badEventCRCToggleSyncRegs(i) <= badEventCRCToggleSyncRegs(i)(2 downto 0) & badEventCRCToggle(i);
1697 ReSyncFakeEventToggleSyncRegs(i) <= ReSyncFakeEventToggleSyncRegs(i)(2 downto 0) & ReSyncFakeEventToggle(i);
1699 if(CntrRst = '1')then
1700 badEventCRC_cntr <= (others => (others => '0'));
1701 ReSyncFakeEvent_cntr <= (others => (others => '0'));
1702 EventBuiltCnt <= (others => (others => '0'));
1703 fake_word_cnt <= (others => '0');
1704 fake_evt_cnt <= (others => '0');
1705 empty_evt_cnt <= (others => '0');
1706 fake_header_cnt <= (others => '0');
1708 for i in 0 to 11 loop
1709 if(badEventCRCToggleSyncRegs(i)(3) /= badEventCRCToggleSyncRegs(i)(2))then
1710 badEventCRC_cntr(i) <= badEventCRC_cntr(i) + 1;
1712 if(ReSyncFakeEventToggleSyncRegs(i)(3) /= ReSyncFakeEventToggleSyncRegs(i)(2))then
1713 ReSyncFakeEvent_cntr(i) <= ReSyncFakeEvent_cntr(i) + 1;
1716 for i in 0 to 2 loop
1717 if(EventBuiltToggleSyncRegs(i)(3) /= EventBuiltToggleSyncRegs(i)(2))then
1718 EventBuiltCnt(i) <= EventBuiltCnt(i) + 1;
1721 if(fake_WrEn = '1')then
1722 fake_word_cnt <= fake_word_cnt + 1;
1724 if(fake_CRC = '1')then
1725 fake_evt_cnt <= fake_evt_cnt + 1;
1727 if(fake_CRC = '1' and empty_event_flag = '1')then
1728 empty_evt_cnt <= empty_evt_cnt + 1;
1730 if(fake_WrEn = '1' and fake_header = '1')then
1731 fake_header_cnt <= fake_header_cnt + 1;
1734 resetCntr_SyncRegs <= resetCntr_SyncRegs(1 downto 0) & resetCntr;
1735 CntrRst <= (not resetCntr_SyncRegs(2) and resetCntr_SyncRegs(1)) or RstAMC_link;
1738 i_AMC_refclk: IBUFDS_GTE2
1744 I => AMC_REFCLK_P,
-- Connect to package pin AB6
1745 IB => AMC_REFCLK_N
-- Connect to package pin AB5
1750 if(sysclk'event and sysclk = '1')then
1751 if(resetSyncRegs(2) = '1')then
1752 errors <= (others => '0');
1755 if(or_reduce(AMCCRC_bad(0)) = '1' or or_reduce(AMCCRC_bad(1)) = '1' or or_reduce(AMCCRC_bad(2)) = '1')then
1758 if(or_reduce(errors and scale(31 downto 24)) = '1' and rst_init_bldr = '1' and LastBlock = '1')then
1762 case scale(22 downto 19) is
1763 when x"0" => mon_mask <= x"00000";
1764 when x"1" => mon_mask <= x"80000";
1765 when x"2" => mon_mask <= x"c0000";
1766 when x"3" => mon_mask <= x"e0000";
1767 when x"4" => mon_mask <= x"f0000";
1768 when x"5" => mon_mask <= x"f8000";
1769 when x"6" => mon_mask <= x"fc000";
1770 when x"7" => mon_mask <= x"fe000";
1771 when x"8" => mon_mask <= x"ff000";
1772 when x"9" => mon_mask <= x"ff800";
1773 when x"a" => mon_mask <= x"ffc00";
1774 when x"b" => mon_mask <= x"ffe00";
1775 when x"c" => mon_mask <= x"fff00";
1776 when x"d" => mon_mask <= x"fff80";
1777 when x"e" => mon_mask <= x"fffc0";
1778 when others => mon_mask <= x"fffe0";
1780 if(CDF_Header = '1' and init_bldr = '1')then
1781 if(and_reduce(CDF_out(51 downto 32) or mon_mask) = '1')then
1782 sample_event <= '1';
1784 sample_event <= '0';
1787 if(flavor = "G2" and enSFP(3) = '0' and enSFP(2 downto 0) /= "000")then
1790 elsif(resetSyncRegs(2) = '1')then
1791 -- After reset, the first event will always be recorded
1792 mon_en <= not scale(23);
1794 elsif(rst_init_bldr = '1' and LastBlock = '1')then
1795 if(scale(23) = '1')then
1796 mon_en <= sample_event and (mon_buf_avl or WaitMonBuf) and not stop_mon;
1799 mon_en <= (mon_buf_avl or WaitMonBuf) and not stop_mon and (and_reduce(scale_cntr) or pending);
1800 pending <= not mon_buf_avl and (and_reduce(scale_cntr) or pending);
1803 -- if(resetSyncRegs(2) = '1')
then
1804 -- start_wc_reg_wa <= (others => '0');
1805 -- elsif(FirstBlock(0) = '1'
and ce_wc_reg_wa = '1')
then
1806 -- start_wc_reg_wa <= wc_reg_wa;
1808 if(resetSyncRegs(2) = '1' or rst_mon_wc = '1')then
1809 mon_wc(0) <= (others => '0');
1810 elsif(zero_wc(0) = '0' and (header = '1' or sel_CDF = '1' or (more_wc(0) = '0' and rst_init_bldr = '1')))then
1811 mon_wc(0) <= mon_wc(0) + 1;
1812 elsif(AMC_wc_we(0) = '1')then
1813 mon_wc(0) <= mon_wc(0) + ("000" & AMC_wc(12 downto 0)) + 1;
1815 if(resetSyncRegs(2) = '1' or rst_mon_wc = '1')then
1816 mon_wc(1) <= (others => '0');
1817 elsif(zero_wc(1) = '0' and (header = '1' or sel_CDF = '1' or (more_wc(1) = '0' and rst_init_bldr = '1')))then
1818 mon_wc(1) <= mon_wc(1) + 1;
1819 elsif(AMC_wc_we(1) = '1')then
1820 mon_wc(1) <= mon_wc(1) + ("000" & AMC_wc(12 downto 0)) + 1;
1822 if(resetSyncRegs(2) = '1' or rst_mon_wc = '1')then
1823 mon_wc(2) <= (others => '0');
1824 elsif(zero_wc(2) = '0' and (header = '1' or sel_CDF = '1' or (more_wc(2) = '0' and rst_init_bldr = '1')))then
1825 mon_wc(2) <= mon_wc(2) + 1;
1826 elsif(AMC_wc_we(2) = '1')then
1827 mon_wc(2) <= mon_wc(2) + ("000" & AMC_wc(12 downto 0)) + 1;
1829 if(ce_scale = '1')then
1830 if(ld_scale = '1')then
1831 scale_cntr <= not scale(15 downto 0);
1833 scale_cntr <= scale_cntr + 1;
1836 if(resetSyncRegs(2) = '1')then
1839 ce_wc_reg_wa <= '0';
1840 -- MonBufAbort <= '0';
1842 ce_scale <= init_bldr and CDF_Header;
1843 ld_scale <= mon_en or pending;
1844 ce_wc_reg_wa <= rst_init_bldr and AMC_header(0)(64);
1845 -- MonBufAbort <= rst_init_bldr and mon_en and not AMC_header(0)(
64);
1847 rst_mon_wc <= rst_init_bldr;
1848 if(resetSyncRegs(2) = '1' or rst_mon_wc = '1')then
1849 en_block_wc <= (others => '0');
1851 en_block_wc <= en_block_wc or amc_header_we;
1853 for i in 0 to 2 loop
1854 block_wc_we(i) <= rst_init_bldr and en_block_wc(i);
1856 if(resetSyncRegs(2) = '1')then
1857 EventInfoRdDone <= (others => '0');
1858 elsif(sel_AMC = x"b")then
1859 -- EventInfoRdDone <= '1' & AMC_hasData_l;
1860 EventInfoRdDone <= '1' & AMC_hasData;
1862 EventInfoRdDone <= (others => '0');
1864 rst_init_bldr <= EventInfoRdDone(12);
1865 if(resetSyncRegs(2) = '1')then
1866 wc_reg_wa <= (others => '0');
1867 -- elsif(MonBufAbort = '1')then
1868 -- wc_reg_wa <= start_wc_reg_wa;
1869 elsif(ce_wc_reg_wa = '1')then
1870 wc_reg_wa <= wc_reg_wa + 1;
1874 g_mon_evt_wc: for i in 0 to 2 generate
1875 i_mon_evt_wc : BRAM_SDP_MACRO
1877 BRAM_SIZE =>
"18Kb",
-- Target BRAM, "18Kb" or "36Kb"
1878 DEVICE =>
"7SERIES",
-- Target device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
1879 WRITE_WIDTH =>
16,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
1880 READ_WIDTH =>
16,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
1881 DO_REG =>
0,
-- Optional output register (0 or 1)
1882 SIM_COLLISION_CHECK =>
"NONE",
-- Collision check enable "ALL",
"WARNING_ONLY",
1883 -- "GENERATE_X_ONLY" or "NONE"
1884 WRITE_MODE =>
"WRITE_FIRST",
-- Specify "READ_FIRST" for same clock
or synchronous clocks
1885 -- Specify "WRITE_FIRST for asynchrononous clocks on ports
1886 INIT => X"000000000000000000"
) -- Initial values on output port
1888 DO => mon_evt_wcp
(i*16+15
downto i*16
),
-- Output read data port, width defined by READ_WIDTH parameter
1889 DI => mon_wc
(i
),
-- Input write data port, width defined by WRITE_WIDTH parameter
1890 RDADDR => ddr_pa,
-- Input read address, width defined by read port depth
1891 RDCLK => ipb_clk,
-- 1-bit input read clock
1892 RDEN => '1',
-- 1-bit input read port enable
1893 REGCE => '1',
-- 1-bit input read output register enable
1894 RST => MonBuf_empty,
-- 1-bit input reset
1895 WE => "
11",
-- Input write enable, width defined by write port depth
1896 WRADDR => wc_reg_wa,
-- Input write address, width defined by write port depth
1897 WRCLK => sysclk,
-- 1-bit input write clock
1898 WREN => ce_wc_reg_wa
-- 1-bit input write port enable
1901 mon_evt_wc(15 downto 0) <= mon_evt_wcp(15 downto 0) when OneSFP = '1' else mon_evt_wcp(31 downto 16);
1902 mon_evt_wc(31 downto 16) <= x"0000" when OneSFP = '1' else mon_evt_wcp(15 downto 0);
1903 mon_evt_wc(47 downto 32) <= mon_evt_wcp(47 downto 32);
1906 if(sysclk'event and sysclk = '1')then
1907 ThreeSFP <= and_reduce(EnSFP(2 downto 0));
1908 if(EnSFP(2 downto 0) = "011" or EnSFP(2 downto 0) = "101" or EnSFP(2 downto 0) = "110")then
1913 if(EnSFP(2 downto 0) = "001" or EnSFP(2 downto 0) = "010" or EnSFP(2 downto 0) = "100" or EnSFP(2 downto 0) = "000")then
1923 fifo_rst => fifo_rst,
1926 resetFIFO <= reset or or_reduce(not AMC_txfsmresetdone and AMC_en);
1929 if(sysclk'event and sysclk = '1')then
1930 if(resetSyncRegs(2) = '1')then
1931 rst_AMC_wc_sum <= '1';
1932 wr_AMC_wc_sum <= '0';
1934 if(wr_AMC_wc_sum = '1' and ec_sel_AMC = '0')then
1935 rst_AMC_wc_sum <= '0';
1937 wr_AMC_wc_sum <= ec_sel_AMC;
1939 sel_AMC_q <= sel_AMC;
1944 di => AMC_wc_sum_di,
1945 we => AMC_wc_sum_we,
1950 AMC_wc_sum_di <= AMC_wc_sum_do + AMC_wc(5 downto 0) when rst_AMC_wc_sum = '0' else AMC_wc(5 downto 0);
1951 AMC_wc_sum_a(3 downto 0) <= sel_AMC_q when wr_AMC_wc_sum = '1' else AMC_if_ADDR(4 downto 1);