ROD firmware  1.0.5
ATLAS l1-calo - ROD_eFEX and ROD_jFEX firmware for the L1Calo ROD board

Back to ROD documentation
l1id_cont_check.vhd
1 ----------------------------------------------------------------------------------
2 -- Company:
3 -- Engineer:
4 --
5 -- Create Date: 12.10.2022 14:06:34
6 -- Design Name:
7 -- Module Name: l1id_cont_check - RTL
8 -- Project Name:
9 -- Target Devices:
10 -- Tool Versions:
11 -- Description:
12 --
13 -- Dependencies:
14 --
15 -- Revision:
16 -- Revision 0.01 - File Created
17 -- Additional Comments:
18 --
19 ----------------------------------------------------------------------------------
20 
21 
22 library IEEE;
23 use IEEE.STD_LOGIC_1164.ALL;
24 use IEEE.STD_LOGIC_UNSIGNED.ALL;
25 
26 -- Uncomment the following library declaration if using
27 -- arithmetic functions with Signed or Unsigned values
28 --use IEEE.NUMERIC_STD.ALL;
29 
30 -- Uncomment the following library declaration if instantiating
31 -- any Xilinx leaf cells in this code.
32 --library UNISIM;
33 --use UNISIM.VComponents.all;
34 
35 entity l1id_cont_check is
36  Port (
37 
38  clock : in STD_LOGIC;
39  reset : in STD_LOGIC;
40  -- clr_errors : in STD_LOGIC;
41  L1A : in STD_LOGIC;
42  ECR : in STD_LOGIC;
43  L1id : in STD_LOGIC_vector(23 downto 0);
44  ECRid : in STD_LOGIC_vector(7 downto 0);
45 
46  timeout_threshold : in STD_LOGIC_vector(31 downto 0);
47  l1id_continuity_control : in STD_LOGIC_vector (31 downto 0);
48  l1id_continuity_status : out STD_LOGIC_vector (31 downto 0);
49  l1id_local_miss : out STD_LOGIC_vector (31 downto 0);
50  l1id_ttc_miss : out STD_LOGIC_vector (31 downto 0);
51  l1id_error_count : out STD_LOGIC_vector(31 downto 0);
52  repeat_counter : out STD_LOGIC_vector(31 downto 0)
53 
54 
55 
56 
57  );
58 end l1id_cont_check;
59 
60 architecture RTL of l1id_cont_check is
61 
62 signal L1id_counter : STD_LOGIC_vector(23 downto 0);
63 signal ECRid_counter : STD_LOGIC_vector(7 downto 0);
64 signal timeout_counter : STD_LOGIC_vector(31 downto 0);
65 signal L1id_error_counter : STD_LOGIC_vector(31 downto 0);
66 signal timeout_enable : STD_LOGIC;
67 signal timeout : STD_LOGIC;
68 signal L1id_mismatch : STD_LOGIC;
69 signal l1id_compare : STD_LOGIC;
70 signal ECRid_compare : STD_LOGIC;
71 signal capture : STD_LOGIC;
72 signal l1id_local_miss_i : STD_LOGIC_vector (31 downto 0);
73 signal l1id_ttc_miss_i : STD_LOGIC_vector (31 downto 0);
74 
75 
76 --signal l1id_continuity_control : STD_LOGIC_vector (31 downto 0);
77 signal clear : std_logic;
78 signal clear_s : std_logic;
79 signal clear_s_del : std_logic;
80 signal armed : std_logic;
81 signal armed_s : std_logic;
82 signal armed_s_del : std_logic;
83 signal armed_pulse : std_logic;
84 signal armed_stat : std_logic;
85 signal triggered : std_logic;
86 signal l1id_del : std_logic;
87 signal ECRid_del : std_logic;
88 signal word_counter : std_logic_vector (1 downto 0);
89 signal current_l1ID : std_logic_vector (31 downto 0);
90 signal last_l1ID : std_logic_vector (31 downto 0);
91 signal repeat_counter_i : std_logic_vector (31 downto 0);
92 signal clear_local_l1id : std_logic;
93 signal clear_local_ECRid : std_logic;
94 
95 COMPONENT ila_l1id_cont
96 
97 PORT (
98  clk : IN STD_LOGIC;
99 
100  probe0 : IN STD_LOGIC_VECTOR(1 DOWNTO 0);
101  probe1 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
102  probe2 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
103  probe3 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
104  probe4 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
105  probe5 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
106  probe6 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
107  probe7 : IN STD_LOGIC_VECTOR(0 DOWNTO 0);
108  probe8 : IN STD_LOGIC_VECTOR(23 DOWNTO 0);
109  probe9 : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
110  probe10 :IN STD_LOGIC_VECTOR(23 DOWNTO 0);
111  probe11 : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
112  probe12 : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
113  probe13 : IN STD_LOGIC_VECTOR(31 DOWNTO 0);
114  probe14 : IN STD_LOGIC_VECTOR(31 DOWNTO 0)
115 
116 );
117 END COMPONENT ;
118 
119 
120 begin
121 
122 
123 timeout_enable <= '1'; --needed?
124 clear_local_l1id <= l1id_continuity_control(4);
125 clear_local_ECRid <= l1id_continuity_control(5);
126 
127 process (clock) begin
128  if rising_edge (clock) then
129  if reset = '1' then
130  l1id_del <= '0';
131  l1id_compare <= '0';
132  ECRid_compare <= '0';
133  else
134  l1id_del <= l1a;
135  l1id_compare <= l1id_del;
136  ECRid_del <= ECR;
137  ECRid_compare <= ECRid_del;
138  end if;
139  end if;
140 end process;
141 
142 -- timeout counter --if timeout = 1, then don't log any errors.
143 process (clock) begin
144  if rising_edge (clock) then
145  if (reset = '1') or ((L1A = '1') and (word_counter = 3)) then
146  timeout_counter <= (others=> '0');
147  timeout <= '0';
148  elsif (timeout_enable = '1') and (timeout_counter <= timeout_threshold) then
149  timeout_counter <= (timeout_counter + '1');
150  elsif (timeout_counter >= timeout_threshold) then
151  timeout <= '1';
152  else
153  timeout_counter <= timeout_counter;
154  timeout <= timeout;
155 
156  end if;
157  end if;
158  end process;
159 
160 
161 -- ttc word counter
162 process (clock) begin
163  if rising_edge (clock) then
164  if (reset = '1') then
165  word_counter <= (others=> '0');
166  elsif (L1A = '1') or (ECR = '1') then
167  word_counter <= (word_counter + 1);
168  else
169  word_counter <= word_counter;
170  end if;
171  end if;
172  end process;
173 
174 --L1ID counter
175  process (clock) begin
176  if rising_edge (clock) then
177  if (reset = '1') or (clear_local_l1id = '1') then
178  L1id_counter <= (others=> '0');
179 
180  elsif (L1A = '1') and (timeout = '0') and (word_counter = x"2") then --and (L1id_counter /= X"FFFFFF")
181  L1id_counter <= (L1id_counter + '1');
182  elsif (L1A = '1') and (timeout = '1') and (word_counter = x"2") then
183  L1id_counter <= L1id;
184  elsif (l1id_compare = '1') and (word_counter = x"3") and (L1id_counter /= L1ID) then
185  L1id_counter <= L1ID;
186 
187  else
188  L1id_counter <= L1id_counter;
189 
190  end if;
191  end if;
192  end process;
193 
194 
195 
196 --L1ID error counter
197 
198  process (clock) begin
199  if rising_edge (clock) then
200  if (reset = '1') or (clear = '1') then
201  L1id_error_counter <= (others=> '0');
202  triggered <= '0';
203  capture <= '0';
204  l1id_local_miss_i <= (others => '0');
205  l1id_ttc_miss_i <= (others => '0');
206  elsif (armed_pulse = '1') then
207  triggered <= '0';
208  elsif (l1id_compare = '1')and (word_counter = x"3") and ((ECRid_counter & L1id_counter) /= (ECRid & L1ID)) and ((ECRid & L1ID) /= x"00000000") and timeout = '0' then
209  L1id_error_counter <= L1id_error_counter + '1';
210  if (armed_stat = '1') then
211  triggered <= '1';
212  capture <= '1';
213  l1id_local_miss_i <= ECRid_counter & l1id_counter;
214  l1id_ttc_miss_i <= ECRid & l1id;
215  else
216  triggered <= triggered;
217  l1id_local_miss_i <= l1id_local_miss_i;
218  l1id_ttc_miss_i <= l1id_ttc_miss_i;
219  capture <= capture;
220  end if;
221  else
222  L1id_error_counter <= L1id_error_counter;
223 -- triggered <= triggered;
224 -- l1id_local_miss <= l1id_local_miss;
225 -- l1id_ttc_miss <= l1id_ttc_miss;
226 -- capture <= capture;
227  end if;
228  end if;
229  end process;
230 
231 l1id_local_miss <= l1id_local_miss_i;
232 l1id_ttc_miss <= l1id_ttc_miss_i;
233 
234 l1id_error_count <= L1id_error_counter;
235 
236 
237 --L1id compare
238 process (clock) begin
239  if rising_edge (clock) then
240  if (reset = '1') then
241  L1id_mismatch <= '0';
242  elsif (L1id_counter /= L1id) and (timeout = '0') then
243  L1id_mismatch <= '1';
244  else
245  L1id_mismatch <= L1id_mismatch;
246  end if;
247  end if;
248  end process;
249 
250 
251 --ECRID counter
252  process (clock) begin
253  if rising_edge (clock) then
254  if (reset = '1') or (clear_local_ECRid = '1')then
255  ECRid_counter <= (others=> '0');
256 
257  elsif (ECR = '1') and (timeout = '0') and (word_counter = x"2") then --and (L1id_counter /= X"FFFFFF")
258  ECRid_counter <= (ECRid_counter + '1');
259  elsif (ECR = '1') and (timeout = '1') and (word_counter = x"2") then
260  ECRid_counter <= ECRid;
261  elsif (l1id_compare = '1') and (word_counter = x"3") and (ECRid_counter /= ECRID) then
262  ECRid_counter <= ECRID;
263 
264  else
265  ECRid_counter <= ECRid_counter;
266 
267  end if;
268  end if;
269  end process;
270 
271 
272 --Duplicate L1ID checker
273 process (clock) begin
274  if rising_edge (clock) then
275  if (reset = '1') then
276  current_l1id <= (others=> '0');
277  last_l1id <= (others=> '0');
278  elsif (word_counter = x"3")and(l1id_compare = '1') then
279  current_l1ID <= (ECRid & L1id);
280  last_L1id <= current_l1ID;
281  end if;
282  end if;
283 end process;
284 
285 process (clock) begin
286  if rising_edge (clock) then
287  if (reset = '1') or (clear = '1')then
288  repeat_counter_i <= (others=> '0');
289  elsif (word_counter = x"3") and (l1id_compare = '1')and (current_l1id = (ECRid & L1id)) and (current_l1id /= x"00000000") then
290  repeat_counter_i <= (repeat_counter_i + 1);
291  end if;
292  end if;
293  end process;
294 
295  repeat_counter <= repeat_counter_i;
296 -------control and status -------------------
297 
298 -------sample the pulse reg in the pp_clock domain ------
299 --armed_s samples the pulse bit running on ipb_clk
300 --armed_s_del sample armed_s synchronously on pp_clock
301 --armed_stat is the user's status flag indicating the mech is armed, but not triggered
302 
303 --clear pulse happens on trailing edge of ipbus pulse
304 process(clock) begin
305  if rising_edge (clock) then
306  clear_s <= l1id_continuity_control(1);
307  clear_s_del <= clear_s;
308  end if;
309 end process;
310 
311 clear <= clear_s_del and not clear_s;
312 
313 process(clock) begin
314  if rising_edge (clock) then
315  armed_s <= l1id_continuity_control(0);
316  armed_s_del <= armed_s;
317  end if;
318 end process;
319 
320 armed_pulse <= armed_s_del and not armed_s;
321 
322 process(clock) begin
323  if rising_edge (clock) then
324  if (armed_pulse = '1') then
325  armed_stat <= '1';
326  elsif (triggered = '1') or (clear = '1') or (reset = '1') then --(ipb_rst = '1') or
327  armed_stat <= '0';
328  else
329  armed_stat <= armed_stat;
330  end if;
331  end if;
332 end process;
333 
334 
335 l1id_continuity_status <= x"0000000" & "00" & triggered & armed_stat;
336 
337 ila_l1id_cont_check: ila_l1id_cont
338 port map (
339  clk => clock,
340  probe0 => word_counter, --2
341  probe1(0) => l1id_compare, --1
342  probe2(0) => L1A, --1
343  probe3(0) => ECR, --1
344  probe4(0) => triggered, --1
345  probe5(0) => capture, --1
346  probe6(0) => armed_stat, --1
347  probe7(0) => timeout, --1
348  probe8 => L1id, --24
349  probe9 => ECRID, --8
350  probe10 => L1id_counter, --24
351  probe11 => ECRID_counter, --8
352  probe12 => repeat_counter_i, --32
353  probe13 => current_l1id, --32
354  probe14 => last_l1id --32
355 
356 );
357 
358 
359 end RTL;