CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
crate_summing_module.vhd
Go to the documentation of this file.
1 
5 
6 library IEEE;
7 use IEEE.STD_LOGIC_UNSIGNED.ALL;
8 use ieee.std_logic_1164.all;
9 use ieee.numeric_std.all;
11 use work.CMXpackage.all;
13 
15  port (
16  CLK : in std_logic;
17  BACKPLANE_DATA_IN : in energy_array;
18  LOCAL_CABLE_OUT : out std_logic_vector(26*4 -1 downto 0);
19  BCID_in : in std_logic_vector(11 downto 0);
20  BCID_delayed : out std_logic_vector(11 downto 0);
21  par_err_lcl : in T_SL; -- parity error local
22  force : in T_SL; -- force
23  --VME
24  ncs : in std_logic;
25  rd_nwr : in std_logic;
26  ds : in std_logic;
27  addr_vme : in std_logic_vector (15 downto 0);
28  data_vme_in : in std_logic_vector (15 downto 0);
29  data_vme_out : out std_logic_vector (15 downto 0);
30  bus_drive : out std_logic
31  --data org 3 - OV res tyx, 3 - OV tyx, 3*15 E res tyx, 3*15 E tyx,
32  );
33 end crate_summing_module;
34 
36  type sum_array is array (0 to 15) of unsigned(19 downto 0);
37  type sum_array_array is array (0 to 15) of sum_array;
38  signal data_in_l : sum_array_array := (others => (others => (others => '0')));
40  type total_sum_array is array (0 to 15) of unsigned(19 downto 0);
42  signal e_ov : std_logic_vector(5 downto 0) := (others => '0');
43  signal energy_out : std_logic_vector(95 downto 0);
44 
45  signal bus_drive_local : std_logic_vector(1 downto 0);
46  signal data_vme_out_local : arr_16(1 downto 0);
47 
48  signal data_from_vme_REG_RW_SUMET_MASK : std_logic_vector(15 downto 0);
49  signal data_to_vme_REG_RW_SUMET_MASK : std_logic_vector(15 downto 0);
50  signal data_from_vme_REG_RW_MISSET_MASK : std_logic_vector(15 downto 0);
51  signal data_to_vme_REG_RW_MISSET_MASK : std_logic_vector(15 downto 0);
52 
53  signal par_err_lcl_d0 : T_SL; -- parity error local
54 
55 begin
56 -- data_in_l --should be organized on the input of the component (tyyxxtyyxx)
57 -- 0 - sum ex u; 1 - sum ex l, 2 - sum ey u, 3 - sum ey l, 4 - sum et,
58 -- 5 - res sum ex u; 6 - res sum ex l, 7 - res sum ey u, 8 - res sum ey l, 9- res sum et,
59 -- quad_rest - selects if the given input is restricter or upper/lower quadrant
60 -- (see cmx_sumet_pkg.vhd)
61 
62 
63  vme_local_switch_inst: entity work.vme_local_switch
64  port map (
65  data_vme_up => data_vme_out,
67  bus_drive_up => bus_drive,
69 
70  vme_inreg_notri_async_REG_RW_SUMET_MASK : entity work.vme_inreg_notri_async
71  generic map (
72  ia_vme => ADDR_REG_RW_SUMET_MASK,
73  width => 16)
74  port map (
75  ncs => ncs,
76  rd_nwr => rd_nwr,
77  ds => ds,
78  addr_vme => addr_vme,
79  data_vme_in => data_vme_in,
84 
86 
87  vme_inreg_notri_async_REG_RW_MISSET_MASK : entity work.vme_inreg_notri_async
88  generic map (
89  ia_vme => ADDR_REG_RW_MISSET_MASK ,
90  width => 16)
91  port map (
92  ncs => ncs,
93  rd_nwr => rd_nwr,
94  ds => ds,
95  addr_vme => addr_vme,
96  data_vme_in => data_vme_in,
101 
103 
104  RESHUFLLE_DATA: for i in 0 to 15 generate --i iterates over module
105  data_in_l(i)(0)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(13 downto 0)); --x
106  data_in_l(i)(1)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(13 downto 0)); --x
107  data_in_l(i)(2)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(27 downto 14)); --y
108  data_in_l(i)(3)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(27 downto 14)); --y
109  data_in_l(i)(4)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(41 downto 28)); --t
110  data_in_l(i)(5)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(13 downto 0)); --x
111  data_in_l(i)(6)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(13 downto 0)); --x
112  data_in_l(i)(7)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(27 downto 14)); --y
113  data_in_l(i)(8)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(27 downto 14)); --y
114  data_in_l(i)(9)(13 downto 0) <= unsigned(BACKPLANE_DATA_IN(i)(41 downto 28)); --t
115  end generate RESHUFLLE_DATA;
116 
117  GENERATE_ALL_SUMS : for j in 0 to 9 generate --j iterates over energy type as
118  --above
119  GENERATE_E_ADDERS : for i in 0 to 7 generate --i iterates over modules
121  begin
122 
123  sum_e(j)(i) <= quad_rest(data_in_l(i*2+1)(j), BACKPLANE_MAP(i*2+1),
126  j)
127  + quad_rest(data_in_l(i*2)(j) , BACKPLANE_MAP(i*2),
130  j);
131  end process CALC_SUM_E_0;
132 
133  ADDER_STAGE_1: if i < 4 generate
134  CALC_SUM_E_1 : process (sum_e)
135  begin
136  sum_e(j)(i+8) <= sum_e(j)(i*2+1)+sum_e(j)(i*2);
137  end process CALC_SUM_E_1;
138  end generate ADDER_STAGE_1;
139 
140  ADDER_STAGE_2: if i < 2 generate
141  CALC_SUM_E_2 : process (sum_e)
142  begin
143  sum_e(j)(i+12) <= sum_e(j)(i*2+1+8)+sum_e(j)(i*2+8);
144  end process CALC_SUM_E_2;
145  end generate ADDER_STAGE_2;
146 
147  ADDER_STAGE_3: if i < 1 generate
148  CALC_SUM_E_3 : process (sum_e)
149  begin
150  sum_e(j)(14) <= sum_e(j)(12) + sum_e(j)(13);
151  end process CALC_SUM_E_3;
152  end generate ADDER_STAGE_3;
153 
154  end generate GENERATE_E_ADDERS;
155  end generate GENERATE_ALL_SUMS;
156 
157  -- 0 -> Ex; 1 -> Ey; 2 -> ET; 3,4,5 as above but restricted
159  begin
160  if rising_edge(CLK) then
161  total_sums(0) <= sum_e(0)(14) + not(sum_e(1)(14)) + 1;
162  total_sums(1) <= sum_e(2)(14) + not(sum_e(3)(14)) + 1;
163  total_sums(2) <= sum_e(4)(14);
164  total_sums(3) <= sum_e(5)(14) + not(sum_e(6)(14)) + 1;
165  total_sums(4) <= sum_e(7)(14) + not(sum_e(8)(14)) + 1;
166  total_sums(5) <= sum_e(9)(14);
168 
169  -- parity error delay
171 
172  end if;
173  end process CALC_CRATE_EX_EY_ET;
174 
175  GENERATE_OV : for i in 0 to 5 generate
176  generate_ov_signed: if i /=2 and i/=5 generate
177  CHECK_E_OV_EXEY : process (total_sums)
178  begin
179  -- if rising_edge(CLK) then
180  if (total_sums(i)(18 downto 14) /= 0 and total_sums(i)(19) = '0') or (par_err_lcl_d0 = '1' and force = '1') then
181  e_ov(i) <= '1';
182 
183  elsif (total_sums(i)(18 downto 14) /= "11111" and total_sums(i)(19) = '1') or (par_err_lcl_d0 = '1' and force = '1') then
184  e_ov(i) <= '1';
185 
186  else
187  e_ov(i) <= '0';
188 
189  end if;
190  energy_out(15*(i+1)-1 downto i*15) <= std_logic_vector(total_sums(i)(14 downto 0));
191 
192 --end if;
193  end process CHECK_E_OV_EXEY;
194  end generate generate_ov_signed;
195  generate_ov_sumET: if i=2 or i=5 generate
196  CHECK_E_OV_TE : process (total_sums)
197  begin
198  -- if rising_edge(CLK) then
199  if total_sums(i)(18 downto 14) /= 0 or (par_err_lcl_d0 = '1' and force = '1') then
200  e_ov(i) <= '1';
201 
202  else
203  e_ov(i) <= '0';
204 
205  end if;
206  --fifteen bits are assigned but the msb will be truncated anyway by the
207  --crate_cable_out function below
208  energy_out(15*(i+1)-1 downto i*15) <= std_logic_vector(total_sums(i)(14 downto 0));
209 
210 --end if;
211  end process CHECK_E_OV_TE;
212  end generate generate_ov_sumET;
213 
214  end generate GENERATE_OV;
215 
216 
217  energy_out(energy_out'high downto energy_out'high-5) <= e_ov;
218 
219  LOCAL_CABLE_OUT <= crate_cable_out(energy_out);
220 
221 
222 end crate_summing_module;
in BACKPLANE_DATA_INenergy_array
std_logic_vector (15 downto 0) data_from_vme_REG_RW_SUMET_MASK
in addr_vmestd_logic_vector (15 downto 0)
std_logic_vector (15 downto 0) data_from_vme_REG_RW_MISSET_MASK
array (0 to 15 ) of unsigned (19 downto 0) total_sum_array
out data_from_vmestd_logic_vector (width - 1 downto 0)
array (0 to 15 ) of sum_array sum_array_array
in data_vme_from_belowarr_16
--! inputs from local registers and from
std_logic_vector (1 downto 0) bus_drive_local
in data_vme_instd_logic_vector (15 downto 0)
out BCID_delayedstd_logic_vector (11 downto 0)
std_logic_vector (5 downto 0) :=( others =>'0' ) e_ov
std_logic_vector (15 downto 0) data_to_vme_REG_RW_MISSET_MASK
std_logic_vector (15 downto 0) data_to_vme_REG_RW_SUMET_MASK
std_logic_vector (95 downto 0) energy_out
in data_to_vmestd_logic_vector (width - 1 downto 0)
out data_vme_upstd_logic_vector (15 downto 0)
--! connect this to
array (0 to 15 ) of unsigned (19 downto 0) sum_array
sum_array_array :=( others =>( others =>( others =>'0' ) ) ) data_in_l
out bus_drive_upstd_logic
or of all bus drive requests from below
out data_vme_outstd_logic_vector (15 downto 0)
test registers
in BCID_instd_logic_vector (11 downto 0)
in bus_drive_from_belowstd_logic_vector