CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
main_crt_vs_cp.vhd
Go to the documentation of this file.
1 
20 
21 library IEEE;
22 use IEEE.STD_LOGIC_1164.ALL;
23 use IEEE.NUMERIC_STD.ALL;
24 use IEEE.STD_LOGIC_UNSIGNED.ALL;
25 use IEEE.STD_LOGIC_ARITH.CONV_STD_LOGIC_VECTOR;
26 
27 LIBRARY work;
28 use work.CMXpackage.all;
29 use work.CMX_flavor_package.all;
30 
31 
32 
33 entity main_crt is
34  port(
35  clk : in std_logic; -- clock
36  thresholds : in arr_16(max_cps*16*4-1 downto 0); -- thresholds
37  datai : in arr_4Xword(max_cps-1 downto 0); -- input data
38  dout_lcl : out T_SLV48; -- local output (multiplicity), excluding parity
39  dout_lcl_ro : out T_SL; -- local overflow
40  par_err_lcl : in T_SL; -- parity error local
41  force : in T_SL; -- force
42  disable_overflow_mask : in std_logic_vector(15 downto 0)
43  );
44 
45 end main_crt;
46 
47 architecture struct of main_crt is
48 
49 
50 -- signal declarations
51 
52  signal sum_internal : T_SLV48;
53  signal thrPat : thPatL_type(max_cps-1 downto 0);
54  signal mult : mult_type(max_cps-1 downto 0);
55  signal threshold_table : threshold_type(max_cps-1 downto 0);
56 
57 
58  signal roi_posRxA : Rxpos_type(max_cps-1 downto 0);
59  signal roi_posRxB : Rxpos_type(max_cps-1 downto 0);
60  signal roi_posRx : Rxpos_type(max_cps-1 downto 0);
61  signal ntobsA : ntobsA_type(max_cps-1 downto 0);
62  signal loc : loc_type(max_cps-1 downto 0);
63 
64  signal TOBs : arr_TOB(max_cps*max_tobs_pcp-1 downto 0); -- Trigger Objects
65  signal data_high : High_word(max_cps-1 downto 0):=(others =>(others =>(others => '0')));
66  signal data_low : Low_word(max_cps-1 downto 0):=(others =>(others =>(others => '0')));
67 
68  signal overflow : T_SLV14;
69  signal bitofw : T_SL;
70  signal bitofw_del0 : T_SL;
71  signal bitofw_del1 : T_SL;
72 
73  signal ntobs_low : ntobsA_type(max_cps-1 downto 0);
74  signal ntobs_high : ntobsA_type(max_cps-1 downto 0);
75  signal ntobs_tot : ntobstot_type(max_cps-1 downto 0);
76 
77  signal par_err_lcl_d0 : T_SL; -- parity error local delayed
78  signal dout_lcl_tmp : T_SLV48;
79 
80 
81 begin
82 
83 
84 
85 
86  data_map: for i in 0 to (max_cps-1) generate
87 
88  TOBs((5*i)+4).ISO <= data_high(i)(3)(6 downto 2);
89  TOBs((5*i)+4).CLE <= data_low(i)(3)( 7 downto 0);
90  TOBs((5*i)+4).POS <= (others=>'0');
91 
92  TOBs((5*i)+3).ISO <= data_low(i)(3)(14 downto 10);
93  TOBs((5*i)+3).CLE <= data_low(i)(2)(15 downto 8);
94  TOBs((5*i)+3).POS <= (others=>'0');
95 
96  TOBs((5*i)+2).ISO <= data_high(i)(2)(6 downto 2);
97  TOBs((5*i)+2).CLE <= data_low(i)(2)(7 downto 0);
98  TOBs((5*i)+2).POS <= (others=>'0');
99 
100  TOBs((5*i)+1).ISO <= data_high(i)(1)(6 downto 2);
101  TOBs((5*i)+1).CLE <= data_low(i)(1)(15 downto 8);
102  TOBs((5*i)+1).POS <= (others=>'0');
103 
104  TOBs((5*i)+0).ISO <= data_high(i)(0)(6 downto 2);
105  TOBs((5*i)+0).CLE <= data_low(i)(1)(7 downto 0);
106  TOBs((5*i)+0).POS <= (others=>'0');
107 
108 
109  end generate;
110 
111 
112  data_parser_0: for i in 0 to (max_cps-1) generate
113  data_parser_1: for j in 0 to (max_tobs_pcp-2) generate
114  data_low(i)(j) <= datai(i)((24*j)+15 downto (25*j)-j);
115  data_high(i)(j) <= datai(i)((24*j)+23 downto (24*j)+16);
116  end generate data_parser_1;
117  end generate data_parser_0;
118 
119 
120  Rxpos_i: for i in 0 to (max_cps-1) generate -- 0 to 13 (CPs)
121 
122  ntobsA(i) <= Rxpos_sort(conv_integer(datai(i)(7 downto 0)))(7 downto 5);
123  roi_posRxA(i) <= Rxpos_sort(conv_integer(datai(i)(7 downto 0)))(4 downto 0);
124  roi_posRxB(i) <= Rxpos_sort(conv_integer(datai(i)(15 downto 8)))(4 downto 0);
125 
126  with ntobsA(i) select roi_posRx(i) <=
127  roi_posRxB(i) when "000",
128  (roi_posRxB(i)(3 downto 0) & roi_posRxA(i)(0)) when "001",
129  (roi_posRxB(i)(2 downto 0) & roi_posRxA(i)(1 downto 0)) when "010",
130  (roi_posRxB(i)(1 downto 0) & roi_posRxA(i)(2 downto 0)) when "011",
131  (roi_posRxB(i)(0) & roi_posRxA(i)(3 downto 0)) when "100",
132  roi_posRxA(i) when others; -- five or more in first half
133  end generate;
134 
135 
136  loc_i: for i in 0 to (max_cps-1) generate -- 0 to 13 (CPs)
137  loc(i)(0) <= roi_posRx(i)(0) & data_high(i)(0)(0);
138  loc(i)(1) <= roi_posRx(i)(1) & data_high(i)(1)(0);
139  loc(i)(2) <= roi_posRx(i)(2) & data_high(i)(2)(0);
140  loc(i)(3) <= roi_posRx(i)(3) & data_low(i)(3)(8);
141  loc(i)(4) <= roi_posRx(i)(4) & data_high(i)(3)(0);
142  end generate;
143 
144 --
145 -- Thresholds
146 --
147 --
148  threshold_CPs: for i in 0 to (max_cps-1) generate -- 0 to 13 (CPs)
149  threshold_num: for j in 0 to (thresholds_num-1) generate -- 0 to 15 (Thresholds)
150  threshold_slice: for k in 0 to (max_eta_slices-1) generate -- 0 to 3 (Eta slices)
151  threshold_table(i)(j)(k) <= thresholds(16*k+64*i+j)(12 downto 0);
152  end generate threshold_slice;
153  end generate threshold_num;
154  end generate threshold_CPs;
155 
156 
157  process (clk)
158 
159  begin
160  if clk'event and clk = '0' then -- falling clock edge
161 
162 
163  thrPat <= (others => (others => '0'));
164  for i in 0 to (max_cps-1) loop -- 0 to 13 (CPs)
165  for j in 0 to (max_tobs_pcp-1) loop -- 0 to 4 (TOBs)
166  for k in 0 to (thresholds_num-1) loop -- 0 to 15 (Thresholds)
167 
168  if TOBs((max_tobs_pcp*i)+j).CLE > threshold_table(i)(k)(conv_integer(loc(i)(j)))(7 downto 0) and -- thresholds
169  (TOBs((max_tobs_pcp*i)+j).ISO and threshold_table(i)(k)(conv_integer(loc(i)(j)))(12 downto 8)) = threshold_table(i)(k)(conv_integer(loc(i)(j)))(12 downto 8) then -- isolation
170  thrPat(i)((max_tobs_pcp*k)+j) <= '1';
171  end if;
172 
173  -- overflow
174  bitofw_del0 <= bitofw;
175 
176  -- parity error local delay
178 
179  end loop;
180  end loop;
181  end loop;
182 
183  end if;
184  end process;
185 
186  g0: for i in 0 to (max_cps-1) generate -- loop over each CPs
187  g1: for j in 0 to (thresholds_num-1) generate -- loop over each threshold
188  mult(i)(j) <= mult_i(conv_integer(thrPat(i)(5*j+4 downto 5*j)));
189  end generate g1;
190  end generate g0;
191 
192  process (clk)
193 
194  variable xsum : xsum_type(thresholds_num-1 downto 0);
195  variable totsum : totsum_type(thresholds_num-1 downto 0);
196 
197  begin
198  if clk'event and clk = '1' then -- raising clock edge
199 
200  for i in 0 to thresholds_num-1 loop -- loop over each threshold
201  for j in 0 to max_cps/2-1 loop -- loop over 7 pairs of CPs
202 
203  xsum(i)(j) := add3x2(mult(2*j)(i),mult(2*j+1)(i));
204 
205  end loop;
206  end loop;
207 
208 
209  for i in 0 to (thresholds_num-1) loop -- loop over each threshold
210 
211  totsum(i) := to_integer(unsigned(xsum(i)(0))) -- sum over 7 pairs of JEMs
212  + to_integer(unsigned(xsum(i)(1)))
213  + to_integer(unsigned(xsum(i)(2)))
214  + to_integer(unsigned(xsum(i)(3)))
215  + to_integer(unsigned(xsum(i)(4)))
216  + to_integer(unsigned(xsum(i)(5)))
217  + to_integer(unsigned(xsum(i)(6)));
218 
219  if (totsum(i) >= 7) then
220  sum_internal((3*i)+2 downto 3*i) <= "111";
221  else
222  sum_internal((3*i)+2 downto 3*i) <= std_logic_vector(to_unsigned(totsum(i), 3));
223  end if;
224 
225  end loop;
226 
227 
228  -- overflow
230 
231  end if;
232  end process;
233 
234 
235 -- Output
236 
237  dout_lcl_tmp(47 downto 0) <= sum_internal(47 downto 0); -- 15 3-bit sums
238 
239  dout_lcl <= (others=>'1') when (par_err_lcl_d0 = '1' and force = '1') or bitofw_del1 = '1' else dout_lcl_tmp;
240 
241 
242 -- overflow calc.
243 
244  gen_cpm_ntobs: for i_cpm in 0 to max_cps-1 generate
245 
246  ntobs_low(i_cpm) <= Rxpos_sort(conv_integer(datai(i_cpm)(7 downto 0)))(7 downto 5);
247  ntobs_high(i_cpm) <= Rxpos_sort(conv_integer(datai(i_cpm)(15 downto 8)))(7 downto 5);
248 
249  ntobs_tot(i_cpm)<=std_logic_vector(resize(unsigned(ntobs_low(i_cpm)),4) + resize(unsigned(ntobs_high(i_cpm)),4));
250 
251  overflow(i_cpm) <= '1' when ntobs_tot(i_cpm) > 5 else '0';
252 
253  end generate;
254 
255 
256 -- overflow output
258 
259  bitofw <= ( (not disable_overflow_mask(1) ) and overflow(0) ) or
260  ( (not disable_overflow_mask(2) ) and overflow(1) ) or
261  ( (not disable_overflow_mask(3) ) and overflow(2) ) or
262  ( (not disable_overflow_mask(4) ) and overflow(3) ) or
263  ( (not disable_overflow_mask(5) ) and overflow(4) ) or
264  ( (not disable_overflow_mask(6) ) and overflow(5) ) or
265  ( (not disable_overflow_mask(7) ) and overflow(6) ) or
266  ( (not disable_overflow_mask(8) ) and overflow(7) ) or
267  ( (not disable_overflow_mask(9) ) and overflow(8) ) or
268  ( (not disable_overflow_mask(10) ) and overflow(9) ) or
269  ( (not disable_overflow_mask(11) ) and overflow(10) ) or
270  ( (not disable_overflow_mask(12) ) and overflow(11) ) or
271  ( (not disable_overflow_mask(13) ) and overflow(12) ) or
272  ( (not disable_overflow_mask(14) ) and overflow(13) ) ;
273 
274 
275 end struct;
T_SLV60 dout_lcl_tmp
Definition: main_crt_vs.vhd:75
loc_type (max_cps - 1 downto 0) loc
Rxpos_type (max_cps - 1 downto 0) roi_posRxB
out dout_lclT_SLV60
Definition: main_crt_vs.vhd:44
_library_ workwork
Definition: jet_decoder.vhd:19
in par_err_lclT_SL
Definition: main_crt_vs.vhd:46
threshold_type (max_cps - 1 downto 0) threshold_table
thPatL_type (max_cps - 1 downto 0) thrPat
out dout_lcl_roT_SL
Definition: main_crt_vs.vhd:45
arr_TOB (max_cps * max_tobs_pcp - 1 downto 0) TOBs)
Low_word (max_jems - 1 downto 0) :=( others =>( others =>( others =>'0' ) ) ) data_low
Definition: main_crt_vs.vhd:64
in dataiarr_4Xword (max_jems - 1 downto 0)
Definition: main_crt_vs.vhd:43
ntobsA_type (max_cps - 1 downto 0) ntobsA
ntobstot_type (max_cps - 1 downto 0) ntobs_tot
Rxpos_type (max_cps - 1 downto 0) roi_posRxA
Rxpos_type (max_cps - 1 downto 0) roi_posRx
mult_type (max_cps - 1 downto 0) mult
ntobsA_type (max_cps - 1 downto 0) ntobs_low
in clkstd_logic
Definition: main_crt_vs.vhd:41
in thresholdsarr_16 (max_jems * 25 * 4 - 1 downto 0)
Definition: main_crt_vs.vhd:42
High_word (max_jems - 1 downto 0) :=( others =>( others =>( others =>'0' ) ) ) data_high
Definition: main_crt_vs.vhd:63
_library_ IEEEIEEE
Definition: jet_decoder.vhd:14
ntobsA_type (max_cps - 1 downto 0) ntobs_high