eFEX firmware  1.7.3
ATLAS l1-calo - electron and tau feature extraction firmware for eFEX boards

Back to eFEX documentation
fsm_TOBs_to_muxPISO.vhd
Go to the documentation of this file.
1 
102 
103 
104 library IEEE;
105 use IEEE.STD_LOGIC_1164.ALL;
106 
107 use IEEE.NUMERIC_STD.ALL;
108 --use ieee.numeric_std_unsigned;
109 
110 library TOB_rdout_lib;
111 use TOB_rdout_lib.TOB_rdout_ip_pkg.ALL;
112 use TOB_rdout_lib.data_type_pkg.all;
113 
116  Generic
117  (
119  FPGA_NUMBER : integer := 1
120  ) ;
121  Port (
123  TOB_FIFO_sw_rst : in std_logic ;
125  hw_addr : in STD_LOGIC_VECTOR(1 downto 0) ;
127  trigger_slice_in : in STD_LOGIC_VECTOR(3 downto 0) ;
129  rdout_T_TOB_209b_in : in STD_LOGIC_VECTOR(208 downto 0);
131  valid_T_TOB_in : in std_logic ;
133  TOB_type_in : in STD_LOGIC;
135  XTOBs_eg_in : in array_8_of_252b; -- XTOBs {array 8 of [(5*48b) + 5b valid] + XTOB_BCN}
137  valid_XTOBs_eg_in : in STD_LOGIC ;
139  XTOBs_tau_in : in array_8_of_252b; -- XTOBs {array 8 of [(5*48b) + 5b valid] + XTOB_BCN}
141  valid_XTOBs_tau_in : in STD_LOGIC ;
143  clk_280M_in : in STD_LOGIC;
145  shelf_number : in STD_LOGIC_VECTOR (3 downto 0);
147  efex_slot_num : in STD_LOGIC_VECTOR (3 downto 0);
149  TOB_FIFO_empty_in : in std_logic ;
151  TOB_prog_full_flag_in : in std_logic ;
153  DPR_locations_to_rd : in STD_LOGIC_VECTOR (2 downto 0);
155  read_on_err_in : in STD_LOGIC;
157  FIFO_BCN_in : in STD_LOGIC_VECTOR (11 downto 0);
159  FIFO_L1A_ID : in STD_LOGIC_VECTOR (23 downto 0);
161  FIFO_L1A_ID_EXT : in STD_LOGIC_VECTOR (7 downto 0);
163  BCN_FIFO_valid_in : in STD_LOGIC;
165  LO_FIFO_prog_full_in : in std_logic ;
167  LO_FIFO_data_count_in : in STD_LOGIC_VECTOR (12 downto 0) ;
169  frame_cntr_en : out STD_LOGIC;
171  BCN_FIFO_rd_en_out : out STD_LOGIC;
173  BCN_FIFO_prog_full_in : in STD_LOGIC;
175  TOB_rdout_fifo_rd_en_out : out STD_LOGIC;
177  TOB_out_valid : out STD_LOGIC;
179  TOB_out_is_char : out STD_LOGIC;
181  TOBs_out : out STD_LOGIC_VECTOR (31 downto 0);
183  TOB_safe_mode_out : out STD_LOGIC;
185  tob_data_mux_fsm : out STD_LOGIC_VECTOR (7 downto 0)
186  );
187 
189 
191 architecture Behavioral of fsm_TOBs_to_muxPISO is
192 
193  type FPGA_mapping_array is array(3 downto 0) of std_logic_vector(1 downto 0);
194  constant FPGA_mapping : FPGA_mapping_array := ("10", "01", "11", "00") ; -- HW address to processor number
195 
196  signal TOB_out_valid_i : std_logic;
197  signal TOB_rdout_fifo_rd_en_i : std_logic ;
198  signal corrective_trailer : std_logic ;
199 
200  signal BCN_FIFO_rd_en_i : std_logic ;
201  signal BCN_FIFO_valid_in_i : std_logic ;
202 
203  signal slice_count_i : unsigned (2 downto 0):= (others => '0');
204  signal link_err_flg_in_i : STD_LOGIC_VECTOR(3 downto 0):= (others => '0');
205  signal TOB_BCN_in_i : STD_LOGIC_VECTOR(7 downto 0):= (others => '0');
206  signal FIFO_BCN_in_i : STD_LOGIC_VECTOR(11 downto 0):= (others => '0');
207  signal XTOB_eg_BCN_in_i : std_logic_vector (7 downto 0):= (others => '0');
208  signal XTOB_hdr_BCN_in_i : std_logic_vector (7 downto 0):= (others => '0');
209  signal XTOB_tau_BCN_in_i : std_logic_vector (7 downto 0):= (others => '0');
210  signal FIFO_L1A_ID_i : STD_LOGIC_VECTOR(23 downto 0):= (others => '0');
211  signal FIFO_L1A_ID_EXT_i : STD_LOGIC_VECTOR(7 downto 0):= (others => '0');
212 
213  signal TOBs_out_i : STD_LOGIC_VECTOR(31 downto 0):= (others => '0');
214 
215  signal TOB_out_is_char_i : std_logic ;
216  signal write_in_LO_FIFO_i : std_logic ;
217 
218  signal CLK_280M_i : std_logic ;
219 
220  signal cntr_rst_i : std_logic ;
221  signal TOB_cntr_rst : std_logic ;
222  signal T_TOB_cntr_en_i : std_logic := '0' ;
223  signal T_TOB_cntr_i : std_logic_vector(3 downto 0) := (others => '0');
224  signal T_TOB_cntr_1dly : std_logic_vector(3 downto 0) := (others => '0');
225 
226  signal XTOB_eg_cntr_en_i : std_logic := '0' ;
227  signal XTOB_eg_cntr_i : std_logic_vector(6 downto 0) := (others => '0');
228  signal XTOB_eg_cntr_1dly : std_logic_vector(6 downto 0) := (others => '0');
229  signal XTOB_tau_cntr_en_i : std_logic := '0' ;
230  signal XTOB_tau_cntr_i : std_logic_vector(6 downto 0) := (others => '0');
231  signal XTOB_tau_cntr_1dly : std_logic_vector(6 downto 0) := (others => '0');
232 
233  signal trailer_cntr_en : std_logic ;
234  signal payld_cntr_rst : std_logic ;
235  signal payld_cntr_rst_i : std_logic ;
236  signal payld_cntr_en : std_logic := '0' ;
237  signal TOB_payld_cntr_i : std_logic_vector(11 downto 0) := (others => '0');
238  signal TOB_payld_cntr_1dly : std_logic_vector(11 downto 0) := (others => '0');
239 
240  signal frame_cntr_en_i : std_logic ;
241  signal slice_no_txed : std_logic_vector(2 downto 0) := (others => '0'); -- slice number transmitted
242 
243  signal T_TOB_eg_i : std_logic_vector(191 downto 0) := (others => '0');
244  signal T_TOB_eg_valid_i : std_logic_vector(5 downto 0) := (others => '0');
245 -- signal FIFO_output_valid_i : std_logic ;
246  signal valid_XTOBs_eg_i : std_logic ;
247  signal valid_XTOBs_tau_i : std_logic ;
248 
249  signal XTOB_eg_i : array_8_of_240b; -- XTOBs e/g {array 8 of [(5*48b) + 5b valid]};
250  signal XTOB_eg_valid_i : array_8_of_5b ; -- std_logic_vector(39 downto 0);
251  signal XTOB_tau_i : array_8_of_240b; -- XTOBs tau {array 8 of [(5*48b) + 5b valid]};
252  signal XTOB_tau_valid_i : array_8_of_5b; -- std_logic_vector(39 downto 0);
253 
254  signal safe_mode_i : std_logic ;
255  signal miss_sop_i : std_logic ; -- signal to miss SOP for multi-slice readout
256  signal wr_en_i : std_logic ; -- enable write into link output fifo when not pfull
257 
258  TYPE STATE_TYPE IS (
259  idle, idle_1, wait1, wait2, wait3, wait4, wait5,
260  err_sop, err_eop,
261  norm_sop1, norm_sop2, norm_tlr, norm_eop,
262  rd_fifo, sub_trl_1, sub_trl_2,
263  rdout_T_TOB_eg,
264  rdout_XTOB_eg_a0, rdout_XTOB_eg_a, rdout_XTOB_eg_b, rdout_XTOB_tau_a0, rdout_XTOB_tau_a, rdout_XTOB_tau_b
265  );
266 
267  SIGNAL current_state : STATE_TYPE;
268  signal i : integer range 0 to 9; -- used to index TOB valid flag
269 -- signal j, n : integer range 0 to 9; -- used to index TOB valid flag
270  signal m_s_count : integer range 0 to 7; -- used to count number of multi slice data 1 to 5
271 
272 -- ####### attributes ########
273  attribute keep : string ;
274  attribute max_fanout : integer;
275 
276 -- attribute keep of i : signal is "true" ;
277 -- attribute max_fanout of i : signal is 30;
278 -- attribute keep of TOBs_out_i : signal is "true" ;
279 -- attribute max_fanout of TOBs_out_i : signal is 30;
280 -- attribute keep of TOB_rdout_fifo_rd_en_i : signal is "true" ;
281 -- attribute max_fanout of TOB_rdout_fifo_rd_en_i : signal is 30;
282 -- attribute keep of TOB_FIFO_sw_rst : signal is "true" ;
283 -- attribute max_fanout of TOB_FIFO_sw_rst : signal is 30;
284 -- attribute keep of write_in_LO_FIFO_i : signal is "true" ;
285 -- attribute max_fanout of write_in_LO_FIFO_i : signal is 30;
286 -- attribute keep of wr_en_i : signal is "true" ;
287 -- attribute max_fanout of wr_en_i : signal is 30;
288 -- attribute keep of TOB_FIFO_empty_in : signal is "true" ;
289 -- attribute max_fanout of TOB_FIFO_empty_in : signal is 30;
290 -- attribute keep of LO_FIFO_prog_full_in : signal is "true" ;
291 -- attribute max_fanout of LO_FIFO_prog_full_in : signal is 30;
292 -- attribute keep of TOB_prog_full_flag_in : signal is "true" ;
293 -- attribute max_fanout of TOB_prog_full_flag_in : signal is 30;
294 -- attribute keep of valid_XTOBs_eg_i : signal is "true" ;
295 -- attribute max_fanout of valid_XTOBs_eg_i : signal is 30;
296 -- #######################################
297 
298 begin
299 
300  -- input ports
301  corrective_trailer <= '0'; -- set corrective_trailer to ZERO
302  CLK_280M_i <= CLK_280M_in ;
303 
304  -- output ports
305  frame_cntr_en <= frame_cntr_en_i ;
306  BCN_FIFO_rd_en_out <= BCN_FIFO_rd_en_i ;
307 
308  TOB_safe_mode_out <= safe_mode_i;
309 
310 -- clk data input to remove timing error
311 U1_clk_280_proc : Process (CLK_280M_i)
312  begin
313  if rising_edge (CLK_280M_i) then
314 
315 -- FIFO_output_valid_i <= valid_T_TOB_in OR valid_XTOBs_eg_in OR valid_XTOBs_tau_in;
316  valid_XTOBs_eg_i <= valid_XTOBs_eg_in;
317 
318  -- output ports
319  TOBs_out <= TOBs_out_i ;
320  TOB_out_valid <= TOB_out_valid_i ;
321  TOB_out_is_char <= TOB_out_is_char_i ;
322  TOB_rdout_fifo_rd_en_out <= TOB_rdout_fifo_rd_en_i ;
323  -- input signals
324  FIFO_BCN_in_i <= FIFO_BCN_in ; -- 12b BCN ID from FIFO
325  FIFO_L1A_ID_i <= FIFO_L1A_ID ; -- 24b L1A ID from FIFO
326  FIFO_L1A_ID_EXT_i <= FIFO_L1A_ID_EXT ; -- 8b L1A ID Extended from FIFO
327  BCN_FIFO_valid_in_i <= BCN_FIFO_valid_in ; -- TTC FIFO output is valid
328 
329  T_TOB_eg_i <= rdout_T_TOB_209b_in(191 downto 0) ; -- 6*32=192b TOB data
330  T_TOB_eg_valid_i <= rdout_T_TOB_209b_in(197 downto 192) ; -- 6b Valid flags
331  link_err_flg_in_i <= rdout_T_TOB_209b_in(201 downto 198) ; -- 4 b Error
332  TOB_BCN_in_i <= std_logic_vector( unsigned('0' & rdout_T_TOB_209b_in(208 downto 202))
333  + unsigned(trigger_slice_in) ); -- 7b TOB_BCN + trigger_slice_no
334 
335  T_TOB_cntr_1dly <= T_TOB_cntr_i ;
336  XTOB_eg_cntr_1dly <= XTOB_eg_cntr_i ;
337  XTOB_tau_cntr_1dly <= XTOB_tau_cntr_i ;
338  TOB_payld_cntr_1dly <= TOB_payld_cntr_i ;
339  end if;
340  end process;
341 
342  TOB_cntr_rst <= cntr_rst_i OR TOB_FIFO_sw_rst; -- sw rst already includes RST
343 
344 -- T_TOB_cntr counter, counts the total number of Valid Sorted TOBs.
345 U2_T_TOB_cntr : entity TOB_rdout_lib.cntr_generic
346  generic map(
347  width => 4
348  )
349  Port map (
350  CE => T_TOB_cntr_en_i ,
351  CLK => CLK_280M_i ,
352  RST => TOB_cntr_rst,
353  Q => T_TOB_cntr_i -- count every valid T_TOB e/g
354  );
355 
356 -- XTOB_eg_cntr counter, counts the total number of valid e/g XTOBs.
357 U2_XTOB_eg_cntr : entity TOB_rdout_lib.cntr_generic
358  generic map(
359  width => 7
360  )
361  Port map (
362  CE => XTOB_eg_cntr_en_i ,
363  CLK => CLK_280M_i ,
364  RST => TOB_cntr_rst,
365  Q => XTOB_eg_cntr_i -- count every valid XTOB e/g
366  );
367 
368 -- XTOB_tau_cntr counter, counts the total number of valid tau XTOBs.
369 U2_XTOB_tau_cntr : entity TOB_rdout_lib.cntr_generic
370  generic map(
371  width => 7
372  )
373  Port map (
374  CE => XTOB_tau_cntr_en_i ,
375  CLK => CLK_280M_i ,
376  RST => TOB_cntr_rst,
377  Q => XTOB_tau_cntr_i -- count every valid XTOB tau
378  );
379 
380  payld_cntr_rst <= payld_cntr_rst_i OR TOB_FIFO_sw_rst; -- sw rst already includes RST
381  payld_cntr_en <= T_TOB_cntr_en_i OR XTOB_eg_cntr_en_i OR XTOB_tau_cntr_en_i OR trailer_cntr_en;
382 
383 
384 -- TOB_payld_length counter, counts the total number of payload data inserted between the Header and Trailer of a TOB/XTOB Event.
385 U2_TOB_payld_length : entity TOB_rdout_lib.cntr_generic
386  generic map(
387  width => 12
388  )
389  Port map (
390  CE => payld_cntr_en , -- count every valid data word (32b words)
391  CLK => CLK_280M_i ,
392  RST => payld_cntr_rst,
393  Q => TOB_payld_cntr_i -- count every valid data word
394  );
395 
396 -- This process disables writing to Link Output FIFO when the LO_FULL reaches a specific occupancy level of 0X1FF0.
397 U3A_proc1 : process (CLK_280M_i)
398 begin
399  if rising_edge (CLK_280M_i) then
400  if (unsigned(LO_FIFO_data_count_in) < X"1FF0") then -- 8128 leaves enough space for a Safe Mode event
401  -- if LO_FIFO is nearly FULL then stop reading from de-randomistion FIFO
402  write_in_LO_FIFO_i <= '1';
403  else
404  write_in_LO_FIFO_i <= '0' ;
405  end if;
406  end if;
407  end process;
408 
409 -- select tau or e/g Topo TOB the counter is counting
410  -- FPGA F1 counting Topo TOB e/g
411  -- FPGA F2 counting Topo TOB tau
412  -- FPGA F3 & 4 NOT counting Topo TOBs = ZERO
413 
414  wr_en_i <= write_in_LO_FIFO_i ; -- enable write into link output fifo when not pfull
415 
416 U4_rd_fsm : process (CLK_280M_i)
417  variable k, j : integer range 0 to 10 ; -- used to index TOB valid flag
418 
419 begin
420  if CLK_280M_i'event and CLK_280M_i = '1' then
421  if ( TOB_FIFO_sw_rst = '1' )then -- signal is RST OR TOB_FIFO_sw_rst
422  current_state <= idle ;
423  safe_mode_i <= '0' ;
424  cntr_rst_i <= '1' ; -- force a reset
425  payld_cntr_rst_i <= '1' ; -- force a reset
426  T_TOB_cntr_en_i <= '0' ;
427  XTOB_eg_cntr_en_i <= '0' ;
428  XTOB_tau_cntr_en_i <= '0' ;
429  TOBs_out_i <= (others => '0') ;
430  tob_data_mux_fsm <= X"00";
431  else
432  CASE current_state is
433  when idle =>
434  tob_data_mux_fsm <= X"01";
435  slice_count_i <= unsigned (DPR_locations_to_rd) ; -- multi-slice read register 1 to 5
436  miss_sop_i <= '0' ; -- do not miss SOP
437  cntr_rst_i <= '0' ;
438  payld_cntr_rst_i <= '0' ;
439  frame_cntr_en_i <= '0' ;
440  trailer_cntr_en <= '0' ;
441  BCN_FIFO_rd_en_i <= '0' ;
442  TOB_rdout_fifo_rd_en_i <= '0' ;
443  T_TOB_cntr_en_i <= '0' ;
444  XTOB_eg_cntr_en_i <= '0' ;
445  XTOB_tau_cntr_en_i <= '0' ;
446  TOB_out_valid_i <= '0' ;
447  TOB_out_is_char_i <= '0' ;
448  m_s_count <= 0 ;
449  i <= 0 ;
450  j := 0 ;
451  k := 0 ;
452  slice_no_txed <= "000"; -- initially set to 1
453  if (write_in_LO_FIFO_i = '1' ) then -- if LO_FIFO is not full, less than X"1FF0"
454  if (TOB_FIFO_empty_in = '0') then -- if TOB/XTOB FIFOs are not empty
455  current_state <= idle_1 ;
456  else
457  current_state <= idle ;
458  end if;
459  end if;
460 
461  when idle_1 => -- wait 1 clk for fifo empty output
462  tob_data_mux_fsm <= X"02";
463  if (TOB_FIFO_empty_in = '0') then -- if TOB FIFOs are not empty
464  -- if LO_FIFO is partial FULL AND TOB_FIFO_prog_full NOT set, then pause
465  if (LO_FIFO_prog_full_in = '1' AND TOB_prog_full_flag_in = '0') then
466  current_state <= idle_1 ;
467  else
468  TOB_rdout_fifo_rd_en_i <= '1'; -- read data from fifos
469  BCN_FIFO_rd_en_i <= '1' ; -- read data from BCN fifo
470  current_state <= wait5 ;
471  end if;
472  else
473  current_state <= idle ;
474  end if;
475 
476  when wait5 => -- wait 1 clk for fifo output
477  tob_data_mux_fsm <= X"03";
478  trailer_cntr_en <= '0' ;
479  cntr_rst_i <= '0' ;
480  TOB_out_is_char_i <= '0';
481  TOB_out_valid_i <= '0' ;
482  BCN_FIFO_rd_en_i <= '0' ; -- read data from BCN fifo
483  TOB_rdout_fifo_rd_en_i <= '0'; -- read data from fifos
484 
485  -- if BCN_L1A FIFO is partial FULL, then SAFE MODE, empty FIFOs
486  if (BCN_FIFO_prog_full_in = '1') then
487  safe_mode_i <= '1' ; -- enable safe mode flag
488 -- TOB_rdout_fifo_rd_en_i <= '0'; -- read data from fifos
489  current_state <= norm_sop1 ;
490  else -- read data
491 -- TOB_rdout_fifo_rd_en_i <= '0'; -- read data from fifos
492  safe_mode_i <= '0' ; -- disable safe mode flag
493  current_state <= rd_fifo ;
494  end if;
495 
496  when rd_fifo => -- wait 1 clk for fifo output
497  tob_data_mux_fsm <= X"04";
498 -- Use eg XTOB BCN for header, correcting for trigger slice offset
499  XTOB_hdr_BCN_in_i <= std_logic_vector( unsigned ('0' & XTOBs_eg_in(0)(251 downto 245))
500  + unsigned (trigger_slice_in) );
501 
502  XTOB_eg_i(0) <= XTOBs_eg_in(0)(239 downto 0); -- XTOBs {array 8 of [(5*48b)
503  XTOB_eg_i(1) <= XTOBs_eg_in(1)(239 downto 0);
504  XTOB_eg_i(2) <= XTOBs_eg_in(2)(239 downto 0);
505  XTOB_eg_i(3) <= XTOBs_eg_in(3)(239 downto 0);
506  XTOB_eg_i(4) <= XTOBs_eg_in(4)(239 downto 0);
507  XTOB_eg_i(5) <= XTOBs_eg_in(5)(239 downto 0);
508  XTOB_eg_i(6) <= XTOBs_eg_in(6)(239 downto 0);
509  XTOB_eg_i(7) <= XTOBs_eg_in(7)(239 downto 0);
510 
511  XTOB_eg_valid_i(0) <= XTOBs_eg_in(0)(244 downto 240);
512  XTOB_eg_valid_i(1) <= XTOBs_eg_in(1)(244 downto 240);
513  XTOB_eg_valid_i(2) <= XTOBs_eg_in(2)(244 downto 240);
514  XTOB_eg_valid_i(3) <= XTOBs_eg_in(3)(244 downto 240);
515  XTOB_eg_valid_i(4) <= XTOBs_eg_in(4)(244 downto 240);
516  XTOB_eg_valid_i(5) <= XTOBs_eg_in(5)(244 downto 240);
517  XTOB_eg_valid_i(6) <= XTOBs_eg_in(6)(244 downto 240);
518  XTOB_eg_valid_i(7) <= XTOBs_eg_in(7)(244 downto 240);
519 
520  XTOB_eg_BCN_in_i <= '0' & XTOBs_eg_in(0)(251 downto 245);
521 
522  XTOB_tau_i(0) <= XTOBs_tau_in(0)(239 downto 0); -- XTOBs {array 8 of [(5*34b)
523  XTOB_tau_i(1) <= XTOBs_tau_in(1)(239 downto 0);
524  XTOB_tau_i(2) <= XTOBs_tau_in(2)(239 downto 0);
525  XTOB_tau_i(3) <= XTOBs_tau_in(3)(239 downto 0);
526  XTOB_tau_i(4) <= XTOBs_tau_in(4)(239 downto 0);
527  XTOB_tau_i(5) <= XTOBs_tau_in(5)(239 downto 0);
528  XTOB_tau_i(6) <= XTOBs_tau_in(6)(239 downto 0);
529  XTOB_tau_i(7) <= XTOBs_tau_in(7)(239 downto 0);
530 
531  XTOB_tau_valid_i(0) <= XTOBs_tau_in(0)(244 downto 240);
532  XTOB_tau_valid_i(1) <= XTOBs_tau_in(1)(244 downto 240);
533  XTOB_tau_valid_i(2) <= XTOBs_tau_in(2)(244 downto 240);
534  XTOB_tau_valid_i(3) <= XTOBs_tau_in(3)(244 downto 240);
535  XTOB_tau_valid_i(4) <= XTOBs_tau_in(4)(244 downto 240);
536  XTOB_tau_valid_i(5) <= XTOBs_tau_in(5)(244 downto 240);
537  XTOB_tau_valid_i(6) <= XTOBs_tau_in(6)(244 downto 240);
538  XTOB_tau_valid_i(7) <= XTOBs_tau_in(7)(244 downto 240);
539 
540  XTOB_tau_BCN_in_i <= '0' & XTOBs_tau_in(0)(251 downto 245);
541 
542  trailer_cntr_en <= '0' ; -- stop counter counting coming here from sub_tlr_2
543  TOB_rdout_fifo_rd_en_i <= '0' ;
544  TOB_out_valid_i <= '0' ; -- do not save in FIFO
545  if valid_XTOBs_eg_i = '1' then -- if TOBs/XTOBs are valid, write to LO FIFO -- works for all pFPGAs
546  if miss_sop_i = '0' then -- insert SOP
547  current_state <= norm_sop1 ;
548  else -- miss SOP
549  current_state <= rdout_T_TOB_eg ;
550  end if;
551  else -- if no valid TOBs yet, wait
552  current_state <= rd_fifo ; -- stay until FIFO read
553  end if;
554 
555  when norm_sop1 => -- normal data header SOP 1
556  tob_data_mux_fsm <= X"05";
557  -- readout expected + 11b reserved + BCN & K28.1
558  TOB_rdout_fifo_rd_en_i <= '0' ;
559  -- work out trigger slice number by subtracting TOB BCN from internal BCN
560  TOBs_out_i <= "0" & TOB_BCN_in_i(6 downto 0) & XTOB_hdr_BCN_in_i(3 downto 0) & FIFO_BCN_in_i & ch_sop1 ;
561  TOB_out_is_char_i <= '1';
562  TOB_out_valid_i <= '1' ; -- save in FIFO
563  current_state <= norm_sop2 ;
564 
565  when norm_sop2 => -- normal data header SOP 2
566  tob_data_mux_fsm <= X"06";
567  TOBs_out_i <= FIFO_L1A_ID_EXT_i & FIFO_L1A_ID_i ; -- L1A_ID_EXT + L1A ID
568  TOB_out_is_char_i <= '0';
569  TOB_out_valid_i <= '1' ;
570  if ( safe_mode_i = '1' ) then -- if in SAFE MODE or Read on Error mode
571  current_state <= sub_trl_1 ;
572  else -- normal read operation
573  current_state <= rdout_T_TOB_eg ;
574  end if;
575 
576  when rdout_T_TOB_eg => -- normal T_TOB_eg rd out 7 clks
577  tob_data_mux_fsm <= X"07";
578  TOB_out_is_char_i <= '0';
579  T_TOB_cntr_en_i <= T_TOB_eg_valid_i(i) AND wr_en_i;
580  TOBs_out_i <= T_TOB_eg_i((((i*32)+32)-1) downto (i*32));
581  TOB_out_valid_i <= T_TOB_eg_valid_i(i) AND wr_en_i; -- on valid save in FIFO
582  if (i = 5) then -- 6 T TOBs are read out, 7th is ignored
583  i <= 0;
584  current_state <= rdout_XTOB_eg_a0;
585  else
586  current_state <= rdout_T_TOB_eg ;
587  i <= i + 1 ;
588  end if;
589 
590 -- XTOBs e/g array 8 of [(5*64b)
591 -- j = 0 and k = 0
592  when rdout_XTOB_eg_a0 => -- normal X_TOB_eg rd out 80 clks
593  j := 0;
594  k := 0;
595  tob_data_mux_fsm <= X"08";
596  T_TOB_cntr_en_i <= '0'; -- to prevent a 1 on last data to persist
597  XTOB_eg_cntr_en_i <= XTOB_eg_valid_i(j)(k) AND wr_en_i;
598  TOB_out_valid_i <= XTOB_eg_valid_i(j)(k) AND wr_en_i; -- on valid save in FIFO
599  TOBs_out_i <= XTOB_eg_i(j)(31 downto 0);
600  current_state <= rdout_XTOB_eg_b ;
601 
602  when rdout_XTOB_eg_a => -- normal X_TOB_eg rd out 80 clks
603  XTOB_eg_cntr_en_i <= XTOB_eg_valid_i(j)(k) AND wr_en_i;
604  TOB_out_valid_i <= XTOB_eg_valid_i(j)(k) AND wr_en_i; -- on valid save in FIFO
605  TOBs_out_i <= XTOB_eg_i(j)(31 downto 0);
606  current_state <= rdout_XTOB_eg_b ;
607 
608  when rdout_XTOB_eg_b => -- normal X_TOB_eg rd out 80 clks
609  XTOB_eg_cntr_en_i <= XTOB_eg_valid_i(j)(k) AND wr_en_i;
610  TOB_out_valid_i <= XTOB_eg_valid_i(j)(k) AND wr_en_i; -- on valid save in FIFO
611  TOBs_out_i <= XTOB_eg_BCN_in_i(3 downto 0) & shelf_number & efex_slot_num & "0000" & XTOB_eg_i(j)(47 downto 32);
612  XTOB_eg_i(j) <= X"000000000000" & XTOB_eg_i(j)(239 downto 48);
613 -- iterate over j 0 - 7, k 0 - 4
614  if (k = 4) then
615  if (j = 7) then
616  current_state <= rdout_XTOB_tau_a0;
617  else
618  j := j + 1;
619  k := 0;
620  current_state <= rdout_XTOB_eg_a;
621  end if;
622  else
623  k := k + 1;
624  current_state <= rdout_XTOB_eg_a;
625  end if;
626 
627 -- XTOBs tau array 8 of (5*64b)
628 -- j = 0 and k = 0
629  when rdout_XTOB_tau_a0 => -- normal X_TOB_eg rd out 80 clks
630  tob_data_mux_fsm <= X"09";
631  k := 0;
632  j := 0;
633  XTOB_eg_cntr_en_i <= '0' ; -- to prevent a 1 on last data to persist
634  XTOB_tau_cntr_en_i <= XTOB_tau_valid_i(j)(k) AND wr_en_i;
635  TOB_out_valid_i <= XTOB_tau_valid_i(j)(k) AND wr_en_i; -- on valid save in FIFO
636  TOBs_out_i <= XTOB_tau_i(j)(31 downto 0);
637  current_state <= rdout_XTOB_tau_b ;
638 
639  when rdout_XTOB_tau_a => -- normal X_TOB_eg rd out 80 clks
640  XTOB_tau_cntr_en_i <= XTOB_tau_valid_i(j)(k) AND wr_en_i;
641  TOB_out_valid_i <= XTOB_tau_valid_i(j)(k) AND wr_en_i; -- on valid save in FIFO
642  TOBs_out_i <= XTOB_tau_i(j)(31 downto 0);
643  current_state <= rdout_XTOB_tau_b ;
644 
645  when rdout_XTOB_tau_b => -- normal X_TOB_eg rd out 80 clks
646  XTOB_tau_cntr_en_i <= XTOB_tau_valid_i(j)(k) AND wr_en_i;
647  TOB_out_valid_i <= XTOB_tau_valid_i(j)(k) AND wr_en_i; -- on valid save in FIFO
648  TOBs_out_i <= XTOB_tau_BCN_in_i(3 downto 0) & shelf_number & efex_slot_num & "0000" & XTOB_tau_i(j)(47 downto 32);
649  XTOB_tau_i(j) <= X"000000000000" & XTOB_tau_i(j)(239 downto 48);
650 -- iterate over j 0 - 7, k 0 - 4
651  if (k = 4) then
652  if (j = 7) then
653  current_state <= wait1;
654  else
655  j := j + 1;
656  k := 0;
657  current_state <= rdout_XTOB_tau_a;
658  end if;
659  else
660  k := k + 1;
661  current_state <= rdout_XTOB_tau_a;
662  end if;
663 
664  when wait1 => -- wait for delayed counter to be valid in sub_trl_1
665  tob_data_mux_fsm <= X"0A";
666  XTOB_tau_cntr_en_i <= '0' ; -- to prevent a 1 on last data to persist
667  TOB_out_valid_i <= '0' ; -- do not save in FIFO
668 -- TOBs_out_i <= X"00000000" ;
669  current_state <= sub_trl_1; -- wait2 ; -- wait for counter to count up.
670 
671  when wait2 => -- wait for delayed counter to be valid in sub_trl_1
672  tob_data_mux_fsm <= X"0B";
673  trailer_cntr_en <= '0' ;
674  TOB_out_is_char_i <= '0';
675  TOB_out_valid_i <= '0' ;
676  current_state <= sub_trl_1 ; -- wait for counter to count up.
677 
678  when sub_trl_1 => -- ZERO data trailer
679  tob_data_mux_fsm <= X"0C";
680  trailer_cntr_en <= '0' ;
681  cntr_rst_i <= '0' ;
682  TOB_rdout_fifo_rd_en_i <= '0'; -- stop read from FIFO
683  slice_no_txed <= std_logic_vector(to_unsigned(m_s_count,3)); -- 1st slice is ZERO
684  m_s_count <= m_s_count + 1 ; -- increment multi slice readout count
685  TOB_out_valid_i <= '0' ; -- do not save in FIFO
686  TOB_out_is_char_i <= '0';
687  if TOB_payld_cntr_i(0) = '0' OR safe_mode_i = '1' then -- no. of 32b words even so send a ZERO word
688  TOB_out_valid_i <= '1' ;
689  TOBs_out_i <= X"00000000" ;
690  trailer_cntr_en <= '1' ; -- increment the payload counter to count the ZERO word
691  end if;
692  current_state <= sub_trl_2 ;
693 
694  when sub_trl_2 => -- normal data trailer
695  tob_data_mux_fsm <= X"0D";
696  trailer_cntr_en <= '1' ; -- increment the payload counter to count the trailer.
697  -- no. of 32b words is odd so just send trailer which makes even
698  TOB_out_is_char_i <= '1';
699  TOB_out_valid_i <= '1' ;
700  -- 1b err_rd + 7b 0 + 2b FPGA no + 1b TSM + 3b Slice + 6b 64b Tau XTOB + 6b 64b e/g XTOB + 3b 32b TOB cntr + 1b TOB type
701  TOBs_out_i <= '0' & read_on_err_in & FPGA_mapping(to_integer(unsigned(hw_addr))) & safe_mode_i & slice_no_txed &
702  XTOB_tau_cntr_1dly(6 downto 1) & XTOB_eg_cntr_1dly(6 downto 1) & T_TOB_cntr_1dly(2 downto 0) &
703  TOB_type_in & slice_end; -- slice_end = X"5C"
704  i <= 0 ;
705  if m_s_count = slice_count_i then
706  current_state <= wait3 ;
707  else -- if not in Safe Mode, normal read
708  cntr_rst_i <= '1' ; -- reset the TOB counters
709  if safe_mode_i = '0' then
710  miss_sop_i <= '1' ; -- miss SOP for multi-slice readout
711  TOB_rdout_fifo_rd_en_i <= '1'; -- read next slice from FIFO
712  current_state <= wait5 ; -- was idle (just in case fifo is empty ie lost sync with data in
713  else -- if in Safe Mode, empty buffers
714  miss_sop_i <= '1' ; -- miss SOP for multi-slice readout
715  TOB_rdout_fifo_rd_en_i <= '1'; -- read next slice from FIFO
716  current_state <= wait2 ; -- empty next slice in Safe Mode, but allow payload counter to count up
717  end if;
718  end if;
719 
720  when wait3 =>
721  tob_data_mux_fsm <= X"0E";
722  trailer_cntr_en <= '0' ;
723  m_s_count <= 0 ;
724  TOB_out_is_char_i <= '0';
725  TOB_out_valid_i <= '0' ;
726  current_state <= wait4 ; -- wait for counter to count up.
727 
728  when wait4 =>
729  TOB_out_valid_i <= '0' ;
730  current_state <= norm_eop ; -- extra delay to remove timing error.
731 
732  when norm_eop => -- normal end of packet
733  frame_cntr_en_i <= '1' ; -- inclrease frame counter by 1
734  payld_cntr_rst_i <= '1' ; -- reset the pay loadcounters
735  cntr_rst_i <= '1' ; -- reset the TOB counters
736  TOB_out_is_char_i <= '1';
737  TOBs_out_i <= safe_mode_i & "0000" & DPR_locations_to_rd & trigger_slice_in & TOB_payld_cntr_1dly(11 downto 0) & ch_eop ; -- pay load cntr is divided by 2 to show number of 32b owrds
738  TOB_out_valid_i <= '1' ;
739  current_state <= idle ;
740 
741  when others =>
742  NULL;
743  end case;
744  end if;
745  END IF;
746 end process;
747 
748 
749 --U2_ila_TOB_XTOB_in : ila_ipbus_fabric_rd_wr
750 --PORT MAP (
751 -- clk => CLK_280M_i,
752 -- probe0(3 downto 0) => T_TOB_cntr_i , -- 36b
753 -- probe0(4) => T_TOB_cntr_en_i , -- 36b
754 -- probe0(11 downto 5) => XTOB_eg_cntr_i , -- 36b
755 -- probe0(12) => XTOB_eg_cntr_en_i, -- 36b
756 -- probe0(19 downto 13) => XTOB_tau_cntr_i , -- 36b
757 -- probe0(20) => XTOB_tau_cntr_en_i, -- 36b
758 -- probe0(32 downto 21) => TOB_payld_cntr_1dly , -- 36b
759 -- probe0(35 downto 33) => (others => '0') , -- 36b
760 -- probe1(5 downto 0) => T_TOB_eg_valid_i, -- 36b
761 -- probe1(10 downto 6) => XTOB_eg_valid_i(0), -- 36b
762 -- probe1(15 downto 11) => XTOB_eg_valid_i(1), -- 36b
763 -- probe1(20 downto 16) => XTOB_eg_valid_i(2), -- 36b
764 -- probe1(25 downto 21) => XTOB_eg_valid_i(3), -- 36b
765 -- probe1(30 downto 26) => XTOB_eg_valid_i(4), -- 36b
766 -- probe1(35 downto 31) => XTOB_eg_valid_i(5), -- 36b
767 -- probe2(0) => cntr_rst_i , -- 1b
768 -- probe3(0) => payld_cntr_rst_i , -- 1b
769 -- probe4(0) => TOB_FIFO_sw_rst , -- 1b
770 -- probe5(0) => '0', -- 36b
771 -- probe5(5 downto 1) => XTOB_tau_valid_i(0), -- 36b
772 -- probe5(10 downto 6) => XTOB_tau_valid_i(1), -- 36b
773 -- probe5(15 downto 11) => XTOB_tau_valid_i(2), -- 36b
774 -- probe5(20 downto 16) => XTOB_tau_valid_i(3), -- 36b
775 -- probe5(25 downto 21) => XTOB_tau_valid_i(4), -- 36b
776 -- probe5(30 downto 26) => XTOB_tau_valid_i(5), -- 36b
777 -- probe5(35 downto 31) => XTOB_tau_valid_i(6), -- 36b
778 -- probe6(0) => '0', -- 36b
779 -- probe6(5 downto 1) => XTOB_tau_valid_i(7), -- 36b
780 -- probe6(10 downto 6) => XTOB_eg_valid_i(6), -- 36b
781 -- probe6(15 downto 11) => XTOB_eg_valid_i(7), -- 36b
782 -- probe6(35 downto 16) => (others => '0'), -- 36b
783 -- probe7(0) => '0', -- 1b
784 -- probe8(0) => TOB_FIFO_sw_rst , -- 1b
785 -- probe9(0) => '0' -- 1b
786 --);
787 
788 end Behavioral;
Generic Counter for process FPGA.
in CLK STD_LOGIC
Clock signal input.
in CE STD_LOGIC
Enable signal input.
out Q STD_LOGIC_VECTOR( width- 1 downto 0)
Counter Output signal.
in RST STD_LOGIC
Reset signal input.
( 7 downto 0) STD_LOGIC_VECTOR( 4 downto 0) array_8_of_5b
array of 8, holding 5b XTOB_valid_out signlas
( 7 downto 0) STD_LOGIC_VECTOR( 239 downto 0) array_8_of_240b
array of 8, holding 240b XTOB_data_out
( 7 downto 0) STD_LOGIC_VECTOR( 251 downto 0) array_8_of_252b
array of 8, holding XTOB_BCN (7b) & 5b valid & 240b XTOB_data_out
FSM to write Merged TOBs and Local XTOBs (tau & e/g) data to Link Output FIFO for process FPGA 1 and ...
FSM to write Merged TOBs and Local XTOBs (tau & e/g) data to Link Output FIFO for process FPGA 1 and ...
in valid_XTOBs_eg_in STD_LOGIC
XTOBs e/g valid signal.
in TOB_type_in STD_LOGIC
Sorted TOB data readout 32b * 7 in series, only 6 is used - F1 reads e/g TOBs and F2 reads tau TOBs.
in trigger_slice_in STD_LOGIC_VECTOR( 3 downto 0)
Trigger slice number - on L1A.
in DPR_locations_to_rd STD_LOGIC_VECTOR( 2 downto 0)
number of DRPAM locations to read for multi-slice (1 to 5)
in TOB_prog_full_flag_in std_logic
Input prog Full flag of all TOB FIFOs TTC, TOB & XTOB FIFOs.
in BCN_FIFO_prog_full_in STD_LOGIC
BCN & L1A FIFO prog full flag.
out tob_data_mux_fsm STD_LOGIC_VECTOR( 7 downto 0)
Monitor state machine status register.
in rdout_T_TOB_209b_in STD_LOGIC_VECTOR( 208 downto 0)
sorted TOBs 209b = 7b+4b+6b+192b TOB_BCN+ERR+valid+TOBs
in FIFO_L1A_ID_EXT STD_LOGIC_VECTOR( 7 downto 0)
Extended L1A ID from TTC input.
in XTOBs_eg_in array_8_of_252b
XTOBs e/g {array 8 of [(5*64b) + 5b valid]}.
in LO_FIFO_data_count_in STD_LOGIC_VECTOR( 12 downto 0)
Link Output FIFO data count.
in TOB_FIFO_empty_in std_logic
Input empty flag of all TOB FIFOs TTC, TOB & XTOB FIFOs.
out BCN_FIFO_rd_en_out STD_LOGIC
read enable signal to BCN & L1A_ID FIFOs
in shelf_number STD_LOGIC_VECTOR( 3 downto 0)
shelf number input
in efex_slot_num STD_LOGIC_VECTOR( 3 downto 0)
eFEX slot number input
in FIFO_BCN_in STD_LOGIC_VECTOR( 11 downto 0)
Bunch Crossing ID from BCN counter.
out TOB_rdout_fifo_rd_en_out STD_LOGIC
read enable signal to all TOB/XTOB FIFOs
out TOB_out_valid STD_LOGIC
sorted TOBsXTOBs data valid signal to Link_outpout_FIFO
in FIFO_L1A_ID STD_LOGIC_VECTOR( 23 downto 0)
L1A ID from TTC input.
FPGA_NUMBER integer := 1
Integer used to distinguish different FPGAs having a slightly different firmware.
in BCN_FIFO_valid_in STD_LOGIC
Data from TTC FIFO is valid.
in hw_addr STD_LOGIC_VECTOR( 1 downto 0)
FPGA Hardware Address.
in valid_XTOBs_tau_in STD_LOGIC
XTOBs tau valid signal.
in LO_FIFO_prog_full_in std_logic
Link Output FIFO partial FULL flag to receive RAW calorimeter data.
in valid_T_TOB_in std_logic
sorted TOBs valid signal
out TOB_safe_mode_out STD_LOGIC
Safe Mode operation flag for TOB readout.
out TOB_out_is_char STD_LOGIC
sorted TOBsXTOBs data is CHAR signal to Link_outpout_FIFO
in TOB_FIFO_sw_rst std_logic
TOB Readout FIFO reset Pulse by software command ORed with SYS_RST.
out frame_cntr_en STD_LOGIC
enable frame counter to count up by 1
out TOBs_out STD_LOGIC_VECTOR( 31 downto 0)
sorted TOBsXTOBs 32b data to Link_outpout_FIFO
in read_on_err_in STD_LOGIC
Read RAW data on error flag.
in clk_280M_in STD_LOGIC
280MHz clock input signal
in XTOBs_tau_in array_8_of_252b
XTOBs tau {array 8 of [(5*64b) + 5b valid]}.