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

Back to eFEX documentation
AlgoRateMonitor.vhd
Go to the documentation of this file.
1 
6 
7 library IEEE;
8 use IEEE.STD_LOGIC_1164.all;
9 use IEEE.NUMERIC_STD.all;
10 
11 library infrastructure_lib;
12 use infrastructure_lib.counter;
13 
15 use work.DataTypes.all;
17 use work.AlgoDataTypes.all;
18 
20 library ipbus_lib;
22 use ipbus_lib.ipbus_reg_types.all;
24 use ipbus_lib.ipbus.all;
25 
27 entity AlgoRateMonitor is
28  port (
29  ipb_clk : in std_logic;
30  ipb_rst : in std_logic;
31  ipb_in : in ipb_wbus;
32  ipb_out : out ipb_rbus;
33 
34  clk : in std_logic;
35  IN_BCN : in std_logic_vector(11 downto 0); --@suppress
36  IN_synch : in std_logic;
37  IN_eta : in std_logic_vector(2 downto 0);
38 
39  IN_eg_energies : in array_std_logic_vector(OUTPUT_TOBS-1 downto 0)(ENERGY_WIDTH-1 downto 0);
40  IN_eg_valids : in std_logic_vector(OUTPUT_TOBS-1 downto 0);
41 
42  IN_tau_energies : in array_std_logic_vector(OUTPUT_TOBS-1 downto 0)(ENERGY_WIDTH-1 downto 0);
43  IN_tau_valids : in std_logic_vector(OUTPUT_TOBS-1 downto 0));
44 
45 end AlgoRateMonitor;
46 
47 
48 architecture Behavioral of AlgoRateMonitor is
49  constant N_CTRL : positive := 2;
50  constant N_STAT : positive := 98;
51 
52  signal write_reg : ipb_reg_v(N_STAT - 1 downto 0) := (others => (others => '0'));
53  signal read_reg : ipb_reg_v(N_CTRL - 1 downto 0);
54 
55  signal enable, counter_reset, reset, sync : std_logic;
56  signal energy_threshold_eg, energy_threshold_tau : std_logic_vector(ENERGY_WIDTH-1 downto 0);
57  signal sync_d : std_logic_vector (2 downto 0);
58  signal counter_start, counter_stop : std_logic;
59  signal status, control : std_logic_vector(31 downto 0);
60 
61  signal right_eta : std_logic_vector(5 downto 0);
62  signal eta_eg, eta_tau : std_logic_vector(7 downto 0);
63  signal normalisation_saturated : std_logic;
64 
65  type STATE_TYPE is (ready, idle, run);
66  signal state : STATE_TYPE;
67 
68 -- ####### attributes ########
69  attribute keep : string ;
70  attribute max_fanout : integer;
71  attribute keep of read_reg : signal is "true" ;
72  attribute max_fanout of read_reg : signal is 1000;
73  attribute keep of reset : signal is "true" ;
74  attribute max_fanout of reset : signal is 1000;
75 
76 
78 begin
79  IPBUS_ALGO_REGISTERS : entity ipbus_lib.ipbus_ctrlreg_v
80  generic map ( -- @suppress "Generic map uses default values. Missing optional actuals: SWAP_ORDER"
81  N_CTRL => N_CTRL, --number of control reg
82  N_STAT => N_STAT) --number of status reg
83  port map ( -- @suppress "Port map uses default values. Missing optional actuals: ctrl_default, qmask"
84  clk => ipb_clk,
85  reset => ipb_rst,
86  ipbus_in => ipb_in,
87  ipbus_out => ipb_out,
88  d => write_reg,
89  q => read_reg,
90 -- qmask => (others => '0'),
91  stb => open);
92 
93  control <= read_reg(0);
94  energy_threshold_eg <= read_reg(1)(15 downto 0);
95  energy_threshold_tau <= read_reg(1)(31 downto 16);
96 
97  write_reg(N_STAT-1) <= status;
98 
99  -- registers connections
100  counter_start <= control(0);
101  counter_stop <= control(1);
102  counter_reset <= control(2);
103 
105  synch_delay : process (clk)
106  begin
107  if rising_edge(clk) then
108  sync_d(0) <= IN_synch;
109  sync_d(2 downto 1) <= sync_d(1 downto 0);
110  sync <= sync_d(2);
111  end if;
112  end process;
113 
114 
115  enable_proc : process (clk)
116  begin
117  if rising_edge(clk) then
118  if sync = '1' then
119  if counter_reset = '1' then
120  state <= ready;
121  reset <= '1';
122  enable <= '0';
123  else
124  case state is
125  when idle => -- @suppress "Dead state 'idle': state does not have outgoing transitions"
126  state <= idle;
127  reset <= '0';
128 
129  when ready =>
130  if counter_start = '1' then
131  state <= run;
132  reset <= '0';
133  enable <= '1';
134  else
135  state <= ready;
136  reset <= '1';
137  enable <= '0';
138  end if;
139 
140  when run =>
141  if counter_stop = '1' then
142  state <= idle;
143  reset <= '0';
144  enable <= '0';
145  else
146  state <= run;
147  reset <= '0';
148  enable <= '1';
149  end if;
150  end case;
151  end if;
152  else
153  state <= state;
154  enable <= enable;
155  reset <= reset;
156  end if;
157  end if;
158  end process;
159 
160  -- status connections
161  status(1 downto 0) <= "11" when state = run else
162  "01" when state = ready else
163  "00"; --idle
164  status(2) <= enable;
165  status(3) <= reset;
166 
167 
168  eg_tau_for : for phi in OUTPUT_TOBS-1 downto 0 generate
169  eta_eg(phi) <= '1' when IN_eg_valids(phi) = '1' and not (unsigned(IN_eg_energies(phi)) < unsigned(energy_threshold_eg)) else '0';
170  eta_tau(phi) <= '1' when IN_tau_valids(phi) = '1' and not (unsigned(IN_tau_energies(phi)) < unsigned(energy_threshold_tau)) else '0';
171  end generate;
172 
173  eta_for : for eta in 5 downto 0 generate
174  right_eta(eta) <= '1' when unsigned(IN_eta) = eta else '0';
175  phi_for : for phi in OUTPUT_TOBS-1 downto 0 generate
176  CNT_EG : entity infrastructure_lib.counter
177  generic map (DEPTH => 32)
178  port map (
179  clk => clk,
180  enable1 => enable and right_eta (eta),
181  enable2 => eta_eg(phi) and not normalisation_saturated,
182  count => write_reg(phi*6 + eta),
183  reset => reset
184  );
185 
186  CNT_TAU : entity infrastructure_lib.counter
187  generic map (DEPTH => 32)
188  port map (
189  clk => clk,
190  enable1 => enable and right_eta (eta),
191  enable2 => eta_tau(phi) and not normalisation_saturated,
192  count => write_reg(48 + phi*6 + eta),
193  reset => reset
194  );
195  end generate;
196  end generate;
197 
198 
199  NORMALISATION_CNT : entity infrastructure_lib.counter
200  generic map (DEPTH => 32)
201  port map (
202  clk => clk,
203  enable1 => enable,
204  enable2 => IN_synch, --this shouldn't be delayed to be in time with data
205  count => write_reg(N_STAT-2),
206  saturated => normalisation_saturated,
207  reset => reset
208  );
209 
210 end Behavioral;
External data-types and functions.
positive := 2 N_CTRL
Number of control IPBus reg.
positive := 98 N_STAT
Number of status IPBus reg.
Algo Rate Monitor.
in ipb_rst std_logic
IPBus reset.
in ipb_clk std_logic
IPBus clk.
out ipb_out ipb_rbus
IPBus read bus.
in ipb_in ipb_wbus
IPBus write bus.
Counter with double enable.
Definition: counter.vhd:12
in reset std_logic
reset
Definition: counter.vhd:27
in enable1 std_logic
enable 1
Definition: counter.vhd:18
in clk std_logic
clock
Definition: counter.vhd:16
out count std_logic_vector( DEPTH- 1 downto 0)
counter value
Definition: counter.vhd:22
in enable2 std_logic := '1'
enable 2
Definition: counter.vhd:20
out saturated std_logic
counter value
Definition: counter.vhd:24