11 USE ieee.std_logic_1164.
all;
12 use ieee.numeric_std.
all;
16 USE ipbus_lib.ipbus.
all;
21 INPUT_FPGA_NO : std_logic_vector(1 downto 0) := "00";
22 DATA_FORMAT_VERSION : std_logic_vector (2 DOWNTO 0) := "001";
23 IPBUS_ADDR_WIDTH : positive := 10;
24 ILA_ENABLED : std_logic := '0'
28 eFEX_number : IN std_logic_vector(7 downto 0);
29 enable
: in std_logic;
31 clk_mgt : in std_logic;
32 data_from_mgt : in std_logic_vector(31 downto 0);
33 char_is_k : in std_logic;
34 error_from_mgt : in std_logic;
36 clk_320 : in std_logic;
37 rst_320 : in std_logic;
38 fifo_data : out std_logic_vector (63 DOWNTO 0);
39 fifo_valid : out std_logic;
40 fifo_last : out std_logic;
42 mgt_last_l1id : out std_logic_vector (31 downto 0);
43 mgt_packet_stats : out std_logic_vector (4 downto 0);
45 clk_ipb : in std_logic;
46 rst_ipb : in std_logic;
47 rst_ipbus_addr : in std_logic;
48 ipbus_wraparound : in std_logic;
50 ipb_out : out ipb_rbus
59 FPGA_NO:
std_logic_vector(
1 downto 0) := "
00";
60 FORMAT_VERSION:
std_logic_vector (
2 DOWNTO 0) := "
001"
64 rst_clk:
in std_logic;
67 eFEX_number :
IN std_logic_vector(
7 downto 0);
69 rd_rst_busy :
in STD_LOGIC;
70 m_axis_tvalid :
in STD_LOGIC;
71 m_axis_tready :
out STD_LOGIC;
72 m_axis_tdata :
in STD_LOGIC_VECTOR(
31 DOWNTO 0);
73 m_axis_tlast :
in STD_LOGIC;
74 m_axis_tuser :
in STD_LOGIC_VECTOR(
1 DOWNTO 0);
76 data_fifo_data:
out std_logic_vector(
63 downto 0);
77 data_fifo_valid:
out std_logic := '
0';
78 data_fifo_last:
out std_logic := '
0'
80 END Component mgt_readout_receiver;
82 Component mgt_axi_fifo
84 wr_rst_busy :
OUT STD_LOGIC;
85 rd_rst_busy :
OUT STD_LOGIC;
86 m_aclk :
IN STD_LOGIC;
87 s_aclk :
IN STD_LOGIC;
88 s_aresetn :
IN STD_LOGIC;
89 s_axis_tvalid :
IN STD_LOGIC;
90 s_axis_tready :
OUT STD_LOGIC;
91 s_axis_tdata :
IN STD_LOGIC_VECTOR(
31 DOWNTO 0);
92 s_axis_tlast :
IN STD_LOGIC;
93 s_axis_tuser :
IN STD_LOGIC_VECTOR(
2 DOWNTO 0);
94 m_axis_tvalid :
OUT STD_LOGIC;
95 m_axis_tready :
IN STD_LOGIC;
96 m_axis_tdata :
OUT STD_LOGIC_VECTOR(
31 DOWNTO 0);
97 m_axis_tlast :
OUT STD_LOGIC;
98 m_axis_tuser :
OUT STD_LOGIC_VECTOR(
2 DOWNTO 0)
100 END Component mgt_axi_fifo;
102 Component ipbus_dpram
is
104 ADDR_WIDTH:
positive;
105 DATA_WIDTH:
positive :=
32
111 ipb_out:
out ipb_rbus;
113 we:
in std_logic := '
0';
114 d:
in std_logic_vector(DATA_WIDTH
- 1 downto 0) := (
others => '
0');
115 q:
out std_logic_vector(DATA_WIDTH
- 1 downto 0);
116 addr:
in std_logic_vector(ADDR_WIDTH
- 1 downto 0)
118 end Component ipbus_dpram;
123 probe0 :
IN STD_LOGIC_VECTOR(
34 DOWNTO 0)
127 SIGNAL char_is_k_sig, error_from_mgt_sig, s_axis_tvalid, s_axis_tlast, wr_rst_busy, wr_rst_stretch : STD_LOGIC;
128 SIGNAL m_axis_tvalid, m_axis_tready, m_axis_tlast, rd_rst_busy, rd_rst_stretch : STD_LOGIC;
129 SIGNAL spy_ready_valid_i, spy_last_i : STD_LOGIC;
130 SIGNAL data_from_mgt_sig, s_axis_tdata, m_axis_tdata, spy_data_i : STD_LOGIC_VECTOR(31 DOWNTO 0);
131 SIGNAL s_axis_tuser, m_axis_tuser, spy_user_i : STD_LOGIC_VECTOR(2 DOWNTO 0);
133 SIGNAL fifo_data_sig : std_logic_vector (63 DOWNTO 0);
134 SIGNAL fifo_valid_sig, fifo_last_sig : std_logic;
135 signal mgt_packet_stats_sig: std_logic_vector (4 downto 0);
137 SIGNAL IPBus_RAM_addr, IPBus_RAM_addr_i : std_logic_vector(IPBUS_ADDR_WIDTH-1 downto 0);
138 SIGNAL IPBus_RAM_din, IPBus_RAM_din_i : std_logic_vector(31 DOWNTO 0);
139 SIGNAL IPBus_RAM_we, IPBus_RAM_we_i : std_logic;
141 SIGNAL rst_mgt_sig, rst_clk320_tff : std_logic := '0';
142 SIGNAL rst_mgt_n : std_logic;
143 signal rst_clkmgt_tff_buf, enable_mgt_buf : std_logic_vector(1 downto 0) := (Others => '0');
145 attribute ASYNC_REG : string;
146 attribute ASYNC_REG of rst_clkmgt_tff_buf : signal is "TRUE";
147 attribute ASYNC_REG of enable_mgt_buf : signal is "TRUE";
151 fifo_data <= fifo_data_sig;
152 fifo_valid <= fifo_valid_sig;
153 fifo_last <= fifo_last_sig;
154 mgt_packet_stats <= mgt_packet_stats_sig;
156 rst_mgt_n <= not rst_mgt_sig;
160 FORMAT_VERSION => DATA_FORMAT_VERSION,
161 FPGA_NO => INPUT_FPGA_NO
166 eFEX_number => eFEX_number,
169 rd_rst_busy => rd_rst_stretch,
170 m_axis_tvalid => m_axis_tvalid,
171 m_axis_tready => m_axis_tready,
172 m_axis_tdata => m_axis_tdata,
173 m_axis_tlast => m_axis_tlast,
174 m_axis_tuser => m_axis_tuser
(1 downto 0),
176 data_fifo_data => fifo_data_sig,
177 data_fifo_valid => fifo_valid_sig,
178 data_fifo_last => fifo_last_sig
181 mgt_fifo : mgt_axi_fifo
183 wr_rst_busy => wr_rst_busy,
184 rd_rst_busy => rd_rst_busy,
187 s_aresetn => rst_mgt_n,
188 s_axis_tvalid => s_axis_tvalid,
189 s_axis_tready =>
OPEN,
190 s_axis_tdata => s_axis_tdata,
191 s_axis_tlast => s_axis_tlast,
192 s_axis_tuser => s_axis_tuser,
193 m_axis_tvalid => m_axis_tvalid,
194 m_axis_tready => m_axis_tready,
195 m_axis_tdata => m_axis_tdata,
196 m_axis_tlast => m_axis_tlast,
197 m_axis_tuser => m_axis_tuser
200 IPbus_RAM : ipbus_dpram
202 ADDR_WIDTH => IPBUS_ADDR_WIDTH,
214 addr => IPBus_RAM_addr
217 input_register_block:
process(clk_mgt)
219 if rising_edge(clk_mgt) then
220 data_from_mgt_sig <= data_from_mgt
225 char_is_k_sig <= char_is_k
230 error_from_mgt_sig <= error_from_mgt
236 end process input_register_block;
240 mgt_input_block:
process(clk_mgt)
241 Variable data_valid, data_last: std_logic := '0';
243 if rising_edge(clk_mgt) then
245 if (rst_mgt_sig = '1') or (wr_rst_stretch = '1') or (s_axis_tlast = '1') or (enable_mgt_buf(1) = '0') then
247 elsif (char_is_k_sig = '1') and (data_from_mgt_sig(4 downto 0) = "11100") then
248 if data_from_mgt_sig(7 downto 5) = "101" then
250 elsif data_from_mgt_sig(7 downto 5) = "110" then
252 elsif (data_from_mgt_sig(7) = '0') and (data_from_mgt_sig(5) = '1') and (char_is_k = '0') then
256 s_axis_tdata <= data_from_mgt_sig
261 s_axis_tvalid <= data_valid
266 s_axis_tlast <= data_last
271 s_axis_tuser(1 downto 0) <= error_from_mgt_sig & char_is_k_sig
277 end process mgt_input_block;
281 input_dodgy_block:
process(clk_mgt)
282 variable input_length: unsigned(8 downto 0) := (Others => '0');
283 variable input_dodgy, last_tvalid: std_logic := '0';
285 if rising_edge(clk_mgt) then
286 if (data_from_mgt_sig = data_from_mgt) and not ((data_from_mgt_sig = x"000000bc") and (char_is_k_sig = '1')) then
291 if (last_tvalid = '0') then
292 input_length := (Others => '0');
293 elsif (data_from_mgt_sig(7 downto 0) = x"dc") and (char_is_k_sig = '1') and (data_from_mgt_sig(16 downto 8) /= std_logic_vector(input_length)) then
296 input_length := input_length + 1;
298 last_tvalid := s_axis_tvalid;
299 s_axis_tuser(2) <= input_dodgy
305 end process input_dodgy_block;
307 status_block:
process(clk_320)
308 Variable got_l1id: std_logic := '0';
309 Variable last_l1id_var: std_logic_vector(31 downto 0);
311 if rising_edge(clk_320) then
312 if (rst_320 = '1') then
314 elsif (fifo_valid_sig = '1') and (got_l1id = '0') then
315 last_l1id_var := fifo_data_sig(63 downto 32);
318 if (fifo_valid_sig = '1') and (fifo_last_sig = '1') then
320 mgt_last_l1id <= last_l1id_var
325 mgt_packet_stats_sig <= fifo_data_sig(36 downto 33) & '1'
331 mgt_last_l1id <= (Others => '0')
336 mgt_packet_stats_sig <= (Others => '0')
343 end process status_block;
345 ipbus_ram_block:
process(clk_320)
346 variable ram_addr, next_addr: unsigned(IPBUS_ADDR_WIDTH-1 downto 0) := (Others => '0');
347 constant max_addr
: unsigned(IPBUS_ADDR_WIDTH-1 downto 0) := (Others => '1');
348 constant min_addr
: unsigned(IPBUS_ADDR_WIDTH-1 downto 0) := to_unsigned(1, IPBUS_ADDR_WIDTH);
349 variable ram_we, endaddr_pending, we_active: std_logic;
350 variable ram_data: std_logic_vector(31 downto 0);
352 if rising_edge(clk_320) then
354 ram_addr := next_addr;
355 ram_data := (Others => '0');
356 if (rst_320 = '1') or (rst_ipbus_addr = '1') then
357 next_addr := min_addr;
358 endaddr_pending := '0';
360 elsif (spy_ready_valid_i = '1') then
362 ram_data := spy_data_i;
363 endaddr_pending := spy_last_i;
364 if (next_addr = max_addr) then
365 next_addr := min_addr;
367 we_active := ipbus_wraparound;
369 next_addr := next_addr + 1;
371 elsif (endaddr_pending = '1') then
373 ram_addr := (Others => '0');
374 ram_data(31 downto IPBUS_ADDR_WIDTH) := (Others => '0');
375 ram_data(IPBUS_ADDR_WIDTH-1 downto 0) := std_logic_vector(next_addr);
376 endaddr_pending := '0';
378 IPBus_RAM_we_i <= ram_we
383 IPBus_RAM_din_i <= ram_data
388 IPBus_RAM_addr_i <= std_logic_vector(ram_addr)
394 end process ipbus_ram_block;
396 spy_reg_block:
process(clk_320)
398 if rising_edge(clk_320) then
399 spy_data_i <= m_axis_tdata
404 spy_last_i <= m_axis_tlast
409 spy_ready_valid_i <= m_axis_tready and m_axis_tvalid
414 spy_user_i <= m_axis_tuser
420 end process spy_reg_block;
422 ila_block : if (ILA_ENABLED = '1') generate
426 probe0
(31 downto 0) => spy_data_i,
427 probe0
(32) => spy_ready_valid_i,
428 probe0
(33) => spy_user_i
(2),
429 probe0
(34) => mgt_packet_stats_sig
(2)
433 ipbus_ram_reg_block:
process(clk_320)
435 if rising_edge(clk_320) then
436 IPBus_RAM_din <= IPBus_RAM_din_i
441 IPBus_RAM_addr <= IPBus_RAM_addr_i
446 IPBus_RAM_we <= IPBus_RAM_we_i
452 end process ipbus_ram_reg_block;
454 rst_clk320_block :
process(clk_320)
456 if rising_edge(clk_320) then
457 if rst_320 = '1' then
459 rst_clk320_tff <= not rst_clk320_tff;
461 rst_clk320_tff <= rst_clk320_tff;
464 end process rst_clk320_block;
466 rst_clkmgt_block :
process(clk_mgt)
467 Variable stretch: std_logic_vector(7 downto 0) := (Others => '1');
468 Variable reset_done: std_logic := '0';
470 if rising_edge(clk_mgt) then
471 rst_clkmgt_tff_buf <= rst_clkmgt_tff_buf(0) & rst_clk320_tff;
472 if ((rst_clkmgt_tff_buf(1) xor rst_clkmgt_tff_buf(0)) = '1') or (reset_done = '0') then
473 stretch := (Others => '1');
476 stretch := stretch(6 downto 0) & "0";
478 rst_mgt_sig <= stretch(7)
484 end process rst_clkmgt_block;
486 wr_rst_stretch_block :
process(clk_mgt)
487 Variable stretch: std_logic_vector(7 downto 0) := (Others => '1');
489 if rising_edge(clk_mgt) then
490 if (wr_rst_busy = '1') or (rst_mgt_sig = '1') then
491 stretch := (Others => '1');
493 stretch := stretch(6 downto 0) & "0";
495 wr_rst_stretch <= stretch(7)
501 end process wr_rst_stretch_block;
503 rd_rst_stretch_block :
process(clk_320)
504 Variable stretch: std_logic_vector(7 downto 0) := (Others => '1');
506 if rising_edge(clk_320) then
507 if (rd_rst_busy = '1') or (rst_320 = '1') then
508 stretch := (Others => '1');
510 stretch := stretch(6 downto 0) & "0";
512 rd_rst_stretch <= stretch(7)
518 end process rd_rst_stretch_block;
520 enable_clkmgt_block :
process(clk_mgt)
522 if rising_edge(clk_mgt) then
523 enable_mgt_buf <= enable_mgt_buf(0) & enable;
525 end process enable_clkmgt_block;
527 END Architecture rtl;
Second version of packet format engine from MGT through to formatted (sub)block...
Second version of packet format engine from MGT through to formatted (sub)block...
Second version of packet format engine...