AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
fed_itf.vhd
1 ------------------------------------------------------
2 -- data IN from FED
3 --
4 -- Ver 1.00
5 --
6 -- Dominique Gigi May 2015
7 ------------------------------------------------------
8 -- This is the TOP level of the core for the sender part
9 --
10 ------------------------------------------------------
11 LIBRARY ieee;
12 library work;
13 USE ieee.std_logic_1164.all;
14 use ieee.numeric_std.all;
15 use ieee.std_logic_unsigned.all;
16 use work.mydefs.all;
17 
18 
19 entity fed_itf is
20  generic (generator : boolean := false);
21 port (
22  reset_sysCLK : in std_logic;
23  Greset_sysCLK : in std_logic;
24  sys_clk : in std_logic;
25 
26 -- link data write enable ACTIVE LOW
27  LinkWe : in STD_LOGIC;
28 -- link data header/trailer marker when '0'
29  LinkCtrl : in STD_LOGIC;
30 -- link data
31  LinkData : in STD_LOGIC_VECTOR (63 downto 0);
32 -- link data buffer almost full ACTIVE LOW
33  LinkAlmostFull : out STD_LOGIC;
34 -- link down ACTIVE LOW
35  LinkDown : out STD_LOGIC;
36 --
37  src_ID : in STD_LOGIC_VECTOR (15 downto 0);
38 -- enables error injection to test error recovery
39  inject_err : in STD_LOGIC_VECTOR (17 downto 0);
40 -- Link status data read out
41  read_ce : in STD_LOGIC;
42  addr : in STD_LOGIC_VECTOR (15 downto 0);
43  status_data : out STD_LOGIC_VECTOR (63 downto 0);
44 
45 -- Interface for internal logic
46  reset_CLK : in std_logic;
47  Greset_CLK : in std_logic;
48  clock : in std_logic; -- clock from internal logic
49  block_free : in std_logic; -- almost one block is free
50 
51  data_fed : out std_logic_vector(63 downto 0);
52  block_sz_fed : out std_logic_vector(15 downto 0);
53  wr_ena : out std_logic;
54  start_evt : out std_logic; -- this block is the first for the current event
55  stop_evt : out std_logic; -- this block is the last for the current event -- both can be set
56  end_blk_fed : out std_logic; -- indicate end of the packet (max 4KBytes)
57  -- interface slave to read and write
58  wr_cmd : in std_logic;
59  func : in std_logic_vector(31 downto 0);
60  data_wr : in std_logic_vector(31 downto 0);
61  data_rd : out std_logic_vector(63 downto 0);
62  cnt_evt : out std_logic; -- pulse for each event (on sys_clk);
63  cnt_pckt_rcv : in std_logic_vector(31 downto 0);
64  cnt_pckt_snd : in std_logic_vector(31 downto 0);
65  -- status
66  retransmit_ena : in std_logic;
67  status_state_build_p : in std_logic_vector(31 downto 0);
68  status_state_core : in std_logic_vector(31 downto 0);
69  Serdes_status : in std_logic_vector(31 downto 0)
70  );
71 
72 end fed_itf;
73 
74 architecture behavioral of fed_itf is
75 
76 type fill_blk_type is ( idle,
77  read_fifo,
78  update_para,
79  dummy_a,
80  dummy_b,
81  dummy_c -- dummy state implement du to the CRC check , which take 2 clock cylces more
82  );
83 signal fill_blk,fill_blkNext:fill_blk_type;
84 
85 component FIFO_sync
86  port
87  (
88  aclr : in std_logic; -- active low
89  clk_w : in std_logic;
90  wen : in std_logic;
91  dataw : in std_logic_vector(65 downto 0);
92  almost_f : out std_logic; -- active low
93  clk_r : in std_logic;
94  datar : out std_logic_vector(65 downto 0);
95  ren : in std_logic;
96  empty : out std_logic -- active low
97  );
98 end component;
99 
100 component event_generator
101  port (
102  reset : IN std_logic;
103  low_clk : IN std_logic; -- frequency of 50 Mhz
104  PCIe_clk : IN std_logic;
105  PCIe_func : IN std_logic_vector(15 downto 0);
106  PCIe_wen : IN std_logic;
107  PCIe_dti : IN std_logic_vector(31 downto 0);
108  PCIe_dto : out std_logic_vector(31 downto 0);
109  PCIe_cs : IN std_logic;
110  evt_clk : IN std_logic;
111  wen : OUT std_logic;
112  data : OUT std_logic_vector(63 downto 0);
113  uctrl : OUT std_logic;
114  Back_p : IN std_logic -- Back_p when '0'
115  );
116 end component;
117 
118 component CRC_SLINKx
119  Port (
120  D : in std_logic_vector(63 downto 0);
121  CRC_out : out std_logic_vector(15 downto 0);
122  clk : in std_logic;
123  clear : in std_logic;
124  enable : in std_logic);
125 end component;
126 
127 component freq_measure
128 port (
129  reset : in std_logic;
130  sysclk : in std_logic;-- clock used by the FED to send data and to measure the backpressure
131  base_clk : in std_logic;-- clock base used to measure the sysclk
132  frequency : out std_logic_vector(31 downto 0)-- measure of the frequency)
133 );
134 end component;
135 
136 signal G_rst_rd : std_logic;
137 signal datar_rreg : std_logic_vector(63 downto 0);
138 signal data_out : std_logic_vector(63 downto 0);
139 signal datar : std_logic_vector(65 downto 0);
140 signal datar_reg : std_logic_vector(63 downto 0);
141 signal start_evt_mem : std_logic;
142 signal stop_evt_mem : std_logic;
143 signal end_frag : std_logic;
144 signal finish_blk : std_logic;
145 signal empt_ff : std_logic;
146 
147 signal rd_ff_reg : std_logic;
148 signal del_rd_ff : std_logic_vector(1 downto 0);
149 signal blk_size : std_logic_vector(15 downto 0);
150 signal blk_full : std_logic;
151 signal blk_full_anti : std_logic;
152 
153 signal End_pckt_lgc : std_logic;
154 signal last_word : std_logic;
155 signal sel_test_mode : std_logic;
156 signal wen_tm : std_logic;
157 signal data_tm : std_logic_vector(63 downto 0);
158 signal uctrl_tm : std_logic;
159 signal backpressure_mux : std_logic;
160 signal wen_mux : std_logic;
161 signal data_mux : std_logic_vector(63 downto 0);
162 signal uctrl_mux : std_logic;
163 signal PCIe_dto : std_logic_vector(31 downto 0);
164 signal local_reg : std_logic_vector(31 downto 0);
165 signal LINKDOWN_cell : std_logic;
166 
167 -- use to pipe frgament during the CRC check
168 signal data_r_crc : std_logic_vector(63 downto 0);
169 signal wen_ra : std_logic;
170 
171 signal CRC_Rst : std_logic;
172 signal CRC_Check : std_logic;
173 signal ena_CRC : std_logic;
174 signal ena_CRC_reg : std_logic;
175 signal CRC_frag : std_logic_vector(15 downto 0);
176 signal CRC_cmp : std_logic_vector(15 downto 0);
177 signal data_rb_mux : std_logic_vector(63 downto 0);
178 signal backpressure : std_logic;
179 
180 -- statistic values
181 signal block_counter : std_logic_vector(31 downto 0);
182 signal event_counter : std_logic_vector(31 downto 0);
183 signal data_counter : std_logic_vector(63 downto 0);
184 signal Retransmit_counter : std_logic_vector(31 downto 0);
185 signal cnt_back_p : std_logic_vector(31 downto 0);
186 signal FED_CRC_error_cnt : std_logic_vector(31 downto 0);
187 signal state_machine_status: std_logic_vector(2 downto 0);
188 
189 
190 signal blk_size_reg : std_logic_vector(15 downto 0);
191 signal start_evt_mem_reg : std_logic;
192 signal stop_evt_mem_reg : std_logic;
193 signal End_pckt_lgc_reg : std_logic;
194 
195 signal freq_measure_reg : std_logic_vector(31 downto 0);
196 signal rsyc_test_mode : std_logic_vector(1 downto 0);
197 signal rsyc_DAQON : std_logic_vector(1 downto 0);
198 
199 signal evt_ongoing : std_logic;
200 signal HD_dup : std_logic;
201 signal TR_dup : std_logic;
202 
203 signal track_evt_num : std_logic_vector(23 downto 0);
204 signal found_dup : std_logic;
205  --***********************************************************
206  --********************** BEGIN ****************************
207  --***********************************************************
208 begin
209 
210 
211 -- Set the TEST mode and DAQ_ON with function (6)
212 -- this function will come from optical link send by DAQ side
213 process(Greset_CLK,clock)
214 begin
215  if Greset_CLK = '0' then
216  sel_test_mode <= '0';
217  LINKDOWN_cell <= '0';
218  elsif rising_edge(clock) then
219  if func(6) = '1' and wr_cmd = '1' then
220  sel_test_mode <= data_wr(31);
221  LINKDOWN_cell <= data_wr(30);
222  end if;
223  end if;
224 end process;
225 
226 process(sys_clk)
227 begin
228  if rising_edge(sys_clk) then
229  rsyc_test_mode(1) <= rsyc_test_mode(0);
230  rsyc_test_mode(0) <= sel_test_mode;
231  END IF;
232 end process;
233 
234 
235 local_reg(31) <= sel_test_mode;
236 local_reg(30) <= LINKDOWN_cell;
237 local_reg(29) <= Backpressure;
238 local_reg(28) <= '1' when block_free = '1' else '0';
239 local_reg(27 downto 7) <= (others => '0');
240 local_reg(6) <= found_dup;
241 local_reg(5) <= TR_dup;
242 local_reg(4) <= HD_dup;
243 local_reg(3) <= evt_ongoing;
244 local_reg(2 downto 0) <= state_machine_status(2 downto 0);
245 
246 process(Greset_sysCLK,sys_clk)
247 begin
248  if rising_edge(sys_clk) then
249  rsyc_DAQON(1) <= rsyc_DAQON(0);
250  rsyc_DAQON(0) <= LINKDOWN_cell;
251  end if;
252 end process;
253 
254 LinkDown <= rsyc_DAQON(1);
255 
256 -- measure the frequency used by the fed to send data
257 req_i1:freq_measure
258 port map(
259  reset => Greset_sysCLK,
260  sysclk => sys_clk, -- clock used by the FED to send data and to measure the backpressure
261  base_clk => clock,
262  frequency => freq_measure_reg-- measure of the frequency)
263 );
264 
265 process(Greset_sysCLK,sys_clk)
266 begin
267  if Greset_sysCLK = '0' then
268  cnt_back_p <= (others => '0');
269  elsif rising_edge(sys_clk) then
270  if backpressure_mux = '0' then
271  cnt_back_p <= cnt_back_p + '1';
272  end if;
273  end if;
274 end process;
275 
276 --multiplex data local and Event_gen status/data for read command coming from optical link send by DAQ side
277 
278 process(clock)
279 begin
280  if rising_edge(clock) then
281  data_rd(63 downto 32) <= (others => '0');
282  if func(6) = '1' then
283  data_rd(31 downto 0) <= local_reg;
284  elsif func(7) = '1' then
285  data_rd <= data_counter;
286  elsif func(8) = '1' then
287  data_rd(31 downto 0) <= event_counter;
288  elsif func(9) = '1' then
289  data_rd(31 downto 0) <= block_counter;
290  elsif func(10) = '1' then
291  data_rd(31 downto 0) <= cnt_pckt_rcv;
292  elsif func(11) = '1' then
293  data_rd(31 downto 0) <= status_state_core;
294  elsif func(12) = '1' then
295  data_rd(31 downto 0) <= cnt_pckt_snd;
296  elsif func(13) = '1' then
297  data_rd(31 downto 0) <= status_state_build_p;
298  elsif func(14) = '1' then
299  data_rd(31 downto 0) <= cnt_back_p;
300  elsif func(15) = '1' then
301  data_rd(31 downto 0) <= version;
302  elsif func(16) = '1' then
303  data_rd(31 downto 0) <= Serdes_status;
304  elsif func(17) = '1' then
305  data_rd(31 downto 0) <= Retransmit_counter;
306  elsif func(18) = '1' then
307  data_rd(31 downto 0) <= freq_measure_reg;
308  else
309  data_rd(31 downto 0) <= PCIe_dto;
310  end if;
311  end if;
312 end process;
313 
314 -- status going back to FED side
315 process(sys_clk)
316 begin
317  if rising_edge(sys_clk) then
318  status_data(63 downto 00) <= (others => '0');
319  if addr = x"0001" then
320  status_data(31 downto 0) <= local_reg;
321  elsif addr = x"0002" then
322  status_data <= data_counter;
323  elsif addr = x"0003" then
324  status_data(31 downto 0) <= event_counter;
325  elsif addr = x"0004" then
326  status_data(31 downto 0) <= block_counter;
327  elsif addr = x"0005" then
328  status_data(31 downto 0) <= cnt_pckt_rcv;
329  elsif addr = x"0006" then
330  status_data(31 downto 0) <= status_state_core;
331  elsif addr = x"0007" then
332  status_data(31 downto 0) <= cnt_pckt_snd;
333  elsif addr = x"0008" then
334  status_data(31 downto 0) <= status_state_build_p;
335  elsif addr = x"0009" then
336  status_data(31 downto 0) <= cnt_back_p;
337  elsif addr = x"000A" then
338  status_data(31 downto 0) <= version;
339  elsif addr = x"000B" then
340  status_data(31 downto 0) <= Serdes_status;
341  elsif addr = x"000C" then
342  status_data(31 downto 0) <= Retransmit_counter;
343  elsif addr = x"000D" then
344  status_data(31 downto 0) <= FED_CRC_error_cnt;
345  elsif addr = x"000E" then
346  status_data(31 downto 0) <= freq_measure_reg;
347  end if;
348  end if;
349 end process;
350 
351 -- retransmit counter
352 process(Greset_CLK,clock)
353 begin
354  if Greset_CLK = '0' then
355  Retransmit_counter <= (others => '0');
356  elsif rising_edge(clock) then
357  if retransmit_ena = '1' then
358  Retransmit_counter <= Retransmit_counter + '1';
359  end if;
360  end if;
361 end process;
362 
363 -- local Event generator used to test the link
364 generator_inst:if generator generate
365  i1:event_generator
366  port map(
367  reset => Greset_CLK,
368  low_clk => clock, -- frequency of ??? Mhz
369  PCIe_clk => clock,
370  PCIe_func => func(15 downto 0),
371  PCIe_wen => wr_cmd,
372  PCIe_dti => data_wr,
373  PCIe_dto => PCIe_dto,
374  PCIe_cs => sel_test_mode,
375  evt_clk => sys_clk,
376  wen => wen_tm,
377  data => data_tm,
378  uctrl => uctrl_tm,
379  Back_p => backpressure_mux
380  );
381 
382 end generate;
383 
384 --******************************************************************************
385 -- multiplexer for event DATA
386 -- mux external (FED) and local data path (Event generator) ********************
387 
388 wen_mux <= wen_tm when rsyc_test_mode(1) = '1' and generator else not(LinkWe);
389 data_mux <= data_tm when rsyc_test_mode(1) = '1' and generator else LinkData;
390 uctrl_mux <= uctrl_tm when rsyc_test_mode(1) = '1' and generator else LinkCtrl;
391 
392 --******************************************************************************
393 process(Greset_sysCLK,sys_clk)
394 begin
395  if Greset_sysCLK = '0' then
396  data_counter <= (others => '0');
397  elsif rising_edge(sys_clk) then
398  if wen_mux = '1' then
399  data_counter <= data_counter + '1';
400  end if;
401  end if;
402 end process;
403 
404 --indicate the last word of the EVENT
405 end_frag <= '1' when data_mux(63 downto 60) = x"A" and uctrl_mux = '0' else '0';
406 
407 -- pulse to count the number of event dicover
408 process(Greset_sysCLK,sys_clk)
409 begin
410 if Greset_sysCLK = '0' then
411  cnt_evt <= '0';
412 elsif rising_edge(sys_clk) then
413  cnt_evt <= '0';
414  if end_frag = '1' then
415  cnt_evt <= '1';
416  end if;
417 end if;
418 end process;
419 
420 -- internal FIFO used to chnage the DATA clock domaine
421 internal_FIFO:FIFO_sync --Show A Head ON
422 port map
423  (
424  aclr => Greset_sysCLK,
425  clk_w => sys_clk,
426  wen => wen_mux,
427  dataw(63 downto 0) => data_mux,
428  dataw(64) => uctrl_mux,
429  dataw(65) => end_frag,
430  almost_f => backpressure_mux,
431 
432  clk_r => clock,
433  datar => datar,
434  ren => rd_ff_reg,
435  empty => empt_ff
436  );
437 
438 -- LinkAlmostFull LFF is valid only in no TEST mode otherwise ALLTIME active (low)
439 Backpressure <= '0' when rsyc_test_mode(1) = '1' else backpressure_mux;
440 LinkAlmostFull <= Backpressure;
441 
442 --******************************************************************************
443 -- -******* This state machine is used to read the FIFO and fill the blocks in the CORE_LOGIC.VHD file
444 --state machine clock
445 FED_itf_state_clk:process(Greset_CLK,clock)
446 begin
447 if Greset_CLK = '0' then
448  fill_blk <= idle;
449 elsif rising_edge(clock) then
450  fill_blk <= fill_blkNext;
451 end if;
452 end process;
453 
454 FED_itf_state_machine:process(fill_blk,empt_ff,block_free,blk_full,last_word)
455 begin
456 fill_blkNext <= fill_blk;
457 state_machine_status <= (others => '0');
458 Case fill_blk is
459  -- wait data and free block in CORE_LOGIC.VHD
460 
461  when idle =>
462  state_machine_status(0) <='1';
463  if empt_ff = '0' and block_free = '1' then
464  fill_blkNext <= read_fifo;
465  end if;
466 
467  -- continue until the last word of the EVENT or until no free BLOCK
468  when read_fifo =>
469  state_machine_status(1) <='1';
470  if blk_full = '1' or last_word = '1' then --stop_evt_mem = '1' then
471  fill_blkNext <= update_para;
472  end if;
473 
474  -- unpdate flags and indicate end of block (block full or end_of_event)
475  when update_para =>
476  state_machine_status(2) <='1';
477  fill_blkNext <= dummy_a;
478 
479  when dummy_a =>
480  fill_blkNext <= dummy_b;
481 
482  when dummy_b =>
483  fill_blkNext <= dummy_c; -- take 3 clock to finish to clsoe the buffer, if no the block_free value can be wrong
484 
485  when dummy_c =>
486  fill_blkNext <= idle;
487 
488  when others =>
489  fill_blkNext <= idle;
490  end case;
491 end process;
492 --******************************************************************************
493 
494 last_word <= '1' when rd_ff_reg = '1' and datar(65) = '1' else '0';
495 
496 G_rst_rd <= '0' when Greset_CLK = '0' or empt_ff = '1' or blk_full = '1' else '1';
497 
498 -- automatic read FIFO until the the last word of the EVENT or end of block (change state FILL_BLK)
499 process(G_rst_rd,clock)
500 begin
501 if G_rst_rd = '0' then
502  rd_ff_reg <= '0';
503 elsif rising_edge(clock) then
504  rd_ff_reg <= '0';
505  if fill_blk = read_fifo and last_word = '0' then
506  rd_ff_reg <= '1';
507  end if;
508 end if;
509 end process;
510 
511 --******************************************************************************
512 -- CRC check
513 process(Greset_CLK,clock)
514 begin
515  if Greset_CLK = '0' then
516  CRC_Rst <= '1';
517  ena_crc <= '0';
518  event_counter <= (others => '0');
519  evt_ongoing <= '0';
520  TR_dup <= '0';
521  HD_dup <= '0';
522  found_dup <= '0';
523  track_evt_num <= (others => '0');
524  elsif rising_edge(clock) then
525 
526  if datar(64) = '0' and datar(63 downto 60) = x"A" and rd_ff_reg = '1' then -- UCTRL= 0 + trailer + DATA_valid
527  -- remove the CRC in the trailer to compute the CRC
528  data_r_crc(63 downto 32) <= datar(63 downto 32);
529  data_r_crc(31 downto 16) <= (others => '0');
530  data_r_crc(15 downto 0) <= datar(15 downto 0);
531  else
532  data_r_crc <= datar(63 downto 00);
533  end if;
534  wen_ra <= rd_ff_reg;
535  datar_reg <= datar(63 downto 00);
536 
537  -- create the envelop of the event + counter status
538  if datar(64) = '0' and datar(63 downto 60) = x"5" and rd_ff_reg = '1' then
539  event_counter <= event_counter + '1';
540  evt_ongoing <= '1';
541  if evt_ongoing = '1' then
542  HD_dup <= '1';
543  end if;
544  if track_evt_num = datar(55 downto 32) then
545  found_dup <= '1';
546  end if;
547  track_evt_num <= datar(55 downto 32);
548  end if;
549 
550  -- specify the place of the Trailer
551  ena_CRC_reg <= ena_CRC;
552 
553  ena_crc <= '0';
554  if datar(64) = '0' and datar(63 downto 60) = x"A" and rd_ff_reg = '1' then
555  ena_crc <= '1';
556  crc_frag <= datar(31 downto 16);
557  evt_ongoing <= '0';
558  if evt_ongoing = '0' then
559  TR_dup <= '1';
560  end if;
561  end if;
562 
563  -- reset the CRC machine between 2 fragments
564  if ena_crc = '1' then -- execute a reset when a Trailer appears
565  CRC_Rst <= '1';
566  elsif datar(64) = '0' and datar(63 downto 60) = x"5" and rd_ff_reg = '1' then
567  CRC_Rst <= '0';
568  end if;
569 
570  end if;
571 end process;
572 
573 -- compute the CRC
574 i_crc_check:CRC_SLINKx
575  Port map(
576  clear => CRC_Rst,
577  clk => clock,
578  D => data_r_crc,
579  enable => wen_ra,
580  CRC_out => crc_cmp
581  );
582 
583 -- compare the CRC received and the CRC computed
584 crc_check <= '0' when crc_cmp = crc_frag else '1';
585 
586 -- count number of FED crc error
587 process(Greset_CLK,clock)
588 begin
589  if Greset_CLK = '0' then
590  FED_CRC_error_cnt <= (others => '0');
591  elsif rising_edge(clock) then
592  if ena_CRC_reg = '1' and crc_check = '1' then
593  FED_CRC_error_cnt <= FED_CRC_error_cnt + '1';
594  end if;
595  end if;
596 end process;
597 
598 -- generate FLAG to indicate the beginning and the end of the event for each BLOCK
599 process(Greset_CLK,clock)
600 begin
601 if Greset_CLK = '0' then
602  start_evt_mem <= '0';
603  stop_evt_mem <= '0';
604 elsif rising_edge(clock) then
605  if datar(64) = '0' and datar(63 downto 60) = x"5" and rd_ff_reg = '1' then
606  start_evt_mem <= '1';
607  elsif last_word = '1' then
608  stop_evt_mem <= '1';
609  elsif fill_blk = update_para then --finish_blk = '1' then
610  start_evt_mem <= '0';
611  stop_evt_mem <= '0';
612  end if;
613 end if;
614 end process;
615 
616 -- compute the size of valid data in the BLOCK
617 process(Greset_CLK,clock)
618 begin
619 if Greset_CLK = '0' then
620  blk_size <= (others => '0');
621 elsif rising_edge(clock) then
622  if fill_blk = idle then
623  blk_size <= (others => '0');
624  elsif rd_ff_reg = '1' and blk_full = '0' then
625  blk_size <= blk_size + '1';
626  end if;
627 end if;
628 end process;
629 
630 -- count the number of block used
631 process(Greset_CLK,clock)
632 begin
633  if Greset_CLK = '0' then
634  block_counter <= (others => '0');
635  elsif rising_edge(clock) then
636  if blk_full = '1' or last_word = '1' then
637  block_counter <= block_counter + '1';
638  end if;
639  end if;
640 end process;
641 
642 --flag when the BLOCK is full
643 process(Greset_CLK,clock)
644 begin
645 if Greset_CLK = '0' then
646  blk_full <= '0';
647 elsif rising_edge(clock) then
648  if blk_size = x"01FF" and rd_ff_reg = '1' then --blk_size = 0x200
649  blk_full <= '1';
650  elsif End_pckt_lgc = '1' then
651  blk_full <= '0';
652  end if;
653 end if;
654 end process;
655 
656 End_pckt_lgc <= '1' when fill_blk = update_para else '0';
657 
658 --Pipe data for the CRC check
659 
660 process(clock)
661 begin
662  if rising_edge(clock) then
663  datar_rreg(63 downto 0) <= datar_reg(63 downto 0);
664  blk_size_reg <= blk_size;
665  start_evt_mem_reg <= start_evt_mem;
666  stop_evt_mem_reg <= stop_evt_mem;
667  End_pckt_lgc_reg <= End_pckt_lgc;
668  end if;
669 end process;
670 
671 
672 data_out(63 downto 32) <= datar_rreg(63 downto 32);
673 data_out(31 downto 16) <= crc_cmp when ena_CRC_reg = '1' else datar_rreg(31 downto 16);
674 data_out(15 downto 3) <= datar_rreg(15 downto 3);
675 data_out(2) <= crc_check when ena_CRC_reg = '1' else datar_rreg(2);
676 data_out(1 downto 0) <= datar_rreg(1 downto 0) ;
677 
678 process(clock)
679 begin
680  if rising_edge(clock) then
681  del_rd_ff(1) <= del_rd_ff(0);
682  del_rd_ff(0) <= rd_ff_reg;
683  end if;
684 end process;
685 
686 --Output value to Optical interface
687 block_sz_fed <= blk_size_reg; -- number of data in the block ready to send
688 data_fed <= data_out;
689 wr_ena <= del_rd_ff(1);
690 start_evt <= start_evt_mem_reg; -- flag is set if this block is the first of the event
691 stop_evt <= stop_evt_mem_reg; -- flag is set if this block is the last of the event
692 end_blk_fed <= End_pckt_lgc_reg; -- flag is set at the end of the event
693 
694 end behavioral;