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

Back to eFEX documentation
efex_packet_mux.vhd
Go to the documentation of this file.
1 
14 
15 library ieee;
16 use ieee.std_logic_1164.all;
17 use ieee.numeric_std.all;
18 
19 LIBRARY infrastructure_lib;
20 use infrastructure_lib.packet_mux_type.all;
21 
23 entity efex_packet_mux is
24  generic(NSRC: positive := 4);
25  port (
26  clk : in std_logic;
27  rst_clk : in std_logic;
28 -- Shelf and eFEX number (for error recovery trailer)
29  eFEX_number : in std_logic_vector(7 downto 0);
30  pause : in std_logic := '0';
31  packet_mux_enabled : IN std_logic_vector(NSRC-1 downto 0);
32  packet_mux_reset : IN std_logic_vector(NSRC-1 downto 0);
33  packet_mux_source : OUT std_logic_vector(3 downto 0);
35  packet_mux_data : IN packet_data_array(NSRC-1 downto 0);
36  packet_mux_valid : IN std_logic_vector(NSRC-1 downto 0);
37  packet_mux_last : IN std_logic_vector(NSRC-1 downto 0);
38  packet_mux_ready : OUT std_logic_vector(NSRC-1 downto 0);
40  packet_data : OUT std_logic_vector (63 DOWNTO 0) ;
41  packet_valid : OUT std_logic;
42  packet_last : OUT std_logic;
43  packet_ready : IN std_logic
44  );
45 end efex_packet_mux;
46 
48 architecture rtl of efex_packet_mux is
49 
50  TYPE STATE_TYPE IS (
51  running,
52  starting,
53  hunting
54  );
55 
56  signal state_sig: STATE_TYPE := hunting;
57  signal src, hunting_src: unsigned(3 downto 0) := (Others => '0'); -- Up to 14 sources (last two are special)...
58  signal sel, hunting_sel: integer range 0 to NSRC+1 := 0;
59  signal active: std_logic;
60  signal packet_mux_data_sig: packet_data_array(NSRC+1 downto 0);
61  signal packet_mux_valid_sig, packet_mux_last_sig, packet_mux_reset_sig: std_logic_vector(NSRC+1 downto 0);
62  signal packet_mux_ready_sig, packet_mux_enabled_sig: std_logic_vector(NSRC-1 downto 0);
63 
64 begin
65 
66  sel <= to_integer(src);
67  hunting_sel <= to_integer(hunting_src);
68  packet_mux_source <= std_logic_vector(src);
69 
70  packet_mux_data_sig(NSRC+1) <= (Others => '0'); -- dummy source for the MUX whilst hunting
71  packet_mux_data_sig(NSRC) <= x"00000028000" & eFEX_number & x"000"; -- Assert Corrective Trailer and Protocol Error in recovery trailer
72  packet_mux_data_sig(NSRC-1 downto 0) <= packet_mux_data;
73  packet_mux_valid_sig <= "01" & packet_mux_valid;
74  packet_mux_last_sig <= "01" & packet_mux_last;
75  packet_mux_reset_sig <= "00" & packet_mux_reset;
76  packet_mux_enabled_sig <= packet_mux_enabled;
77  packet_mux_ready <= packet_mux_ready_sig;
78 
79  process(clk)
80  begin
81  if rising_edge(clk) then
82  if rst_clk = '1' then
83  active <= '0';
84  src <= (others => '0');
85  hunting_src <= (others => '0');
86  state_sig <= hunting;
87  else
88  Case state_sig is
89  When running =>
90 -- Remember that we could be in error recovery so sel might be equal to NSRC...
91  if (packet_mux_last_sig(sel) = '1') and (packet_ready = '1') then -- End of Frame...
92  active <= '0'; -- disable control logic
93  src <= to_unsigned(NSRC+1, 4); -- park MUX on dummy input
94  state_sig <= hunting; -- switch to search for next packet
95  elsif (packet_mux_reset_sig(sel) = '1') then -- Error recovery, switch to sending corrective trailer...
96  src <= to_unsigned(NSRC, 4);
97  end if;
98  When starting =>
99  active <= '1';
100  state_sig <= running;
101  When Others => -- hunting...
102  if (pause = '1') then
103  null;
104 -- Activate if packet ready and not being reset...
105  elsif (packet_mux_valid_sig(hunting_sel) = '1') and (packet_mux_enabled_sig(hunting_sel) = '1') and (packet_mux_reset_sig(hunting_sel) = '0') then
106  src <= hunting_src;
107  state_sig <= starting;
108 -- Switch to 0 if packet available there!
109  elsif (packet_mux_valid_sig(0) = '1') and (packet_mux_enabled_sig(0) = '1') and (packet_mux_reset_sig(0) = '0') then
110  src <= (others => '0');
111  state_sig <= starting;
112 -- Otherwise Round Robin over the real inputs
113  elsif (hunting_src /= (NSRC-1)) then
114  hunting_src <= hunting_src + 1;
115  else
116  hunting_src <= to_unsigned(1, 4); -- We always check 0 so start at 1 for the round robin
117  end if;
118  end case;
119  end if;
120  end if;
121  end process;
122 
123 -- mask signal when hunting for data...
124  packet_valid <= packet_mux_valid_sig(sel) when active = '1' else '0';
125  packet_data <= packet_mux_data_sig(sel);
126  packet_last <= packet_mux_last_sig(sel);
127 
128  ackgen: for i in NSRC-1 downto 0 generate
129  begin
130  packet_mux_ready_sig(i) <= packet_ready when (sel = i) and (active = '1') else '0';
131  end generate;
132 
133 end rtl;
134 
AXI-stream MUX into packet engine...
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.