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

Back to eFEX documentation
data_alignment.vhd
Go to the documentation of this file.
1 
10 
11 library IEEE;
12 use IEEE.STD_LOGIC_1164.all;
13 use IEEE.NUMERIC_STD.all;
14 
15 library algolib;
16 use algolib.AlgoDataTypes.all;
17 library TOB_rdout_lib;
18 use TOB_rdout_lib.TOB_rdout_ip_pkg.all;
19 use TOB_rdout_lib.data_type_pkg.all;
20 use work.synch_type.all;
21 use work.EfexDataFormats.all;
22 
24 entity data_alignment is
25  generic(n_channels : natural := N_MGT;
26  FPGA_NUMBER : integer);
27  port(
28  TTC_clk : in std_logic;
29  clk280 : in std_logic;
30  rx_clk280 : in std_logic_vector(n_channels - 1 downto 0);
31  MGT_Commadet : in std_logic_vector(n_channels - 1 downto 0);
32  enable_mgt : in std_logic_vector(n_channels - 1 downto 0);
33  BC_Reg_sel : in std_logic_vector(255 downto 0);
34  mux_sel : in std_logic_vector(255 downto 0);
35  sel_bcn_or_bc_cnt : in std_logic; -- selects between real data BC value and BC delay counter
36  pseudo_orbit : out std_logic;
37  start : in std_logic;
38  start_pulse_rst : out std_logic;
39  rx_resetdone : in std_logic_vector(n_channels - 1 downto 0);
40  reset : in std_logic;
41  DataToAlgo : out Algoinput;
42  RAW_data : out RAW_data_227_type;
43  bc_cntr_0 : out std_logic_vector(111 downto 0);
44  bc_cntr_1 : out std_logic_vector(111 downto 0);
45  bc_cntr_2 : out std_logic_vector(111 downto 0);
46  bc_cntr_3 : out std_logic_vector(111 downto 0);
47  bc_mux_cntr_0 : out std_logic_vector(111 downto 0);
48  bc_mux_cntr_1 : out std_logic_vector(111 downto 0);
49  bc_mux_cntr_2 : out std_logic_vector(111 downto 0);
50  bc_mux_cntr_3 : out std_logic_vector(111 downto 0);
51  bcn_synch : out std_logic_vector(63 downto 0);
52  crc_error_chan : out std_logic_vector(63 downto 0);
53  -- for debug
54  data_readout_0 : out std_logic_vector(223 downto 0); -- for debug
55  data_readout_1 : out std_logic_vector(223 downto 0); -- for debug
56  data_readout_2 : out std_logic_vector(223 downto 0); -- for debug
57  data_readout_3 : out std_logic_vector(223 downto 0); -- for debug
58  delay_num : out std_logic_vector(255 downto 0); -- for debug
59  Reg224_latch : out std_logic_vector(n_channels - 1 downto 0); -- for debug
60  ttc_pipe : out std_logic_vector(n_channels - 1 downto 0); -- for debug
61  delay_latch : out std_logic_vector(n_channels - 1 downto 0); -- for debug
62  eFEXPosition : in std_logic_vector(31 downto 0);
63  sel_data_in : in std_logic;
64  ram_data : in ram_data_in;
65  MGT_data : in mgt_data_in;
66  align_frame : in std_logic_vector(n_channels - 1 downto 0);
67  disperr_error : in std_logic_vector(n_channels - 1 downto 0);
68  notable_error : in std_logic_vector(n_channels - 1 downto 0)
69  );
70 end data_alignment;
71 
73 architecture Behavioral of data_alignment is
74 ------------- Begin Cut here for COMPONENT Declaration ------ COMP_TAG
75 
76 
77 
78  signal crc_error_chan_i : std_logic_vector(63 downto 0);
79  signal MGT_Commadet_tmp : std_logic_vector(63 downto 0);
80 
81  -------------------------------------
82 
83  signal data_in_int, ram_data_tmp : mgt_data_in;
84  signal dataout_after_mux ,dataout_after_mux_i ,ram_data_int : mgt_data_out;
85 
86  --signal data_out_reg224 : mgt_data_out;
87  signal dataout_before_mux : mgt_data_out;
88 
89  --signal data_in_int, data_out_int,data_out_reg224: data_path_array (n_channels-1 downto 0);
90 
91  signal sel_reg, sel_mux : std_logic_vector(255 downto 0);
92  --signal crc_error_flag_tmp : std_logic_vector(48 downto 0);
93  signal reg1, reg2, reg3, start_pulse_280 : std_logic;
94 
95  signal temp0, temp1, temp2, start_40, pseudo_orbit_ref, pseudo_orbit_out : std_logic;
96  signal bcn_0, bcn_1, bcn_2, bcn_3, bc_mux_out_0, bc_mux_out_1, bc_mux_out_2, bc_mux_out_3 : std_logic_vector(111 downto 0);
97  signal bcn_tmp_0, bcn_tmp_1, bcn_tmp_2, bcn_tmp_3, bc_mux_tmp_0, bc_mux_tmp_1, bc_mux_tmp_2, bc_mux_tmp_3 : std_logic_vector(111 downto 0);
98  --signal aeqb_ch0, aeqb_ch1, aeqb_ch2, aeqb_ch3, mux_aeqb_ch0, mux_aeqb_ch1, mux_aeqb_ch2, mux_aeqb_ch3 : std_logic_vector(15 downto 0);
99 
100  signal MGT_Commadet_i : std_logic_vector(n_channels - 1 downto 0);
101 
102  type crc_error_40_type is array (n_channels - 1 downto 0) of std_logic;
103  signal crc_error_40_i : crc_error_40_type;
104 
105  --signal disperr_notable_error_i: disperr_notable_error;
106 
107  -- ####### Mark signals ########
108  attribute keep : string;
109  attribute max_fanout : integer;
110  attribute keep of MGT_Commadet_i : signal is "true";
111 -- attribute max_fanout of MGT_Commadet_i : signal is 10;
112  attribute keep of bc_cntr_0 : signal is "true";
113  attribute keep of bc_cntr_1 : signal is "true";
114  attribute keep of bc_cntr_2 : signal is "true";
115  attribute keep of bc_cntr_3 : signal is "true";
116  attribute keep of bc_mux_out_0 : signal is "true";
117  attribute keep of bc_mux_out_1 : signal is "true";
118  attribute keep of bc_mux_out_2 : signal is "true";
119  attribute keep of bc_mux_out_3 : signal is "true";
120  -- #######################################
121 
122 begin
123 
124  -- for debugging
125  data_readout_0 <= dataout_before_mux(16)(223 downto 0);
126  data_readout_1 <= dataout_before_mux(17)(223 downto 0);
127  data_readout_2 <= dataout_before_mux(18)(223 downto 0);
128  data_readout_3 <= dataout_before_mux(19)(223 downto 0);
129  pseudo_orbit <= pseudo_orbit_out;
130 
131  ----------------------------------------------------------------------------------------------------
132  -- bc data before the mux bits asignment
133  ----------------------------------------------------------------------------------------------------
134  bcn_gen : for i in 0 to (15) generate
135  bcn_0(i * 7 + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_before_mux(i + 3 * i)).BCID(6 downto 0);
136  bcn_1(i * 7 + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_before_mux(i + 1 + 3 * i)).BCID(6 downto 0);
137  bcn_2(i * 7 + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_before_mux(i + 2 + 3 * i)).BCID(6 downto 0);
138  bcn_3(i * 7 + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_before_mux(i + 3 + 3 * i)).BCID(6 downto 0);
139  end generate bcn_gen;
140 
141  --------------------------------------------------------------------------------------------------
142  --- Create bc alignment blocks for each mgt 64 before the mux
143  --------------------------------------------------------------------------------------------------
144  bc_alignment_before_mux : for i in 0 to 15 generate
145  bc_align_a : entity work.quad_bc_alignment
146  port map(
147  reset => reset,
148  clk => TTC_clk,
149  start => start_40, -- start pulse for the pseudo orbit state machines
150  bcn_0 => bcn_0(7 * i + 6 downto 7 * i),
151  bcn_1 => bcn_1(7 * i + 6 downto 7 * i),
152  bcn_2 => bcn_2(7 * i + 6 downto 7 * i),
153  bcn_3 => bcn_3(7 * i + 6 downto 7 * i),
154  ref_orbit => pseudo_orbit_ref, -- pseudo orbit reference signal for all channels
155  aeqb_ch0 => open,
156  aeqb_ch1 => open,
157  aeqb_ch2 => open,
158  aeqb_ch3 => open,
159  cntr_ch0 => bcn_tmp_0(7 * i + 6 downto 7 * i),
160  cntr_ch1 => bcn_tmp_1(7 * i + 6 downto 7 * i),
161  cntr_ch2 => bcn_tmp_2(7 * i + 6 downto 7 * i),
162  cntr_ch3 => bcn_tmp_3(7 * i + 6 downto 7 * i)
163  );
164 
165  end generate bc_alignment_before_mux;
166 
167  bcn_before_mux : process(TTC_clk)
168  begin
169  if rising_edge(TTC_clk) then -- selects between real data BC value and BC delay counter to IPBUS
170  if sel_bcn_or_bc_cnt = '1' then -- send real data BC value to IPBUS
171  bc_cntr_0 <= bcn_0;
172  bc_cntr_1 <= bcn_1;
173  bc_cntr_2 <= bcn_2;
174  bc_cntr_3 <= bcn_3;
175  else -- send out the BC delay counter to IPBUS
176  bc_cntr_0 <= bcn_tmp_0;
177  bc_cntr_1 <= bcn_tmp_1;
178  bc_cntr_2 <= bcn_tmp_2;
179  bc_cntr_3 <= bcn_tmp_3;
180  end if;
181  end if;
182  end process;
183 
184  ------------------------------------------------------------------------------------------------------------------
185  --- generate the reference pseudo orbit fo all the mgts, in this instance first quad mgt0 was used as reference.
186  -----------------------------------------------------------------------------------------------------------------
187  orbit_ref_pseudo : entity work.pseudo_orbit_gen
188  port map(
189  clk => TTC_clk,
190  bcn => bcn_0(4 downto 0),
191  pseudo_orbit => pseudo_orbit_ref
192  );
193 
194  -----------------------------------------------------------------------------------------
195  ---- bc data after the bc mux
196  ----------------------------------------------------------------------------------------
197 
198  bcn_mux_gen : for i in 0 to (15) generate
199  bc_mux_out_0(7 * i + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_after_mux(i + 3 * i)).BCID(6 downto 0);
200  bc_mux_out_1(7 * i + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_after_mux(i + 1 + 3 * i)).BCID(6 downto 0);
201  bc_mux_out_2(7 * i + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_after_mux(i + 2 + 3 * i)).BCID(6 downto 0);
202  bc_mux_out_3(7 * i + 6 downto 7 * i) <= MGT_to_SuperCells(dataout_after_mux(i + 3 + 3 * i)).BCID(6 downto 0);
203  end generate bcn_mux_gen;
204 
205  --------------------------------------------------------------------------------------
206  ---- Create bc alignment blocks for each mgt 64 after the mux
207  ---------------------------------------------------------------------------------------
208  bc_alignment_after_mux : for i in 0 to 15 generate
209  bc_align_b : entity work.quad_bc_alignment
210  port map(
211  reset => reset,
212  clk => TTC_clk,
213  start => start_40, -- start pulse for the pseudo orbit state machines
214  bcn_0 => bc_mux_out_0(7 * i + 6 downto 7 * i),
215  bcn_1 => bc_mux_out_1(7 * i + 6 downto 7 * i),
216  bcn_2 => bc_mux_out_2(7 * i + 6 downto 7 * i),
217  bcn_3 => bc_mux_out_3(7 * i + 6 downto 7 * i),
218  ref_orbit => pseudo_orbit_out, -- pseudo orbit reference signal for all channels
219  aeqb_ch0 => open,
220  aeqb_ch1 => open,
221  aeqb_ch2 => open,
222  aeqb_ch3 => open,
223  cntr_ch0 => bc_mux_tmp_0(7 * i + 6 downto 7 * i),
224  cntr_ch1 => bc_mux_tmp_1(7 * i + 6 downto 7 * i),
225  cntr_ch2 => bc_mux_tmp_2(7 * i + 6 downto 7 * i),
226  cntr_ch3 => bc_mux_tmp_3(7 * i + 6 downto 7 * i)
227  );
228  end generate bc_alignment_after_mux;
229 
230  bcn_after_mux : process(TTC_clk)
231  begin
232  if rising_edge(TTC_clk) then -- selects between real data BC value and BC delay counter to IPBUS
233  if sel_bcn_or_bc_cnt = '1' then -- send real data BC value to IPBUS
234  bc_mux_cntr_0 <= bc_mux_out_0;
235  bc_mux_cntr_1 <= bc_mux_out_1;
236  bc_mux_cntr_2 <= bc_mux_out_2;
237  bc_mux_cntr_3 <= bc_mux_out_3;
238  else -- send out the BC delay counter to IPBUS
239  bc_mux_cntr_0 <= bc_mux_tmp_0;
240  bc_mux_cntr_1 <= bc_mux_tmp_1;
241  bc_mux_cntr_2 <= bc_mux_tmp_2;
242  bc_mux_cntr_3 <= bc_mux_tmp_3;
243  end if;
244  end if;
245  end process;
246 
247  ---------------------------------------------------------------------------------------------------------------------
248  --- Generate the reference pseudo orbit fo all the mgts,. in this instance first quad mgt0 was used as reference.
249  --------------------------------------------------------------------------------------------------------------------
250  orbit_ref_pseudo_b : entity work.pseudo_orbit_gen
251  port map(
252  clk => TTC_clk,
253  bcn => bc_mux_out_0(4 downto 0),
254  pseudo_orbit => pseudo_orbit_out
255  );
256 
257  ---------------------------------------------------------
258  -- Generates start pulse for the bc alignment block.
259  --------------------------------------------------------
260  start_pulse_40 : process(TTC_clk)
261  begin
262  if TTC_clk'event and TTC_clk = '1' then
263  temp0 <= start;
264  temp1 <= temp0;
265  temp2 <= temp1;
266  start_40 <= temp1 and not temp2;
267  end if;
268  end process;
269  start_pulse_rst <= start_40;
270 
271  --------------------------------------------------------------------------------------------------------------------------
272  ---- synchronisation logic block that generates n-channels of synchronisations for n_channels of MGTs
273  --------------------------------------------------------------------------------------------------------------------------
274  synch_gen : for i in 0 to (n_channels - 1) generate
275  u0 : entity work.top_synch
276  port map(
277  rx_clk280 => rx_clk280(i),
278  TTC_clk => TTC_clk,
279  reset => reset,
280  enable_mgt => enable_mgt(i),
281  MGT_Commadet => MGT_Commadet_i(i),
282  reg_sel => sel_reg(i + 3 + 3 * i downto i + 3 * i),
283  mux_sel => sel_mux(i + 3 + 3 * i downto i + 3 * i),
284  start => start_pulse_280,
285  rx_resetdone => rx_resetdone(i),
286  reg224_latch => Reg224_latch(i),
287  delay_latch => delay_latch(i),
288  ttc_pipe => ttc_pipe(i),
289  delay_num => delay_num(i + 3 + 3 * i downto i + 3 * i),
290  bcn_synch => bcn_synch(i),
291  data_out_reg224 => dataout_before_mux(i)(223 downto 0), -- data before mux
292  disp_notable_error => dataout_after_mux_i(i)(225 downto 224), -- two bit errors
293  crc_error_out => dataout_after_mux_i(i)(227),
294  align_frame_out => dataout_after_mux_i(i)(226),
295  data_out => dataout_after_mux_i(i)(223 downto 0),
296  data_in => data_in_int(i),
297  align_frame => align_frame(i),
298  disperr_error => disperr_error(i),
299  notable_error => notable_error(i),
300  crc_error_in => crc_error_chan_i(i)
301  );
302 
303  --- crc generation
304  u1 : entity work.crc_checker
305  port map(
306  clk => rx_clk280(i),
307  reset => reset,
308  enable_mgt => enable_mgt(i),
309  mgt_commdet => MGT_Commadet_i(i),
310  rxdata => data_in_int(i),
311  crc_error => crc_error_chan_i(i)
312  );
313 
314  ram_data_int(i) <= ram_data(i);
315  data_in_int(i) <= MGT_data(i);
316  MGT_Commadet_i(i) <= MGT_Commadet(i);
317 
318  end generate synch_gen;
319 
320  crc_error_chan <= crc_error_chan_i;
321  sel_reg <= BC_Reg_sel;
322  sel_mux <= mux_sel;
323 
325  start_pulse : process(clk280)
326  begin
327  if rising_edge(clk280) then
328  reg1 <= start;
329  reg2 <= reg1;
330  reg3 <= reg2;
331  start_pulse_280 <= reg2 and not reg3;
332  end if;
333  end process;
334 
335  dataout_after_mux <= ram_data_int when sel_data_in ='1' else dataout_after_mux_i ;
336 
337  -- MGT_Commadet_tmp(i) when sel_data_in = '1' else MGT_Commadet(i)
338 
339  -----------------------------------------------------------------------------------------
340  ------------------------------------------------------------------------------------------
341  fibre_map : entity work.fibremap_block
342  generic map(FPGA_NUMBER => FPGA_NUMBER)
343  port map(
345  MGT_data_in => dataout_after_mux,
346  RAW_data_out => RAW_data,
347  DataToAlg_out => DataToAlgo);
348 
349 
350 
351 
352 
353 -- crc_scope : ila_0
354 --PORT MAP (
355 -- clk => clk280,
356 -- probe0(227 downto 0) => dataout_after_mux(0)(227 downto 0),
357 -- probe0(259 downto 228) => data_in_int(0),
358 -- probe0(260) => crc_error_chan_i(0),
359 -- probe0(261) => crc_error_40_i(0),
360 -- probe0(262) => MGT_Commadet_i(0),
361 -- probe0(486 downto 263)=> dataout_before_mux(0)(223 downto 0)
362 --);
363 
364 end Behavioral;
External data-types and functions.
eFEX data-types and functions
crc checker
Definition: crc_checker.vhd:11
in reset std_logic
reset
Definition: crc_checker.vhd:16
in clk std_logic
MGT rx clock.
Definition: crc_checker.vhd:14
in mgt_commdet std_logic
MGT commadet.
Definition: crc_checker.vhd:19
in rxdata std_logic_vector( 31 downto 0)
MGT rx data.
Definition: crc_checker.vhd:21
out crc_error std_logic
crc error crc error in 40MHz clock domain
Definition: crc_checker.vhd:25
Data Alignment module.
Data Alignment module.
in eFEXPosition std_logic_vector( 31 downto 0)
Geographical position of eFEX module for dynamic mapping.
eFEX Fibre mapping module
out DataToAlg_out Algoinput
output to algorithm block
in MGT_data_in mgt_data_out
data in from MGT
in eFEXPosition_in std_logic_vector( 31 downto 0)
Geographical position of eFEX module for dynamic mapping.
out RAW_data_out RAW_data_227_type
datata out to readout block
pseudo orbit gen
in clk std_logic
ttc clock
in bcn std_logic_vector( 4 downto 0)
5 lsb of the bcn kn the data
out pseudo_orbit std_logic
pseudo orbit pulse generated
quad bc alignment
in reset std_logic
reset
out cntr_ch2 std_logic_vector( 6 downto 0)
counter value of channel 2
out aeqb_ch1 std_logic
two counter equal in channel 1
out aeqb_ch2 std_logic
two counter equal in channel 2
in bcn_2 std_logic_vector( 6 downto 0)
bunch crossing number of channel 2
in clk std_logic
TTC 40MHz clock.
in bcn_0 std_logic_vector( 6 downto 0)
bunch crossing number of channel 1
out aeqb_ch0 std_logic
two counter equal in channel 0
out aeqb_ch3 std_logic
two counter equal in channel 3
in bcn_1 std_logic_vector( 6 downto 0)
bunch crossing number of channel 3
in bcn_3 std_logic_vector( 6 downto 0)
bunch crossing number of channel 3
out cntr_ch0 std_logic_vector( 6 downto 0)
counter value of channel 0
in start std_logic
start pulse
out cntr_ch1 std_logic_vector( 6 downto 0)
counter value of channel 1
out cntr_ch3 std_logic_vector( 6 downto 0)
counter value of channel 3
in ref_orbit std_logic
orbit reference signal
Top Synchronisation.
Definition: top_synch.vhd:24
in rx_clk280 std_logic
rx clock of the mgt
Definition: top_synch.vhd:28
out delay_num std_logic_vector( 3 downto 0)
first stage dealy counter value
Definition: top_synch.vhd:52
in reset std_logic
reset active high
Definition: top_synch.vhd:32
out crc_error_out std_logic
crc_error to the error counter
Definition: top_synch.vhd:62
in rx_resetdone std_logic
rx reset done of the MGT
Definition: top_synch.vhd:44
in MGT_Commadet std_logic
comma detected for incoming data
Definition: top_synch.vhd:36
out delay_latch std_logic
delay latch
Definition: top_synch.vhd:48
in mux_sel std_logic_vector( 3 downto 0)
setting BC mux
Definition: top_synch.vhd:40
in align_frame std_logic
bit indicating if data is an alignment frame or not
Definition: top_synch.vhd:66
in notable_error std_logic
notable channel error
Definition: top_synch.vhd:72
in disperr_error std_logic
disperr channel error
Definition: top_synch.vhd:70
in data_in std_logic_vector( 31 downto 0)
rx data in
Definition: top_synch.vhd:68
in start std_logic
start pulse for the calibration to start
Definition: top_synch.vhd:42
out reg224_latch std_logic
latch enable
Definition: top_synch.vhd:46
in crc_error_in std_logic
crc channel error
Definition: top_synch.vhd:75
in enable_mgt std_logic
enable mgt rx register
Definition: top_synch.vhd:34
out disp_notable_error std_logic_vector( 1 downto 0)
combined disperr and notable errors
Definition: top_synch.vhd:58
out ttc_pipe std_logic
ttc pipe
Definition: top_synch.vhd:50
out data_out_reg224 std_logic_vector( 223 downto 0) :=( others => '0')
data before mux
Definition: top_synch.vhd:56
out align_frame_out std_logic
align frame output
Definition: top_synch.vhd:60
in TTC_clk std_logic
ttc clk of 40MHz
Definition: top_synch.vhd:30
out bcn_synch std_logic
bcn synch
Definition: top_synch.vhd:54
out data_out std_logic_vector( 223 downto 0)
data out of 224 bits
Definition: top_synch.vhd:64
in reg_sel std_logic_vector( 3 downto 0)
setting the first stage mux
Definition: top_synch.vhd:38