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

Back to ROD documentation
trailer_map.vhd
1 ----------------------------------------------------------------------------------
2 -- Company: University of Cambridge
3 -- Engineer: Ed Flaherty
4 --
5 -- Create Date: 15.02.2020 12:57:20
6 -- Design Name:
7 -- Module Name: trailer_map - 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 
25 -- Uncomment the following library declaration if using
26 -- arithmetic functions with Signed or Unsigned values
27 --use IEEE.NUMERIC_STD.ALL;
28 
29 -- Uncomment the following library declaration if instantiating
30 -- any Xilinx leaf cells in this code.
31 --library UNISIM;
32 --use UNISIM.VComponents.all;
33 
34 entity trailer_map is
35  generic (
36  jfex : integer := 1
37  );
38  Port (
39  pp_clock : in STD_LOGIC;
40  reset : in STD_LOGIC;
41  current_chan : in STD_LOGIC_VECTOR (4 downto 0);
42  chan_len_error : in STD_LOGIC;
43  chan_hdr_crc_err : in STD_LOGIC;
44  chan_crc20_err : in STD_LOGIC;
45  L1ID_eq : in STD_LOGIC;
46  chan_crc20_samp : in STD_LOGIC;
47  crc9_err_samp : in STD_LOGIC;
48  len_err_samp : in STD_LOGIC;
49  L1ID_eq_samp : in STD_LOGIC;
50  timeout_error : in STD_LOGIC;
51  clear_map : in STD_LOGIC;
52  sel_corr_trailer : in STD_LOGIC;
53  error_map : out STD_LOGIC_VECTOR(11 downto 0);
54  lmem : out STD_LOGIC_VECTOR(3 downto 0);
55  rod_err_map : out STD_LOGIC_VECTOR(6 downto 0);
56  debug_pkt_module_map: out STD_LOGIC_VECTOR(11 downto 0)
57 
58  );
59 end trailer_map;
60 
61 architecture RTL of trailer_map is
62 
63 component onehot_dec is
64 
65  generic(
66  n : integer := 4;
67  m : integer := 16
68  );
69  Port (
70  bin_in : in STD_LOGIC_VECTOR (n-1 downto 0);
71  oh_out : out STD_LOGIC_VECTOR (m-1 downto 0));
72 
73 end component;
74 
75 signal error_map_reg : STD_LOGIC_VECTOR(11 downto 0);
76 signal chan_sel : STD_LOGIC_VECTOR(15 downto 0);
77 signal crc20_err : STD_LOGIC;
78 signal len_err : STD_LOGIC;
79 signal crc9_err : STD_LOGIC;
80 signal L1id_err : STD_LOGIC;
81 signal any_err : STD_LOGIC;
82 
83 signal lmem_reg : STD_LOGIC_VECTOR(3 downto 0);
84 
85 signal chan_in : STD_LOGIC_VECTOR (3 downto 0);
86 signal module_in : STD_LOGIC_VECTOR (3 downto 0);
87 signal module_sel : STD_LOGIC_VECTOR(15 downto 0);
88 
89 signal current_chan_del : STD_LOGIC_VECTOR (4 downto 0);
90 signal crc20_reg : STD_LOGIC;
91 signal len_err_reg : STD_LOGIC;
92 signal crc9_reg : STD_LOGIC;
93 signal L1id_err_reg : STD_LOGIC;
94 signal timeout_err_reg : STD_LOGIC;
95 signal flag : STD_LOGIC_VECTOR(11 downto 0);
96 signal lflag : STD_LOGIC_VECTOR(3 downto 0);
97 signal corr_trailer_flag : STD_LOGIC;
98 
99 begin
100 
101 
102 crc20_err <= chan_crc20_err and chan_crc20_samp;
103 len_err <= chan_len_error and len_err_samp;
104 crc9_err <= chan_hdr_crc_err and crc9_err_samp;
105 L1id_err <= L1id_eq_samp and not L1id_eq;
106 any_err <= crc9_err or len_err or crc20_err or L1id_err;
107 
108 process (pp_clock) begin
109  if rising_edge (pp_clock) then
110  current_chan_del <= current_chan;
111  end if;
112 end process;
113 
114 ------------------------------------------
115 ---- ROD ERROR MAP -------------------------
116 ------------------------------------------
117 
118 --FEX timeout Error
119 process (pp_clock) begin
120  if rising_edge (pp_clock) then
121  if (reset = '1') or (clear_map = '1') then
122  timeout_err_reg <= '0';
123  elsif (timeout_error = '1') then
124  timeout_err_reg <= '1';
125  else
126  timeout_err_reg <= timeout_err_reg;
127  end if;
128  end if;
129 end process;
130 rod_err_map(0) <= timeout_err_reg;
131 
132 
133 
134 --Header Mismatch
135 process (pp_clock) begin
136  if rising_edge (pp_clock) then
137  if (reset = '1') or (clear_map = '1') then
138  L1id_err_reg <= '0';
139  elsif (L1id_err = '1') then
140  L1id_err_reg <= '1';
141  else
142  L1id_err_reg <= L1id_err_reg;
143  end if;
144  end if;
145 end process;
146 rod_err_map(1) <= L1id_err_reg;
147 
148 -- Length Mismatch
149 process (pp_clock) begin
150  if rising_edge (pp_clock) then
151  if (reset = '1') or (clear_map = '1') then
152  len_err_reg <= '0';
153  elsif (len_err = '1') then
154  len_err_reg <= '1';
155  else
156  len_err_reg <= len_err_reg;
157  end if;
158  end if;
159 end process;
160 --rod_err_map(2) <= len_err_reg;
161 --note that len_err has been or'd with len_err_reg in order to produce the flag one cycle early
162 --this allows an error in the last event fragment to be propagated to the event trailer crc20 calculation one cycle early
163 rod_err_map(2) <= len_err_reg or len_err;
164 
165 --protocol error-- this is an OR of all of the Aurora errors to be passed through as a tuser
166 rod_err_map(3) <= '0';
167 
168 
169 --Header CRC error crc9_err
170 process (pp_clock) begin
171  if rising_edge (pp_clock) then
172  if (reset = '1') or (clear_map = '1') then
173  crc9_reg <= '0';
174  elsif (crc9_err = '1') then
175  crc9_reg <= '1';
176  else
177  crc9_reg <= crc9_reg;
178  end if;
179  end if;
180 end process;
181 --rod_err_map(4) <= crc9_reg;
182 --note that crc9_err has been or'd with len_err_reg in order to produce the flag one cycle early
183 --this allows an error in the last event fragment to be propagated to the event trailer crc20 calculation one cycle early
184 rod_err_map(4) <= crc9_reg or crc9_err;
185 
186 --Payload CRC error
187 process (pp_clock) begin
188  if rising_edge (pp_clock) then
189  if (reset = '1') or (clear_map = '1') then
190  crc20_reg <= '0';
191  elsif (crc20_err = '1') then
192  crc20_reg <= '1';
193  else
194  crc20_reg <= crc20_reg;
195  end if;
196  end if;
197 end process;
198 
199 --rod_err_map(5) <= crc20_reg;
200 --note that crc20_err has been or'd with len_err_reg in order to produce the flag one cycle early
201 --this allows an error in the last event fragment to be propagated to the event trailer crc20 calculation one cycle early
202 rod_err_map(5) <= crc20_reg or crc20_err;
203 
204 
205 -----------------------------------------------------------------------------------
206 --corrective trailer flag
207 process (pp_clock) begin
208  if rising_edge (pp_clock) then
209  if (reset = '1') or (clear_map = '1') then
210  corr_trailer_flag <= '0';
211  elsif (sel_corr_trailer = '1') then
212  corr_trailer_flag <= '1';
213  else
214  corr_trailer_flag <= corr_trailer_flag;
215  end if;
216  end if;
217 end process;
218 --Corrective Trailer
219 --rod_err_map(6) <= corr_trailer_flag or sel_corr_trailer;
220 rod_err_map(6) <= '0';
221 -----------------------------------------------------efex-specific-source-module-error-map---------------------------------------------------
222 
223 
224 gen_efex_map: if jfex=0 generate
225 
226 chan_selector: onehot_dec
227  port map (
228  bin_in => current_chan_del(3 downto 0),
229  oh_out => chan_sel
230  );
231 
232 debug_pkt_module_map <= chan_sel(11 downto 0);
233 
234 process (pp_clock) begin
235  if rising_edge (pp_clock) then
236  -- if reset = '1' then
237  -- if (reset = '1') or (clear_map = '1') then
238  if (clear_map = '1') then
239  error_map_reg <= (others => '0');
240  else
241  for I in 0 to 11 loop
242 -- if ((chan_sel(I) = '1') and (any_err = '1') ) then --need to factor chan enable here to avoid errors from off channels?
243  if ((flag(I) = '1') ) then --need to factor chan enable here to avoid errors from off channels?
244  error_map_reg(I) <= '1';
245  end if;
246  end loop;
247  end if;
248  end if;
249 end process;
250 
251 process(chan_sel, any_err) begin
252  for K in 0 to 11 loop
253  flag(K) <= chan_sel(K) and any_err;
254  end loop;
255 end process;
256 
257 process(error_map_reg, flag) begin
258  for K in 0 to 11 loop
259  error_map(K) <= error_map_reg(K) or flag(K);
260  end loop;
261 end process;
262 
263 
264 --error_map <= error_map_reg;
265 lmem <= (others => '0');
266 
267 end generate gen_efex_map;
268 -----------------------------------------------------jfex-specific--source-module-error-map-----------------------------------------------------------
269 gen_jfex_map: if jfex=1 generate
270 chan_selector: onehot_dec
271  port map (
272  bin_in => chan_in(3 downto 0),
273  oh_out => chan_sel
274  );
275 
276 debug_pkt_module_map <= chan_sel(11 downto 0);
277 chan_in <= "00" & current_chan_del(1 downto 0);
278 
279 module_selector: onehot_dec
280  port map (
281  bin_in => module_in,
282  oh_out => module_sel
283  );
284 
285 module_in <= "0" & current_chan_del(4 downto 2);
286 
287 ---set the link map: lmem
288 process (pp_clock) begin
289  if rising_edge (pp_clock) then
290  if reset = '1' then
291  lmem_reg <= (others => '0');
292  else
293  for I in 0 to 3 loop
294 -- if ((chan_sel(I) = '1') and (any_err = '1') ) then
295  if ((lflag(I) = '1') ) then
296  lmem_reg(I) <= '1';
297  end if;
298  end loop;
299  end if;
300  end if;
301 end process;
302 
303 process(chan_sel, any_err) begin
304  for K in 0 to 3 loop
305  lflag(K) <= chan_sel(K) and any_err;
306  end loop;
307 end process;
308 
309 --process(error_map_reg, flag) begin
310 process(error_map_reg, flag, lmem_reg, lflag) begin
311  for K in 0 to 3 loop
312  lmem(K) <= lmem_reg(K) or lflag(K);
313  end loop;
314 end process;
315 --lmem <= lmem_reg(3 downto 0);
316 
317 
318 --set the module error map
319 
320 process (pp_clock) begin
321  if rising_edge (pp_clock) then
322  if reset = '1' then
323  error_map_reg <= (others => '0');
324  else
325  for J in 0 to 5 loop
326 -- if ((module_sel(J) = '1') and (any_err = '1') ) then
327  if ((flag(J) = '1')) then
328  error_map_reg(J) <= '1';
329  end if;
330  end loop;
331  end if;
332  end if;
333 end process;
334 
335 process(module_sel, any_err) begin
336  for K in 0 to 5 loop
337  flag(K) <= module_sel(K) and any_err;
338  end loop;
339 end process;
340 
341 process(module_sel, any_err) begin
342  for K in 6 to 11 loop
343  flag(K) <= '0';
344  end loop;
345 end process;
346 
347 process(error_map_reg, flag) begin
348  for K in 0 to 5 loop
349  error_map(K) <= error_map_reg(K) or flag(K);
350  end loop;
351 end process;
352 
353 process(error_map_reg, flag) begin
354  for K in 6 to 11 loop
355  error_map(K) <= error_map_reg(K);
356  end loop;
357 end process;
358 --error_map <= error_map_reg;
359 
360 end generate gen_jfex_map;
361 
362 end RTL;
363 
364