CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
CMX_flavor_package.vhd
Go to the documentation of this file.
1 
5 
6 library IEEE;
7 use IEEE.STD_LOGIC_1164.ALL;
8 use IEEE.NUMERIC_STD.ALL;
9 
10 library work;
11 
12 use work.CMXpackage.all;
13 use work.CMX_local_package.all;
14 
15 package CMX_flavor_package is
16 
17  constant version_flavor_common : std_logic_vector(15 downto 0):=x"F0A5";
18  CONSTANT max_jems : integer := 16;
19 
20  constant num_thresholds : integer := 8;
21 
22  constant max_bits_ExEy : integer :=15;
23  constant max_bits_TE : integer :=15;
24 
25  constant max_bits_XE2 : integer := max_bits_ExEy*2 +1;
26 
27  subtype T_SL is std_logic;
28  subtype T_SLV2 is std_logic_vector(1 downto 0);
29  subtype T_SLV3 is std_logic_vector(2 downto 0);
30  subtype T_SLV4 is std_logic_vector(3 downto 0);
31  subtype T_SLV12 is std_logic_vector(11 downto 0);
32  subtype T_SLV13 is std_logic_vector(12 downto 0);
33  subtype T_SLV24 is std_logic_vector(23 downto 0);
34  subtype T_SLV25 is std_logic_vector(24 downto 0);
35  subtype T_SLV30 is std_logic_vector(29 downto 0);
36  subtype T_SLV32 is std_logic_vector(31 downto 0);
37  subtype T_SLV16 is std_logic_vector(15 downto 0);
38  subtype T_SLV60 is std_logic_vector(59 downto 0);
39  subtype T_SLV61 is std_logic_vector(60 downto 0);
40  subtype T_SLV62 is std_logic_vector(61 downto 0);
41  subtype T_SLV65 is std_logic_vector(64 downto 0);
42  subtype T_SLV75 is std_logic_vector(74 downto 0);
43  subtype T_SLV120 is std_logic_vector(119 downto 0);
44  subtype T_SLV121 is std_logic_vector(120 downto 0);
45  subtype T_SLV1936 is std_logic_vector(1935 downto 0);
46 
47 
48  subtype sum_array is arr_ctr_15bit(9 downto 0);
49 
50  type energy_array is array (0 to 15) of std_logic_vector(41 downto 0);
51  type thr_array is array (0 to 15) of std_logic_vector(31 downto 0);
52  type xs_thr_param_array is array (0 to 7) of std_logic_vector(31 downto 0);
53 
54  type calc_parity_typa_a is array(integer range <>) of std_logic;
55  type calc_parity_type is array(integer range <>) of calc_parity_typa_a(3 downto 0);
56 
57  type cnt_mult_arr is array(integer range <>) of std_logic_vector(31 downto 0);
58  type cnt_mult_arr_2x16 is array(integer range <>) of std_logic_vector(15 downto 0);
59 
60  --This defines if the JEM at a given position is in the upper or lower half
61  --bit set to true means that JEM is in the upper half
62  constant BACKPLANE_MAP : std_logic_vector(15 downto 0):= x"00FF";
63 
64  function quad_rest(arg : unsigned; quadrant : std_logic; restricted_SUMET : std_logic; restricted_MISSET : std_logic; iterator : integer) return unsigned;
65  function xor_reduce (arg : std_logic_vector ) return std_logic;
66  function raw_encoder(arg : std_logic_vector) return std_logic_vector;
67  function crate_cable_in(arg : std_logic_vector) return std_logic_vector;
68  function crate_cable_out(arg : std_logic_vector) return std_logic_vector;
69  --function sqrt32( d : unsigned ) return unsigned;
70  --function sqrt( d : unsigned ) return unsigned;
71  --function divide(a : unsigned; b : unsigned) return unsigned;
72 
73 end CMX_flavor_package;
74 
75 
76 package body CMX_flavor_package is
77 
78 
79  function quad_rest(arg : unsigned; quadrant : std_logic; restricted_SUMET : std_logic; restricted_MISSET : std_logic; iterator : integer) return unsigned is
80  variable tmp : unsigned(arg'range);
81  variable result : unsigned(19 downto 0);
82  begin
83  if (quadrant = '1') and (iterator = 0 or iterator = 2 or iterator = 4) then
84  --upper no res --ex u ey u et
85  tmp := arg;
86  elsif (quadrant = '0') and (iterator = 1 or iterator = 3 or iterator = 4) then
87  --lower no res --ex l ex l
88  tmp := arg;
89  elsif ((quadrant = '1') and (iterator = 5 or iterator = 7)) and restricted_MISSET = '1' then
90  --upper res
91  tmp := arg;
92  elsif ((quadrant = '0') and (iterator = 6 or iterator = 8)) and restricted_MISSET = '1' then
93  --lower res
94  tmp := arg;
95  elsif ((iterator = 9) and restricted_SUMET = '1') then
96  tmp := arg;
97  else
98  tmp := (others => '0');
99  end if;
100  result := tmp;
101  return result;
102  end;
103 
104  function xor_reduce (arg : std_logic_vector ) return std_logic is
105  variable Upper, Lower : std_logic;
106  variable Half : integer;
107  variable BUS_int : std_logic_vector ( arg'length - 1 downto 0 );
108  variable Result : std_logic;
109  begin
110  if (arg'LENGTH < 1) then -- In the case of a NULL range
111  Result := '0';
112  else
113  BUS_int := to_ux01 (arg);
114  if ( BUS_int'length = 1 ) then
115  Result := BUS_int ( BUS_int'left );
116  elsif ( BUS_int'length = 2 ) then
117  Result := BUS_int ( BUS_int'right ) xor BUS_int ( BUS_int'left);
118  else
119  Half := ( BUS_int'length + 1 ) / 2 + BUS_int'right;
120  Upper := xor_reduce ( BUS_int ( BUS_int'left downto Half ));
121  Lower := xor_reduce ( BUS_int ( Half - 1 downto BUS_int'right));
122  Result := Upper xor Lower;
123  end if;
124  end if;
125  return Result;
126  end;
127 
128  function raw_encoder(arg : std_logic_vector) return std_logic_vector is
129  variable result : std_logic_vector(127 downto 0) := (others => '0');
130  begin
131  result(13 downto 0) := arg(13 downto 0);
132  result(22 downto 14) := (others => '0');
133  result(23) := arg(42);
134  result(37 downto 24) := arg(27 downto 14);
135  result(46 downto 38) := (others => '0');
136  result(47) := arg(43);
137  result(61 downto 48) := arg(41 downto 28);
138  result(70 downto 62) := (others => '0');
139  result(71) := arg(44);
140  result(94 downto 72) := (others => '0');
141  result(95) := arg(45);
142  result(96) := xor_reduce(arg);
143  result(127 downto 97) := (others => '0');
144  return result;
145  end;
146 
147  function crate_cable_out(arg : std_logic_vector) return std_logic_vector is
148  variable result : std_logic_vector(26*4-1 downto 0) := (others => '0');
149  variable c0m0_parity, c0m1_parity : std_logic_vector(25 downto 0) := (others => '0');
150  variable c1m0_parity, c1m1_parity : std_logic_vector(25 downto 0) := (others => '0');
151  begin
152  -- c0m0_parity := arg(arg'HIGH-5) & arg(2*15+9 downto 2*15) & arg(14 downto 0);
153  c0m0_parity := '0' & arg(2*15+9 downto 2*15) & arg(14 downto 0);
154  result(25 downto 0) := c0m0_parity;
155 
156  -- c0m1_parity := arg(arg'HIGH-3) & arg(5*15+9 downto 5*15) & arg(3*15+14 downto 3*15);
157  c0m1_parity := '0' & arg(5*15+9 downto 5*15) & arg(3*15+14 downto 3*15);
158  result(51 downto 26) :=c0m1_parity;
159 
160  -- c1m0_parity := arg(arg'HIGH-4) & x"0" & "00" & arg(2*15+13 downto 2*15+10) & arg(1*15+14 downto 15);
161  c1m0_parity := '0' & "00" & arg(arg'HIGH-1)& arg(arg'HIGH-2) & arg(arg'HIGH-4) & arg(arg'HIGH-5) & arg(2*15+13 downto 2*15+10) & arg(1*15+14 downto 15);
162  result(77 downto 52) := c1m0_parity;
163 
164  -- c1m1_parity := x"0" & "000" & arg(5*15+13 downto 5*15+10) & arg(4*15+14 downto 4*15);
165  c1m1_parity := '0' & x"0" & arg(arg'HIGH) & arg(arg'HIGH-3) & arg(5*15+13 downto 5*15+10) & arg(4*15+14 downto 4*15);
166  result(103 downto 78) := c1m1_parity;
167  return result;
168  end;
169 
170  function crate_cable_in(arg : std_logic_vector) return std_logic_vector is
171  variable result : std_logic_vector(6*15+6-1 downto 0) := (others => '0');
172  begin
173  --ex
174  result(1*15-1 downto 0*15) := arg(14 downto 0);
175  --ey
176  result(2*15-1 downto 1*15) := arg(2*26+14 downto 2*26);
177  --et
178  result(3*15-1 downto 2*15) := '0' & arg(2*26+18 downto 2*26+15) & arg(24 downto 15);
179 
180  result(4*15-1 downto 3*15) := arg(26+14 downto 26);
181  result(5*15-1 downto 4*15) := arg(3*26+14 downto 3*26);
182  result(6*15-1 downto 5*15) := '0' & arg(3*26+18 downto 3*26+15) & arg(26+24 downto 26+15);
183  -- result(6*15+2 downto 6*15) := arg(26+25) & arg(25) & arg(2*26+25) ;
184  result(6*15+5 downto 6*15) := arg(98) & arg(74) &arg(73) & arg(97) & arg(72) & arg(71) ;
185  return result;
186  end;
187 
188 --function sqrt ( arg : unsigned ) return unsigned is
189 -- variable tmp : unsigned(15 downto 0):= '0' & arg;
190 -- variable result : unsigned(7 downto 0):=(others => '0');
191 -- variable left, right, r : unsigned(9 downto 0):=(others => '0'); --input to adder/sub.r-remainder.
192 -- variable i : integer:=0;
193 --begin
194 -- for i in 0 to 7 loop
195 -- right(0) := '1';
196 -- right(1) := r(9);
197 -- right(9 downto 2) := result;
198 -- left(1 downto 0) := tmp (15 downto 14);
199 -- left(9 downto 2) := r (7 downto 0);
200 -- tmp(15 downto 2) := tmp(13 downto 0); --shifting by 2 bit.
201 -- if ( r(9) = '1') then
202 -- r := left + right;
203 -- else
204 -- r := left - right;
205 -- end if;
206 -- result(7 downto 1) := result(6 downto 0);
207 -- result(0) := not r(9);
208 -- end loop;
209 -- return result;
210 --end sqrt;
211 --
212 --function sqrt32 ( d : UNSIGNED ) return UNSIGNED is
213 -- variable a : unsigned(31 downto 0):=d; --original input.
214 -- variable q : unsigned(15 downto 0):=(others => '0'); --result.
215 -- variable left,right,r : unsigned(17 downto 0):=(others => '0'); --input to adder/sub.r-remainder.
216 -- variable i : integer:=0;
217 --begin
218 -- for i in 0 to 15 loop
219 -- right(0):='1';
220 -- right(1):=r(17);
221 -- right(17 downto 2):=q;
222 -- left(1 downto 0):=a(31 downto 30);
223 -- left(17 downto 2):=r(15 downto 0);
224 -- a(31 downto 2):=a(29 downto 0); --shifting by 2 bit.
225 -- if ( r(17) = '1') then
226 -- r := left + right;
227 -- else
228 -- r := left - right;
229 -- end if;
230 -- q(15 downto 1) := q(14 downto 0);
231 -- q(0) := not r(17);
232 -- end loop;
233 -- return q;
234 --
235 --end sqrt32;
236 --
237 --function divide (a : UNSIGNED; b : UNSIGNED) return UNSIGNED is
238 -- variable a1 : unsigned(a'length-1 downto 0):=a;
239 -- variable b1 : unsigned(b'length-1 downto 0):=b;
240 -- variable p1 : unsigned(b'length downto 0):= (others => '0');
241 -- variable i : integer:=0;
242 --begin
243 -- for i in 0 to b'length-1 loop
244 -- p1(b'length-1 downto 1) := p1(b'length-2 downto 0);
245 -- p1(0) := a1(a'length-1);
246 -- a1(a'length-1 downto 1) := a1(a'length-2 downto 0);
247 -- p1 := p1-b1;
248 -- if(p1(b'length-1) ='1') then
249 -- a1(0) :='0';
250 -- p1 := p1+b1;
251 -- else
252 -- a1(0) :='1';
253 -- end if;
254 -- end loop;
255 -- return a1;
256 --
257 --end divide;
258 --
259 --
260 
261 end CMX_flavor_package;
262 
263 
264 
265 
std_logic_vector (3 downto 0) T_SLV4
std_logic_vector (12 downto 0) T_SLV13
std_logic_vector (59 downto 0) T_SLV60
std_logic_vector crate_cable_outarg,
std_logic_vector (15 downto 0) T_SLV16
array ( integer range<> ) of std_logic calc_parity_typa_a
std_logic_vector (15 downto 0) :=x"F0A5" version_flavor_common
std_logic_vector crate_cable_inarg,
array (0 to 7 ) of std_logic_vector (31 downto 0) xs_thr_param_array
array (0 to 15 ) of std_logic_vector (41 downto 0) energy_array
std_logic_vector (2 downto 0) T_SLV3
std_logic_vector (60 downto 0) T_SLV61
std_logic_vector (31 downto 0) T_SLV32
std_logic_vector (120 downto 0) T_SLV121
std_logic_vector (11 downto 0) T_SLV12
std_logic_vector crate_cable_outarg,
array ( integer range<> ) of std_logic_vector (31 downto 0) cnt_mult_arr
std_logic_vector (23 downto 0) T_SLV24
std_logic_vector (24 downto 0) T_SLV25
std_logic_vector (119 downto 0) T_SLV120
unsigned quad_restarg,quadrant,restricted_SUMET,restricted_MISSET,iterator,
arr_ctr_15bit (9 downto 0) sum_array
std_logic_vector (64 downto 0) T_SLV65
std_logic_vector (61 downto 0) T_SLV62
std_logic_vector raw_encoderarg,
std_logic_vector crate_cable_inarg,
std_logic_vector raw_encoderarg,
std_logic_vector (15 downto 0) :=x"00FF" BACKPLANE_MAP
array (0 to 15 ) of std_logic_vector (31 downto 0) thr_array
integer :=15 max_bits_ExEy
integer :=max_bits_ExEy * 2 + 1 max_bits_XE2
array ( integer range<> ) of calc_parity_typa_a (3 downto 0) calc_parity_type
std_logic_vector (74 downto 0) T_SLV75
std_logic xor_reducearg,
std_logic_vector (1 downto 0) T_SLV2
array ( integer range<> ) of std_logic_vector (15 downto 0) cnt_mult_arr_2x16
std_logic_vector (29 downto 0) T_SLV30
std_logic_vector (1935 downto 0) T_SLV1936