1 ------------------------------------------------------
2 -- remove CMC slink status word until the first Header on L0 & L1 before each event
6 -- Dominique Gigi Jan 2011
7 ------------------------------------------------------
8 -- func(0)
0 PCI trigger
14 -- func(1) bit23.
0 event #
15 -- func(2)
0 CRC error gen
17 -- func(3) bit11.
0 Source #
19 -- func(4) bit23.
0 event lenght
20 -- func(5) bit15..
0 wc --
for random distribution
of triggers
21 -- 31..
16 timer between two trigger
23 -- correct some variable to be compliant the the old graphical version
24 ------------------------------------------------------
30 USE ieee.std_logic_1164.
all;
31 use ieee.numeric_std.
all;
32 use ieee.std_logic_unsigned.
all;
34 --USE lpm.lpm_components.all;
35 --USE altera_mf.altera_mf_components.all;
36 --USE altera.altera_primitives_components.all;
42 low_clk : IN ;
-- frequency of 50 Mhz
44 PCIe_func : IN (15 downto 0);
46 PCIe_dti : IN (31 downto 0);
47 PCIe_dto : out (31 downto 0);
53 data : OUT (63 downto 0);
55 Back_p : IN -- Back_p when '0'
76 PCIe_func :
IN (
15 downto 0);
78 PCIe_dti :
IN (
31 downto 0);
79 PCIe_dto :
OUT (
31 downto 0);
87 trig_nb :
OUT (
23 downto 0);
93 component CRC_generator
96 CRC_out :
out (
15 downto 0);
101 --memory used to store WC and trigger distribution (31..
16) WC (words) // (
15..
0) between triggers (bit=
20 ns)
109 PCIe_dt :
IN (
31 downto 0);
110 PCIe_func :
IN (
15 downto 0);
114 wc :
OUT (
15 downto 0);
128 SEED :
IN (
7 DOWNTO 0);
129 rnd :
OUT (
7 DOWNTO 0)
142 signal rnd_dt_O : (63 downto 0);
143 signal rnd_dt_L : (63 downto 0);
144 signal ena_rnd_dt : ;
146 signal BX : (11 downto 0);
147 signal SOURCE : (11 downto 0);
148 signal evt_lenght : (23 downto 0);
--(byte--)
149 signal crc_error : (2 downto 0);
150 signal bit_error : (2 downto 0);
151 signal hd_error : (2 downto 0);
152 signal tr_error : (2 downto 0);
154 signal TR_ena : (3 downto 0);
155 signal PL_ena : (1 downto 0);
156 signal HD_dt : (63 downto 0);
157 signal TR_dt : (63 downto 0);
158 signal PL_dt : (63 downto 0);
159 signal evt_run : (3 downto 0);
160 signal pre_TR : (63 downto 0);
161 signal WC_size : (20 downto 0);
162 signal end_WC : (1 downto 0);
166 signal trig_nb : (23 downto 0);
171 signal wc_rnd : (15 downto 0);
172 signal trigger_rnd : ;
173 signal pseudo_reset : (0 downto 0);
174 signal CRC_OUT : (15 downto 0);
175 signal CRC_val : (15 downto 0);
177 signal CRC_reg : (63 downto 0);
180 signal data_reg : (63 downto 0);
182 signal PCIe_dto_trg : (31 downto 0);
183 signal PCIe_dto_local: (31 downto 0);
185 signal Byte_rnd : (7 downto 0);
186 signal Rst_PCIclk : ;
187 signal Rst_Evtclk : ;
188 signal Rst_lowclk : ;
189 --***********************************************************************
190 --**********************<< BEGIN >>*************************
191 --***********************************************************************
193 --/***************** resync reset to clocks domain******************
198 Reset_sync => Rst_PCIclk
205 Reset_sync => Rst_Evtclk
212 Reset_sync => Rst_lowclk
216 --*************** Sync Back_pressure ************************
217 process(Rst_Evtclk,evt_clk)
219 if Rst_Evtclk = '0' then
221 elsif rising_edge(evt_clk) then
222 LFF_D <= Back_p;
-- Back_p when '0'
227 ena_rnd_dt <= '1' when LFF_D = '1' and evt_run(2) = '1' else '0';
229 --################## Pseudo random data with 8 times same bytes ###################
235 LOAD_SEED => evt_run
(0),
240 rnd_dt_L(63 downto 56) <= Byte_rnd;
241 rnd_dt_L(55 downto 48) <= Byte_rnd;
242 rnd_dt_L(47 downto 40) <= Byte_rnd;
243 rnd_dt_L(39 downto 32) <= Byte_rnd;
244 rnd_dt_L(31 downto 24) <= not(Byte_rnd);
245 rnd_dt_L(23 downto 16) <= not(Byte_rnd);
246 rnd_dt_L(15 downto 08) <= not(Byte_rnd);
247 rnd_dt_L(07 downto 00) <= not(Byte_rnd);
250 --*********************************************************************************
251 --***********************<< error generator >> ***********************************
252 --******** decoding PCIe functions
253 process(Rst_PCIclk,PCIe_clk)
255 if Rst_PCIclk = '0' then
260 elsif rising_edge(PCIe_clk) then
265 if PCIe_cs = '1' AND PCIe_func(6) = '1' AND PCIe_wen = '1' then
266 crc_error(0) <= PCIe_dti(0);
267 bit_error(0) <= PCIe_dti(1);
268 hd_error(0) <= PCIe_dti(2);
269 tr_error(0) <= PCIe_dti(3);
280 input => crc_error
(0),
281 output => crc_error
(1) );
288 input => bit_error
(0),
289 output => bit_error
(1) );
297 input => hd_error
(0),
298 output => hd_error
(1) );
306 input => tr_error
(0),
307 output => tr_error
(1) );
309 process(Rst_Evtclk,evt_clk)
311 if Rst_Evtclk = '0' then
316 elsif rising_edge(evt_clk) then
317 if crc_error(1) = '1' then
319 elsif TR_ena(3) = '1' then
323 if bit_error(1) = '1' then
325 elsif evt_run(3) = '1' and LFF_D = '1' then
329 if hd_error(1) = '1' then
331 elsif TR_ena(3) = '1' and LFF_D = '1' then
335 if tr_error(1) = '1' then
337 elsif TR_ena(3) = '1' and LFF_D = '1' then
343 end_evt <= TR_ena(3);
345 --*******************************************************************************
346 --**************************<< event gener. >>***********************************
350 Rst_Pciclk => Rst_Pciclk,
351 PCIe_clk => PCIe_clk,
352 PCIe_func => PCIe_func,
353 PCIe_wen => PCIe_wen,
354 PCIe_dti => PCIe_dti,
355 PCIe_dto => PCIe_dto_trg,
357 ttc_trigger => trigger_rnd,
358 Rst_Evtclk => Rst_Evtclk,
360 ena_PCIe => ena_PCIe,
361 run_mode => run_mode,
367 process(Rst_Evtclk,evt_clk)
369 if Rst_Evtclk = '0' then
370 evt_run <= (others => '0');
371 elsif rising_edge(evt_clk) then
372 if evt_run(1) = '1' then
374 elsif LFF_D = '1' AND end_WC(0) = '1' then
378 if evt_run(2) = '1' then
380 elsif end_WC(1) = '1' then
384 evt_run(1) <= evt_run(0);
385 evt_run(0) <= trigger;
391 RST_lowClk => RST_lowClk,
393 RST_PCIClk => RST_PCIClk,
394 PCIe_clk => PCIe_clk,
396 PCIe_func => PCIe_func,
398 PCIe_wen => PCIe_wen,
401 RST_EvtClk => RST_EvtClk,
403 trigger => trigger_rnd,
407 --*******************************************************************************
408 --************************** << Header >> ***********************************
409 process(Rst_PCIclk,PCIe_clk)
411 if Rst_PCIclk = '0' then
412 BX <= (others => '0');
413 SOURCE <= (others => '0');
414 evt_lenght <= (others => '0');
415 elsif rising_edge(PCIe_clk) then
416 if PCIe_cs = '1' and PCIe_func(3) = '1' AND PCIe_wen = '1' then
417 BX <= PCIe_dti(27 downto 16);
418 SOURCE <= PCIe_dti(11 downto 00);
420 if PCIe_cs = '1' and PCIe_func(4) = '1' AND PCIe_wen = '1' then
421 evt_lenght <= PCIe_dti(23 downto 00);
424 PCIe_dto_local <= (others => '0');
425 if PCIe_func(3) = '1' then
426 PCIe_dto_local(11 downto 0) <= BX;
427 PCIe_dto_local(27 downto 16) <= SOURCE;
428 elsif PCIe_func(4) = '1' then
429 PCIe_dto_local(23 downto 00) <= evt_lenght;
434 PCIe_dto <= PCIe_dto_local when PCIe_func(4) = '1' or PCIe_func(3) = '1' else PCIe_dto_trg;
436 process(Rst_Evtclk,evt_clk)
438 if Rst_Evtclk = '0' then
440 elsif rising_edge(evt_clk) then
441 HD_ena <= evt_run(0);
443 HD_dt(63 downto 56) <= x"50";
444 HD_dt(55 downto 32) <= trig_nb;
445 HD_dt(31 downto 20) <= BX;
446 HD_dt(19 downto 08) <= SOURCE;
447 HD_dt(07 downto 00) <= x"00";
452 --*******************************************************************************
453 --************************** << PayLoad >> ***********************************
454 pseudo_reset(0) <= '0' when (end_WC(0) = '1' AND LFF_D = '1') else '1';
456 process(pseudo_reset(
0),evt_clk)
458 if pseudo_reset(0) = '0' then
460 elsif rising_edge(evt_clk) then
463 elsif evt_run(2) = '1' and LFF_D = '1' then
469 process(Rst_Evtclk,evt_clk)
471 if Rst_Evtclk = '0' then
473 elsif rising_edge(evt_clk) then
474 if PL_ena(0) = '1' and LFF_D = '1' and end_WC(0) = '0' then
476 elsif end_WC(0) = '1' and LFF_D = '1' then
482 process(evt_run(
0),evt_clk)
484 if evt_run(0) = '1' then
485 PL_dt <= (others => '0');
486 elsif rising_edge(evt_clk) then
487 if evt_run(2) = '1' and LFF_D = '1' then
493 --*******************************************************************************
494 --************************** << Trailer >> ***********************************
495 process(Rst_Evtclk,evt_clk)
497 if Rst_Evtclk = '0' then
498 pre_TR <= (others => '0');
499 TR_ena <= (others => '0');
500 elsif rising_edge(evt_clk) then
501 if trigger = '1' then
502 pre_TR(63 downto 56) <= x"A0";
503 if ena_PCIe = '1' then
504 pre_TR(55 downto 53) <= (others => '0');
505 pre_TR(52 downto 32) <= evt_lenght(23 downto 3);
-- value send by PCIe (in bytes) wc used in 63-bit words , it's why we start by '3'
507 pre_TR(55 downto 48) <= "00000000";
508 pre_TR(47 downto 32) <= wc_rnd;
510 pre_TR(31 downto 00) <= x"00000000";
515 TR_ena(3 downto 1) <= TR_ena(2 downto 0);
518 if evt_run(2) = '1' and end_WC(0) = '1' and LFF_D = '1' then
524 TR_dt(63 downto 32) <= pre_TR(63 downto 32);
525 TR_dt(31 downto 16) <= CRC_val;
526 TR_dt(15 downto 00) <= pre_TR(15 downto 00);
529 --*******************************************************************************
530 --**************************<< Event size >>***********************************
531 process(Rst_Evtclk,evt_clk)
533 if Rst_Evtclk = '0' then
534 WC_size <= (others => '0');
535 elsif rising_edge(evt_clk) then
536 if evt_run(0) = '1' then
537 WC_size(20 downto 0) <= pre_TR(52 downto 32);
538 elsif evt_run(2) = '1' and LFF_D = '1' then
539 WC_size <= WC_size - "1";
544 process(trigger,evt_clk)
546 if trigger = '1' then
547 end_WC <=(others => '0');
548 elsif rising_edge(evt_clk) then
550 if end_WC(0) = '1' AND LFF_D = '1' AND evt_run(1) = '1' then
554 if WC_size = "000000000000000000010" AND evt_run(2) = '1' AND LFF_D = '1' then -- WC include Header and trailer (in 64-bit words)
560 --*******************************************************************************
561 --**************************<< CRC compute >>***********************************
562 process(Rst_Evtclk,evt_clk)
564 if Rst_Evtclk = '0' then
566 elsif rising_edge(evt_clk) then
569 elsif PL_ena(1) = '1' then
571 elsif TR_ena(0) = '1' then
576 if HD_ena = '1' OR (PL_ena(1) = '1' AND LFF_D = '1') OR TR_ena(0) = '1' then
582 crc_cmp_comp:CRC_generator
590 CRC_val <= not(CRC_OUT) when crc_error(2) = '1' else CRC_OUT;
593 --**********************************************************************************
594 --******************** << registers output >> ************************************
596 process(Rst_Evtclk,evt_clk)
598 if Rst_Evtclk = '0' then
601 elsif rising_edge(evt_clk) then
603 if (HD_ena = '1' and hd_error(2) = '0') OR (TR_ena(2) = '1' and tr_error(2) = '0') then
608 if HD_ena = '1' OR (PL_ena(1) = '1' AND LFF_D = '1') OR TR_ena(2) = '1' then
614 elsif TR_ena(2) = '1' then
616 elsif LFF_D = '1' and evt_run(2) = '1' then
617 data_reg(63 downto 43) <= PL_dt(63 downto 43);
618 if bit_error(2) = '1' then
619 data_reg(42) <= not(PL_dt(42));
621 data_reg(42) <= PL_dt(42);
623 data_reg(41 downto 00) <= PL_dt(41 downto 00);
630 uctrl <= not(uctrl_reg);