9 USE ieee.std_logic_1164.
all;
10 use ieee.numeric_std.
all;
15 FPGA_NO: std_logic_vector(1 downto 0) := "00";
16 FORMAT_VERSION: std_logic_vector (2 DOWNTO 0) := "001"
20 rst_clk: in std_logic;
23 eFEX_number : IN std_logic_vector(7 downto 0);
25 rd_rst_busy : in STD_LOGIC;
26 m_axis_tvalid : in STD_LOGIC;
27 m_axis_tready : out STD_LOGIC;
28 m_axis_tdata : in STD_LOGIC_VECTOR(31 DOWNTO 0);
29 m_axis_tlast : in STD_LOGIC;
30 m_axis_tuser : in STD_LOGIC_VECTOR(1 DOWNTO 0);
32 data_fifo_data: out std_logic_vector(63 downto 0);
33 data_fifo_valid: out std_logic := '0';
34 data_fifo_last: out std_logic := '0'
54 signal state_sig: STATE_TYPE := init;
55 signal data_from_mgt_fifo_sig, data_from_mgt_fifo_buf, data_output_sig: std_logic_vector(31 downto 0);
56 signal input_length_sig, output_length_sig, slice_length_sig: std_logic_vector(8 downto 0);
57 signal write_block_sig, write_block_buf, we_sig, last_sig, char_is_k_sig, error_from_mgt_sig, TOB_mode_sig, TOB_trailer_OK_sig, valid_sig, valid_buf, data_fifo_valid_sig: std_logic := '0';
58 signal Errors_sig: std_logic_vector(3 downto 0);
59 signal trailer_info_sig: std_logic_vector(11 downto 0);
63 data_fifo_valid <= data_fifo_valid_sig;
65 Input_buffer:
process(clk)
67 if rising_edge(clk) then
68 valid_sig <= m_axis_tvalid and enable
73 valid_buf <= valid_sig
78 data_from_mgt_fifo_sig <= m_axis_tdata
83 data_from_mgt_fifo_buf <= data_from_mgt_fifo_sig
88 char_is_k_sig <= m_axis_tuser(0)
93 error_from_mgt_sig <= m_axis_tuser(1)
99 end process Input_buffer;
102 Ready_block:
process(clk)
103 variable ready: std_logic := '0';
105 if rising_edge(clk) then
106 if (rst_clk = '1') or (rd_rst_busy = '1') then
108 elsif (m_axis_tlast = '1') and (m_axis_tvalid = '1') then
110 elsif state_sig = init then
113 m_axis_tready <= ready
119 end process Ready_block;
122 Output_buffer:
process(clk)
123 variable toggle_bit, data_valid_bit: std_logic := '0';
124 variable data_buffer: std_logic_vector(63 downto 0) := (Others => '0');
125 variable output_length, next_length: unsigned(7 downto 0) := (Others => '0');
127 if rising_edge(clk) then
128 data_valid_bit := '0';
130 data_valid_bit := toggle_bit and write_block_buf;
131 data_buffer := data_output_sig & data_buffer(63 downto 32);
132 toggle_bit := not toggle_bit;
133 elsif state_sig = waiting then
137 if state_sig = new_packet then
138 next_length := (Others => '0');
139 output_length := (Others => '0');
140 elsif (data_valid_bit = '1') then
141 output_length := next_length;
142 next_length := next_length + 1;
144 data_fifo_valid_sig <= data_valid_bit
149 data_fifo_last <= last_sig
154 data_fifo_data <= data_buffer
159 output_length_sig <= std_logic_vector(output_length) & "0"
165 end process Output_buffer;
167 Input_length_block:
process(clk)
168 variable input_length: unsigned(8 downto 0) := (Others => '0');
170 if rising_edge(clk) then
171 if state_sig = new_packet then
172 input_length := (Others => '0');
173 elsif ((state_sig = save_payload) or (state_sig = tob_trailer)) and (valid_sig = '1') then
174 input_length := input_length + 1;
176 input_length_sig <= std_logic_vector(input_length)
182 end process Input_length_block;
184 Slice_length_block:
process(clk)
185 variable slice_length: unsigned(8 downto 0) := (Others => '0');
187 if rising_edge(clk) then
188 if state_sig = new_packet then
189 slice_length := (Others => '0');
190 elsif (char_is_k_sig = '1') and (data_from_mgt_fifo_sig(7 downto 0) = x"5C") then
191 slice_length := (Others => '0');
192 elsif valid_sig = '1' then
193 slice_length := slice_length + 1;
195 slice_length_sig <= std_logic_vector(slice_length)
201 end process Slice_length_block;
203 Trailer_checker:
process(clk)
215 variable expected_length: unsigned(7 downto 0) := (Others => '0');
216 variable TOB_trailer_OK, write_block: std_logic := '0';
218 if rising_edge(clk) then
219 if (valid_sig = '1') then
221 if (char_is_k_sig = '1') and (data_from_mgt_fifo_sig(7 downto 0) = x"5C") then
223 expected_length := unsigned("00" & data_from_mgt_fifo_sig(23 downto 18));
224 expected_length := expected_length + unsigned(data_from_mgt_fifo_sig(17 downto 12));
226 expected_length := expected_length + unsigned(data_from_mgt_fifo_sig(11 downto 10));
228 if (slice_length_sig = std_logic_vector(expected_length) & '1') then
229 TOB_trailer_OK := '1';
231 if (data_from_mgt_fifo_sig(9) = '0') and (slice_length_sig = std_logic_vector(to_unsigned(1, 9))) then
235 elsif (data_from_mgt_fifo_sig(27) = '1') and (slice_length_sig = std_logic_vector(to_unsigned(1, 9))) then
236 TOB_trailer_OK := '1';
238 TOB_trailer_OK := '0';
241 expected_length := (Others => '0');
242 TOB_trailer_OK := '0';
245 TOB_trailer_OK_sig <= TOB_trailer_OK
250 write_block_sig <= write_block
256 write_block_buf <= write_block_sig
262 end process Trailer_checker;
264 Output_Data_engine:
process(clk)
265 variable data_output: std_logic_vector(31 downto 0) := (Others => '0');
266 variable write_data, last, odd_length: std_logic := '0';
267 variable bcn: std_logic_vector(11 downto 0);
268 variable stream_id: std_logic_vector(7 downto 0);
270 if rising_edge(clk) then
271 data_output := (Others => '0');
272 write_data := valid_buf;
276 if TOB_mode_sig = '1' then
279 stream_id := "10" & FPGA_NO & eFEX_number(3 downto 0);
281 if (valid_buf = '1') then
282 data_output := FORMAT_VERSION & "0" & x"00" & data_from_mgt_fifo_buf(19 downto 8) & stream_id;
283 bcn := data_from_mgt_fifo_buf(19 downto 8);
285 when save_payload | tob_trailer =>
286 data_output := data_from_mgt_fifo_buf;
291 when corrective_trailer =>
292 data_output(31 downto 30) := "11";
293 data_output(25 downto 24) := FPGA_NO;
294 data_output(23 downto 12) := bcn;
295 data_output(8 downto 1) := output_length_sig(8 downto 1);
296 data_output(0) := odd_length;
298 when write_trailer =>
299 data_output(31 downto 20) := trailer_info_sig;
300 data_output(19 downto 12) := eFEX_number;
301 data_output(8 downto 0) := output_length_sig;
304 if TOB_mode_sig = '1' then
305 data_output(11 downto 10) := FPGA_NO;
307 data_output(4 downto 1) := Errors_sig;
313 data_output_sig <= data_output
329 end process Output_Data_engine;
331 State_machine:
process(clk)
332 variable TOB_mode, Bad_Packet, Length_Error, BCN_Error, Seen_Trailer: std_logic := '0';
333 variable Errors: std_logic_vector(3 downto 0);
334 variable trailer_info: std_logic_vector(11 downto 0);
335 variable next_state: STATE_TYPE := init;
337 if rising_edge(clk) then
338 if (rst_clk = '1') or (rd_rst_busy = '1') then
342 if error_from_mgt_sig = '1' then
347 Errors := (Others => '0');
348 trailer_info := (Others => '0');
353 if (valid_sig = '1') and (char_is_k_sig = '1') and (data_from_mgt_fifo_sig(7) = '0') and (data_from_mgt_fifo_sig(5 downto 0) = "111100") then
354 if data_from_mgt_fifo_sig(6) = '0' then
356 if (data_from_mgt_fifo_sig(23 downto 20) /= data_from_mgt_fifo_sig(11 downto 8)) or ((FPGA_NO(0) = FPGA_NO(1)) and (data_from_mgt_fifo_sig(30 downto 24) /= data_from_mgt_fifo_sig(14 downto 8))) then
363 next_state := new_packet;
366 if (valid_sig = '1') then
367 next_state := save_payload;
369 When save_payload | tob_trailer =>
370 if (state_sig = tob_trailer) and (valid_buf = '1') and (TOB_trailer_OK_sig = '0') then
373 if (valid_sig = '1') and (char_is_k_sig = '1') then
374 if (data_from_mgt_fifo_sig(7 downto 0) = x"5C") then
375 next_state := tob_trailer;
378 if (data_from_mgt_fifo_sig(19 downto 8) /= "000" & input_length_sig) or (TOB_mode /= Seen_Trailer) or (input_length_sig(0) = '1') then
381 Errors := data_from_mgt_fifo_sig(31) & Bad_Packet & Length_Error & BCN_Error;
382 if (TOB_mode = '1') then
390 trailer_info := data_from_mgt_fifo_sig(23 downto 20) & "0" & data_from_mgt_fifo_sig(26 downto 24) & x"0";
391 if (Errors /= "0000") then
392 trailer_info(to_integer(unsigned(FPGA_NO))) := '1';
395 trailer_info := x"00" & "00" & FPGA_NO;
397 if (Bad_Packet = '0') and (Length_Error = '0') then
398 next_state := write_trailer;
400 if input_length_sig(0) = '1' then
401 next_state := corrective_trailer;
403 next_state := padding;
408 if (valid_sig = '1') then
411 next_state := save_payload;
414 next_state := corrective_trailer;
415 When corrective_trailer =>
416 next_state := write_trailer;
417 When write_trailer =>
418 next_state := write_last;
424 next_state := waiting;
427 state_sig <= next_state
432 TOB_mode_sig <= TOB_mode
442 trailer_info_sig <= trailer_info
448 end process State_machine;
Second version of packet format engine...
Second version of packet format engine...