7 use ieee.std_logic_1164.
all;
8 use ieee.numeric_std.
all;
10 LIBRARY infrastructure_lib;
15 DATA_FORMAT_VERSION : std_logic_vector (2 DOWNTO 0) := "001";
16 DELAY_DEPTH : Integer range 0 to 15 := 15
20 rst_clk : in std_logic;
22 eFEX_number : in std_logic_vector(7 downto 0);
24 ifg_duration : IN std_logic_vector(3 downto 0);
25 fpga_tob_enabled : IN std_logic_vector(3 downto 0);
26 pause : IN std_logic_vector(1 downto 0);
28 ttc_rd_en : OUT STD_LOGIC;
29 ttc_dout : IN std_logic_vector(49 DOWNTO 0);
30 ttc_fifo_empty : IN STD_LOGIC;
32 input_fifo_empty : IN std_logic_vector(3 downto 0);
33 fpga_tob_data : IN packet_data_array(3 downto 0);
34 fpga_tob_valid : IN std_logic_vector(3 downto 0);
35 fpga_tob_last : IN std_logic_vector(3 downto 0);
36 fpga_tob_ready : OUT std_logic_vector(3 downto 0);
38 merged_fifo_data : OUT packet_data_array(1 downto 0);
39 merged_fifo_valid : OUT std_logic_vector(1 downto 0);
40 merged_fifo_last : OUT std_logic_vector(1 downto 0);
42 L1A_seen : OUT STD_LOGIC;
43 Last_L1ID_merged : OUT std_logic_vector(31 downto 0);
44 TOB_packet_merged_bus : OUT std_logic_vector(3 downto 0);
45 TOB_packet_missing_bus : OUT std_logic_vector(3 downto 0);
46 debug_packet_created_bus : OUT std_logic_vector(3 downto 0)
54 DEBUG_FORMAT_VERSION :
std_logic_vector (
2 DOWNTO 0) := "
001"
58 rst_clk :
in std_logic;
60 ttc_info :
IN std_logic_vector(
49 DOWNTO 0);
61 ttc_valid :
IN std_logic;
63 input_fifo_empty :
IN std_logic;
64 input_tob_data :
IN std_logic_vector(
63 downto 0);
65 input_tob_valid :
IN std_logic;
66 input_tob_last :
IN std_logic;
67 input_tob_ready :
OUT std_logic;
69 output_fifo_data :
OUT packet_data_array(
1 downto 0);
70 output_fifo_valid :
OUT std_logic_vector(
1 downto 0);
71 output_fifo_last :
OUT std_logic_vector(
1 downto 0);
72 output_fifo_ready :
IN std_logic_vector(
1 downto 0);
74 TOB_packet_ready :
OUT std_logic;
75 TOB_packet_to_merge :
OUT std_logic;
76 TOB_packet_missing :
OUT std_logic;
77 debug_packet_created :
OUT std_logic
79 end Component efex_tob_processer;
82 generic(NSRC:
positive :=
4);
85 rst_clk :
in std_logic;
86 packet_merger_start :
in std_logic := '
0';
87 packet_merger_enabled :
IN std_logic_vector(NSRC
-1 downto 0);
88 packet_merger_source :
OUT std_logic_vector(
2 downto 0);
91 packet_merger_valid :
IN std_logic_vector(NSRC
-1 downto 0);
92 packet_merger_last :
IN std_logic_vector(NSRC
-1 downto 0);
93 packet_merger_ready :
OUT std_logic_vector(NSRC
-1 downto 0);
96 packet_valid :
OUT std_logic;
97 packet_last :
OUT std_logic;
98 packet_sub_last :
OUT std_logic;
99 packet_ready :
IN std_logic
104 generic(NSRC:
positive :=
4);
107 rst_clk :
in std_logic;
109 eFEX_number :
in std_logic_vector(
7 downto 0);
110 pause :
in std_logic := '
0';
111 packet_mux_enabled :
IN std_logic_vector(NSRC
-1 downto 0);
112 packet_mux_reset :
IN std_logic_vector(NSRC
-1 downto 0);
113 packet_mux_source :
OUT std_logic_vector(
3 downto 0);
116 packet_mux_valid :
IN std_logic_vector(NSRC
-1 downto 0);
117 packet_mux_last :
IN std_logic_vector(NSRC
-1 downto 0);
118 packet_mux_ready :
OUT std_logic_vector(NSRC
-1 downto 0);
121 packet_valid :
OUT std_logic;
122 packet_last :
OUT std_logic;
123 packet_ready :
IN std_logic
129 INIT :
std_logic_vector(
31 downto 0) := (
Others => '
0')
135 A :
in std_logic_vector(
4 downto 0);
139 end COMPONENT SRLC32E;
151 signal state_sig: STATE_TYPE;
152 signal debug_data_bus, tob_data_bus: packet_data_array(3 downto 0);
153 signal debug_valid_bus, debug_last_bus, debug_ready_bus, tob_valid_bus, tob_last_bus, tob_ready_bus: std_logic_vector(3 downto 0);
154 signal ttc_valid_bus, tob_packet_ready_bus, tob_packet_to_merge_bus, tob_good_bus, packet_missing_bus, packet_created_bus: std_logic_vector(3 downto 0);
155 signal tob_packet_data_sig, tob_header_data_sig: std_logic_vector (63 downto 0);
156 signal ttc_read_sig, ttc_valid_sig, tob_packet_valid_sig, tob_packet_last_sig, tob_packet_sub_last_sig: std_logic;
157 signal tob_merger_start_sig, debug_enable_sig, debug_fifo_valid_sig, debug_fifo_last_sig: std_logic;
158 signal fifo_delay_start, fifo_delay_end, ifg_delay_start, ifg_delay_end: std_logic;
159 signal q_i: std_logic_vector(DELAY_DEPTH - 1 downto 0);
160 signal tob_packet_source_sig: std_logic_vector(2 downto 0);
161 signal dummy_sig: std_logic_vector(1 downto 0);
162 signal error_bus: std_logic_vector(5 downto 0);
163 signal merged_fifo_data_sig: packet_data_array(1 downto 0);
164 signal merged_fifo_valid_sig, merged_fifo_last_sig: std_logic_vector(1 downto 0);
169 TOB_sources: for i in 0 to 3 generate
173 DEBUG_FORMAT_VERSION => DATA_FORMAT_VERSION
179 ttc_info => ttc_dout,
180 ttc_valid => ttc_valid_bus
(i
),
182 input_fifo_empty => input_fifo_empty
(i
),
183 input_tob_data => fpga_tob_data
(i
),
184 input_tob_valid => fpga_tob_valid
(i
),
185 input_tob_last => fpga_tob_last
(i
),
186 input_tob_ready => fpga_tob_ready
(i
),
188 output_fifo_data
(0) => tob_data_bus
(i
),
189 output_fifo_data
(1) => debug_data_bus
(i
),
190 output_fifo_valid
(0) => tob_valid_bus
(i
),
191 output_fifo_valid
(1) => debug_valid_bus
(i
),
192 output_fifo_last
(0) => tob_last_bus
(i
),
193 output_fifo_last
(1) => debug_last_bus
(i
),
194 output_fifo_ready
(0) => tob_ready_bus
(i
),
195 output_fifo_ready
(1) => debug_ready_bus
(i
),
197 TOB_packet_ready => tob_packet_ready_bus
(i
),
198 TOB_packet_to_merge => tob_packet_to_merge_bus
(i
),
199 TOB_packet_missing => packet_missing_bus
(i
),
200 debug_packet_created => packet_created_bus
(i
)
203 End generate TOB_sources;
205 TOB_packet_missing_bus <= packet_missing_bus;
206 debug_packet_created_bus <= packet_created_bus;
216 packet_merger_start => tob_merger_start_sig,
217 packet_merger_enabled
(0) => '1',
218 packet_merger_enabled
(4 downto 1) => tob_good_bus,
219 packet_merger_enabled
(5) => '1',
220 packet_merger_source => tob_packet_source_sig,
221 packet_merger_data
(0) => tob_header_data_sig,
222 packet_merger_data
(4 downto 1) => tob_data_bus,
223 packet_merger_data
(5) =>
(Others => '0'
),
224 packet_merger_valid
(0) => '1',
225 packet_merger_valid
(4 downto 1) => tob_valid_bus,
226 packet_merger_valid
(5) => '1',
227 packet_merger_last
(0) => '1',
228 packet_merger_last
(4 downto 1) => tob_last_bus,
229 packet_merger_last
(5) => '1',
230 packet_merger_ready
(0) => dummy_sig
(0),
231 packet_merger_ready
(4 downto 1) => tob_ready_bus,
232 packet_merger_ready
(5) => dummy_sig
(1),
234 packet_valid => tob_packet_valid_sig,
235 packet_last => tob_packet_last_sig,
236 packet_sub_last => tob_packet_sub_last_sig,
240 TOB_Header_block:
process(clk)
241 variable header: std_logic_vector(63 downto 0) := (Others => '0');
243 if rising_edge(clk) then
244 if (ttc_read_sig = '1') then
245 ttc_valid_bus <= fpga_tob_enabled;
247 ttc_valid_bus <= (Others => '0');
249 if (ttc_valid_sig = '1') then
250 header := ttc_dout(43 downto 12) & DATA_FORMAT_VERSION & "0" & x"00" & ttc_dout(11 downto 0) & x"01";
252 Last_L1ID_merged <= ttc_dout(43 downto 12);
256 tob_header_data_sig <= header
262 end process TOB_Header_block;
265 TOB_output_block:
process(clk)
266 variable trailer: std_logic_vector(63 downto 0);
268 if rising_edge(clk) then
269 if (tob_merger_start_sig = '1') then
270 trailer := x"0000000" & "00" & error_bus(5 downto 4) & x"00" & error_bus(3 downto 0) & eFEX_number & x"000";
272 if (tob_packet_source_sig /= "000") and (tob_packet_source_sig /= "101") and (tob_packet_sub_last_sig = '1') then
273 trailer(36 downto 32) := trailer(36 downto 32) or tob_packet_data_sig(36 downto 32);
274 trailer(31 downto 24) := tob_packet_data_sig(31 downto 24);
275 trailer(23 downto 20) := trailer(23 downto 20) or tob_packet_data_sig(23 downto 20);
276 merged_fifo_valid_sig(0) <= '0';
278 merged_fifo_valid_sig(0) <= tob_packet_valid_sig;
280 if (tob_packet_last_sig = '1') then
281 merged_fifo_data_sig(0) <= trailer;
283 merged_fifo_data_sig(0) <= tob_packet_data_sig;
285 merged_fifo_last_sig(0) <= tob_packet_last_sig;
287 end process TOB_output_block;
289 TOB_packet_merged_block:
process(clk)
291 if rising_edge(clk) then
293 if (tob_valid_bus(i) = '1') and (tob_last_bus(i) = '1') and (tob_ready_bus(i) = '1') then
294 TOB_packet_merged_bus(i) <= '1';
296 TOB_packet_merged_bus(i) <= '0';
300 end process TOB_packet_merged_block;
302 TOB_enable_error_block:
process(clk)
303 variable tob_good: std_logic_vector(3 downto 0);
304 variable error: std_logic_vector(5 downto 0);
306 if rising_edge(clk) then
307 if rst_clk = '1' then
308 tob_good := (Others => '0');
309 error := (Others => '0');
311 if (state_sig = idle) then
312 tob_good := (Others => '0');
313 error := (Others => '0');
314 elsif (state_sig = prepare_tobs) then
316 if (tob_packet_to_merge_bus(i) = '1') then
319 if (packet_missing_bus(i) = '1') then
323 if (packet_created_bus(i) = '1') then
330 tob_good_bus <= tob_good
341 end process TOB_enable_error_block;
351 eFEX_number => eFEX_number,
353 packet_mux_enabled => fpga_tob_enabled,
354 packet_mux_reset =>
(Others => '0'
),
355 packet_mux_source =>
OPEN,
357 packet_mux_valid => debug_valid_bus,
358 packet_mux_last => debug_last_bus,
359 packet_mux_ready => debug_ready_bus,
361 packet_valid => debug_fifo_valid_sig,
362 packet_last => debug_fifo_last_sig,
366 merged_fifo_valid_sig(1) <= debug_fifo_valid_sig and debug_enable_sig;
367 merged_fifo_last_sig(1) <= debug_fifo_last_sig;
369 Output_register_block:
process(clk)
371 if rising_edge(clk) then
372 merged_fifo_data <= merged_fifo_data_sig;
373 merged_fifo_valid <= merged_fifo_valid_sig;
374 merged_fifo_last <= merged_fifo_last_sig;
376 end process Output_register_block;
379 Debug_enable_block:
process(clk)
380 variable debug_enable, packet_active: std_logic;
382 if rising_edge(clk) then
383 if (rst_clk = '1') then
385 packet_active := '0';
387 if (debug_fifo_valid_sig = '1') then
388 if (debug_fifo_last_sig = '1') then
389 packet_active := '0';
391 packet_active := '1';
394 if (packet_active = '0') then
395 if (pause(1) = '1') then
402 debug_enable_sig <= debug_enable
408 end process Debug_enable_block;
410 pulse_block:
process(clk)
411 variable ttc_read, tob_merger_start: std_logic;
413 if rising_edge(clk) then
414 if (state_sig = start_event) then
419 if (state_sig = start_merger) then
420 tob_merger_start := '1';
422 tob_merger_start := '0';
424 ttc_read_sig <= ttc_read
429 ttc_valid_sig <= ttc_read_sig
434 tob_merger_start_sig <= tob_merger_start
440 end process pulse_block;
442 ttc_rd_en <= ttc_read_sig;
444 SRLC32E_fifo_delay : SRLC32E
445 generic map (INIT => X"00000000"
)
448 Q31 => fifo_delay_end,
449 A =>
(Others => '1'
),
452 D => fifo_delay_start
455 ifg_delay_strobe : for i in 0 to DELAY_DEPTH - 2 generate
456 SRLC32E_delay_strobe : SRLC32E
462 A =>
(Others => '1'
),
467 end generate ifg_delay_strobe;
469 q_i(0) <= ifg_delay_start;
471 actual_ifg_delay_block:
process(clk)
472 variable input_delay: integer range 0 to 15;
474 if rising_edge(clk) then
475 input_delay := to_integer(unsigned(ifg_duration));
476 if (input_delay > DELAY_DEPTH) then
477 input_delay := DELAY_DEPTH;
479 ifg_delay_end <= q_i(input_delay);
481 end process actual_ifg_delay_block;
483 state_machine:
process(clk)
484 variable next_state: STATE_TYPE := idle;
485 variable processor_ready: std_logic_vector(3 downto 0);
486 variable fifo_delay: unsigned(2 downto 0);
487 variable fifo_start, ifg_start: std_logic;
489 if rising_edge(clk) then
492 if rst_clk = '1' then
494 fifo_delay := (Others => '1');
498 if (input_fifo_empty = x"0") then
499 next_state := start_event;
500 elsif (fifo_delay_end = '1') then
503 next_state := wait_fifos;
506 next_state := prepare_tobs;
508 if (fifo_delay < 7) then
509 fifo_delay := fifo_delay + 1;
513 if (tob_packet_ready_bus(i) = '1') then
514 processor_ready(i) := '1';
517 if (processor_ready = fpga_tob_enabled) then
518 next_state := start_merger;
520 next_state := prepare_tobs;
523 next_state := merge_tobs;
525 if (tob_packet_last_sig = '1') then
529 next_state := merge_tobs;
532 if (ifg_delay_end = '1') then
538 processor_ready := (Others => '0');
539 if (ttc_fifo_empty = '0') and (pause(0) = '0') then
541 if (input_fifo_empty = x"0") or (fifo_delay = "000") then
542 next_state := start_event;
544 next_state := wait_fifos;
546 fifo_delay := fifo_delay - 1;
553 state_sig <= next_state
558 fifo_delay_start <= fifo_start
563 ifg_delay_start <= ifg_start
569 end process state_machine;
MUX to concatenate AXI-stream fragments into single packet...
in packet_merger_data packet_data_array( NSRC- 1 downto 0)
Input signals.
out packet_data std_logic_vector( 63 DOWNTO 0)
FIFO signals.
AXI-stream MUX into packet engine...
in packet_mux_data packet_data_array( NSRC- 1 downto 0)
Input signals.
out packet_data std_logic_vector( 63 DOWNTO 0)
FIFO signals.