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