9 use ieee.std_logic_1164.
all;
10 use ieee.numeric_std.
all;
16 rst_clk : in std_logic;
19 packet_valid : IN std_logic;
20 packet_last : IN std_logic;
21 packet_ready : OUT std_logic;
24 payload_valid : OUT std_logic;
25 payload_last : OUT std_logic;
26 tready_data : IN std_logic
49 Nbits :
positive :=
64;
50 CRC_Width :
positive :=
20;
51 G_Poly :
Std_Logic_Vector :=x"
8349f";
52 G_InitVal :
std_logic_vector :=x
"fffff"
55 CRC :
out std_logic_vector(CRC_Width
-1 downto 0);
58 DIn :
in std_logic_vector(Nbits
-1 downto 0);
59 Reset :
in std_logic);
62 signal valid_sig, last_sig, ready_sig, force_ready_sig, input_active_sig: std_logic;
63 signal do_crc9, calc_crc20, reset_crc20, send_crc9, send_crc20: std_logic;
64 signal input_valid_sig, input_data_end_sig, prefetch_sig: std_logic;
65 signal data_sig, inputdata_sig, crc_word: std_logic_vector(63 DOWNTO 0);
66 signal crc9val: std_logic_vector(8 DOWNTO 0);
67 signal crc20val: std_logic_vector(19 DOWNTO 0);
68 signal state_sig: STATE_TYPE;
72 payload_valid <= valid_sig;
73 payload_last <= last_sig;
74 ready_sig <= tready_data and valid_sig;
76 packet_ready <= ((ready_sig or force_ready_sig) and input_active_sig) or prefetch_sig;
82 G_Poly => "
011111011",
83 G_InitVal => "
111111111"
108 buffer_input:
process(clk)
109 variable valid_int, valid_buf, data_end_int: std_logic := '0';
110 variable data_int, data_buf: std_logic_vector(63 DOWNTO 0) := (others => '0');
111 variable input_active_int: std_logic := '0';
113 if rising_edge(clk) then
114 if rst_clk = '1' then
117 input_active_int := '0';
118 elsif ((state_sig = idle) and (input_active_int = '0')) or (prefetch_sig = '1') or (ready_sig = '1') or (force_ready_sig = '1') then
119 data_int := data_buf;
121 valid_int := valid_buf;
122 valid_buf := packet_valid;
123 data_end_int := packet_last;
124 elsif state_sig = wait_hdr_crc then
125 input_active_int := '1';
127 if (input_active_sig = '1') and (packet_valid = '0') then
128 input_active_int := '0';
130 inputdata_sig <= data_int
135 input_valid_sig <= valid_int
140 input_data_end_sig <= data_end_int
145 input_active_sig <= input_active_int
151 end process buffer_input;
153 build_crc_word:
process(clk)
154 variable do_crc9_int, calc_crc20_int, reset_crc20_int, send_crc9_int, send_crc20_int: std_logic := '0';
155 variable crc_word_int: std_logic_vector(63 downto 0) := (others => '0');
156 variable payload_length: unsigned(7 downto 0) := (Others => '0');
158 if rising_edge(clk) then
160 calc_crc20_int := '0';
161 reset_crc20_int := '0';
162 send_crc9_int := '0';
163 send_crc20_int := '0';
167 crc_word_int := inputdata_sig(31 downto 29) & "000000000" & inputdata_sig(19 downto 0) & inputdata_sig(63 downto 32);
170 send_crc9_int := '1';
172 reset_crc20_int := '1';
173 payload_length := (Others => '0');
175 if ready_sig = '1' then
176 crc_word_int := inputdata_sig(31 downto 0) & inputdata_sig(63 downto 32);
177 calc_crc20_int := '1';
178 payload_length := payload_length + 1;
180 when build_trailer =>
181 crc_word_int := inputdata_sig(31 downto 9) & std_logic_vector(payload_length) & "0" & x"00000" & inputdata_sig(43 downto 32) ;
182 calc_crc20_int := ready_sig;
183 when do_trailer_crc =>
184 when wait_trailer_crc =>
185 send_crc20_int := '1';
187 crc_word_int := (Others => '0');
189 do_crc9 <= do_crc9_int
194 calc_crc20 <= calc_crc20_int
199 reset_crc20 <= reset_crc20_int
204 send_crc9 <= send_crc9_int
209 send_crc20 <= send_crc20_int
214 crc_word <= crc_word_int
220 end process build_crc_word;
222 send_data:
process(clk)
223 variable data_int, next_data, next_data_buf: std_logic_vector(63 DOWNTO 0) := (others => '0');
224 variable ready_buf: std_logic := '0';
226 if rising_edge(clk) then
227 if send_crc9 = '1' then
228 next_data_buf := crc_word(31 downto 0) & crc_word(63 downto 61) & crc9val & crc_word(51 downto 32);
229 elsif send_crc20 = '1' then
230 next_data_buf := crc20val & crc_word(11 downto 0) & crc_word(63 downto 32);
231 elsif input_valid_sig = '1' then
232 next_data_buf := inputdata_sig;
234 next_data_buf := (Others => '0');
236 if ready_buf = '1' or force_ready_sig = '1' then
237 next_data := next_data_buf;
239 if ready_sig = '1' and last_sig = '1' then
240 data_int := (Others => '0');
241 elsif ready_sig = '1' or force_ready_sig = '1' then
243 data_int := next_data;
253 end process send_data;
255 state_machine:
process(clk)
256 variable got_data_end: std_logic := '0';
257 variable valid_int, last_int, prefetch_int, force_ready_int: std_logic := '0';
258 variable next_state: STATE_TYPE := idle;
260 if rising_edge(clk) then
261 if rst_clk = '1' then
267 force_ready_int := '0';
268 if input_data_end_sig = '1' then
274 next_state := do_hdr_crc;
276 next_state := wait_hdr_crc;
278 force_ready_int := '1';
279 next_state := send_l1id;
282 if got_data_end = '1' then
283 next_state := build_trailer;
285 next_state := send_payload;
289 if got_data_end = '1' and ready_sig = '1' then
290 next_state := build_trailer;
292 when build_trailer =>
293 if ready_sig = '1' then
294 next_state := do_trailer_crc;
298 when do_trailer_crc =>
299 next_state := wait_trailer_crc;
300 when wait_trailer_crc =>
301 next_state := send_trailer;
302 force_ready_int := '1';
306 next_state := wait_end;
308 if ready_sig = '1' then
316 if (input_valid_sig = '1') then
318 next_state := capture_l1id;
321 state_sig <= next_state
326 prefetch_sig <= prefetch_int
331 force_ready_sig <= force_ready_int
341 valid_sig <= valid_int
347 end process state_machine;
AXI-stream version of packet engine...
AXI-stream version of packet engine...
in packet_data std_logic_vector( 63 DOWNTO 0)
FIFO signals.
out payload_data std_logic_vector( 63 DOWNTO 0)
towards Aurora readout