Belle II KLM Scint Firmware  1
klm_scint_pkg.vhd
1 library ieee;
2  use ieee.std_logic_1164.all;
3 library work;
4  use work.conc_intfc_pkg.all;
5  use work.klm_scrod_pkg.all;
6 
7 package klm_scint_pkg is
8 
9  constant TargetRegWidth : integer := 19;
10  constant ROI : integer := 128;
11 
12  subtype st_i5 is integer range 0 to 4;
13  type i5 is array (natural range <>) of st_i5;
14  subtype st_slv2 is std_logic_vector(1 downto 0);
15  type slv2 is array (natural range <>) of st_slv2;
16  subtype st_slv3 is std_logic_vector(2 downto 0);
17  type slv3 is array (natural range <>) of st_slv3;
18  subtype st_slv4 is std_logic_vector(3 downto 0);
19  type slv4 is array (natural range <>) of st_slv4;
20  subtype st_slv5 is std_logic_vector(4 downto 0);
21  type slv5 is array (natural range <>) of st_slv5;
22  subtype st_slv7 is std_logic_vector(6 downto 0);
23  type slv7 is array (natural range <>) of st_slv7;
24  subtype st_slv8 is std_logic_vector(7 downto 0);
25  type slv8 is array (natural range <>) of st_slv8;
26  subtype st_slv9 is std_logic_vector(8 downto 0);
27  type slv9 is array (natural range <>) of st_slv9;
28  subtype st_slv10 is std_logic_vector(9 downto 0);
29  type slv10 is array (natural range <>) of st_slv10;
30  subtype st_slv11 is std_logic_vector(10 downto 0);
31  type slv11 is array (natural range <>) of st_slv11;
32  subtype st_slv12 is std_logic_vector(11 downto 0);
33  type slv12 is array (natural range <>) of st_slv12;
34  subtype st_slv14 is std_logic_vector(13 downto 0);
35  type slv14 is array (natural range <>) of st_slv14;
36  subtype st_slv15 is std_logic_vector(14 downto 0);
37  type slv15 is array (natural range <>) of st_slv15;
38  subtype st_slv16 is std_logic_vector(15 downto 0);
39  type slv16 is array (natural range <>) of st_slv16;
40  subtype st_slv22 is std_logic_vector(21 downto 0);
41  type slv22 is array (natural range <>) of st_slv22;
42  subtype st_slv24 is std_logic_vector(23 downto 0);
43  type slv24 is array (natural range <>) of st_slv24;
44  subtype st_slv32 is std_logic_vector(31 downto 0);
45  type slv32 is array (natural range <>) of st_slv32;
46  subtype st_slv41 is std_logic_vector(40 downto 0);
47  type slv41 is array (natural range <>) of st_slv41;
48 
49  type waveform_stat_t is record
50  ped_meas_busy : std_logic;
51  -- sps_dbg : std_logic_vector(1 downto 0);
52  fe_dbg_a : std_logic_vector(1 downto 0);
53  fe_dbg_b : std_logic_vector(1 downto 0);
54  wave_proc_busy : std_logic;
55  end record;
56  constant wave_stat_0 : waveform_stat_t := (
57  ped_meas_busy => '0',
58  -- sps_dbg => "00",
59  fe_dbg_a => "00",
60  fe_dbg_b => "00",
61  wave_proc_busy => '0'
62  );
63  type wave_stat_vec is array (natural range <>) of waveform_stat_t;
64 
65  -- type scalers_type is array(0 to 9) of std_logic_vector(15 downto 0);
66  -- type scalers32_type is array(0 to 9) of std_logic_vector(31 downto 0);
67  -- type scalers32_asic_type is array (0 to 15) of std_logic_vector(31 downto 0);
68  type scalers32_all_type is array(0 to 9) of slv32(15 downto 0);
69  -- type scalers16_asic_type is array (0 to 15) of std_logic_vector(15 downto 0);
70 
71  -- type trgbit_data_type is array(0 to 9) of std_logic_vector(9+5+27-1 downto 0); -- win, trig bits, ctime
72 
73  type ReadOutModesType is (ROMODE_DUMMY, ROMODE_SIMPLE, ROMODE_TEST, ROMODE_SCALERS, ROMODE_FULL);
74 
75  type KlmScrodHitDataType is record
76  first_hit : std_logic;
77  last_hit : std_logic;
78  null_hit : std_logic;
79 
80  word1 : std_logic_vector(15 downto 0);
81  word2 : std_logic_vector(15 downto 0);
82  word3 : std_logic_vector(15 downto 0);
83  word4 : std_logic_vector(15 downto 0);
84 
85  end record;
86 
87  constant KlmScrodHitDataNull : KlmScrodHitDataType := (
88  first_hit => '0',
89  last_hit => '0',
90  null_hit => '0',
91 
92  word1 => (others=>'0'),
93  word2 => (others=>'0'),
94  word3 => (others=>'0'),
95  word4 => (others=>'0')
96  );
97 
98  -- STATUS TYPE
99  type KlmScrodStatusType is record
100  Version : std_logic_vector(15 downto 0);
101  -- AliveCnt : std_logic_vector(15 downto 0);
102  TxRegBusy : std_logic;
103  -- TxRegError : std_logic;
104 
105  -- BClkCnt : std_logic_vector(15 downto 0);
106  -- FakeStat : std_logic_vector(15 downto 0);
107 
108  -- TxScalersArr : slv32(15 downto 0);
109  TbScalersChnArr: slv32(9 downto 0);
110 
111  TrgCnt : std_logic_vector(15 downto 0);
112  FullProcCnt : std_logic_vector(15 downto 0);
113  SimpProcCnt : std_logic_vector(15 downto 0);
114  NullProcCnt : std_logic_vector(15 downto 0);
115 
116  -- HitsOverflowCnt : std_logic_vector(15 downto 0);
117 
118  -- debug1 : std_logic_vector(15 downto 0);
119  -- debug2 : std_logic_vector(15 downto 0);
120  -- debug3 : std_logic_vector(15 downto 0);
121  -- CTimeMax : std_logic_vector(26 downto 0);
122 
123  TbScalersBusy : std_logic;
124  -- TbFifoCnt : slv16(9 downto 0);
125  TbFifoFullCnt : slv16(9 downto 0);
126  QtFifoFullCnt : std_logic_vector(15 downto 0);
127  -- TrgFifoFullCnt : std_logic_vector(15 downto 0);
128  -- RclWordsCnt : std_logic_vector(15 downto 0);
129 
130  MppcDacBusy : std_logic;
131  -- MppcAdcBusy : std_logic;
132 
133  -- MppcAdcData : std_logic_vector(11 downto 0);
134 
135  B2ttUp : std_logic;
136  B2ClkUp : std_logic;
137  B2ttStaIddr : std_logic_vector(1 downto 0);
138  B2ttCntIdelay : std_logic_vector(6 downto 0);
139  StartUtime : std_logic_vector(31 downto 0);
140  B2ttUpUTime : std_logic_vector(31 downto 0);
141  CurUTime : std_logic_vector(31 downto 0);
142  Shout : std_logic_vector(9 downto 0);
143  -- runrstdbg : std_logic_vector(3 downto 0);
144  -- feerstdbg : std_logic_vector(3 downto 0);
145  -- b2lrstdbg : std_logic_vector(3 downto 0);
146  -- gtprstdbg : std_logic_vector(3 downto 0);
147  WaveStat : waveform_stat_t;
148  debug_wave_we : std_logic_vector(1 downto 0);
149  debug_wave_din : slv12(1 downto 0);
150  SPS_hist_rd_data : slv16(1 downto 0);
151  sfp_stat : SFP_Status_t;
152  aurora_stat : Aurora_Status_t;
153  end record;
154  constant KlmScrodStatusType0 : KlmScrodStatusType := (
155  Version => (others=>'0'),
156  -- AliveCnt => (others=>'0'),
157  TxRegBusy => '0',
158  -- TxRegError => '0',
159  -- BClkCnt => (others=>'0'),
160  -- FakeStat => (others=>'0'),
161  -- TxScalersArr : slv32(15 downto 0),
162  TbScalersChnArr => (others=>(others=>'0')),
163  TrgCnt => (others=>'0'),
164  FullProcCnt => (others=>'0'),
165  SimpProcCnt => (others=>'0'),
166  NullProcCnt => (others=>'0'),
167  -- HitsOverflowCnt => (others=>'0'),
168  -- debug1 => (others=>'0'),
169  -- debug2 => (others=>'0'),
170  -- debug3 => (others=>'0'),
171  -- CTimeMax => (others=>'0'),
172  TbScalersBusy => '0',
173  -- TbFifoCnt => (others=>(others=>'0')),
174  TbFifoFullCnt => (others=>(others=>'0')),
175  QtFifoFullCnt => (others=>'0'),
176  -- TrgFifoFullCnt => (others=>'0'),
177  -- RclWordsCnt => (others=>'0'),
178  MppcDacBusy => '0',
179  -- MppcAdcBusy => '0',
180  -- MppcAdcData => (others=>'0'),
181  B2ttUp => '0',
182  B2ClkUp => '0',
183  B2ttStaIddr => (others=>'0'),
184  B2ttCntIdelay => (others=>'0'),
185  StartUtime => (others=>'0'),
186  B2ttUpUTime => (others=>'0'),
187  CurUTime => (others=>'0'),
188  Shout => (others=>'0'),
189  -- runrstdbg => (others=>'0'),
190  -- feerstdbg => (others=>'0'),
191  -- b2lrstdbg => (others=>'0'),
192  -- gtprstdbg => (others=>'0'),
193  WaveStat => wave_stat_0,
194  debug_wave_we => (others=>'0'),
195  debug_wave_din => (others=>(others=>'0')),
196  SPS_hist_rd_data => (others=>(others=>'0')),
197  sfp_stat => (others=>'0'),
198  aurora_stat => (others=>'0')
199  );
200 
201  type wave_config_t is record
202  measure_peds : std_logic;
203  -- use_self_trig : std_logic;
204  use_ftsw_trig : std_logic;
205  ped_sub_ena : std_logic;
206  ramp_length : std_logic_vector(11 downto 6);
207  use_force_trig : std_logic;
208  t_samp_addr_settle : std_logic_vector(3 downto 0);
209  t_setup_ss_any : std_logic_vector(3 downto 0);
210  t_strobe_settle : std_logic_vector(3 downto 0);
211  t_sr_clk_high : std_logic_vector(3 downto 0);
212  t_sr_clk_low : std_logic_vector(3 downto 0);
213  t_sr_clk_strobe : std_logic_vector(3 downto 0);
214  LE_time_thresh : std_logic_vector(11 downto 0);
215  force_trig_asic : i5(1 downto 0);
216  -- force_trig_win : std_logic_vector(8 downto 0);
217  force_trig_bits : std_logic_vector(4 downto 0);
218  -- SPS_count_max : std_logic_vector(4 downto 0);
219  SPS_hist_rd_addr : slv10(1 downto 0);
220  stream_peds : std_logic;
221  end record;
222 
223  constant default_wave_config : wave_config_t := (
224  measure_peds => '0',
225  -- use_self_trig => '1',
226  use_ftsw_trig => '0',
227  ped_sub_ena => '1',
228  ramp_length => "010111", -- 1472
229  use_force_trig => '0',
230  t_samp_addr_settle => "0000",-- 0
231  t_setup_ss_any => "0010",-- 2
232  t_strobe_settle => "0000",-- 0
233  t_sr_clk_high => "0011",-- 3
234  t_sr_clk_low => "0010",-- 2
235  t_sr_clk_strobe => "0001",-- 1
236  LE_time_thresh => "000000110010", -- 50
237  force_trig_asic => (others=> 0),
238  -- force_trig_win => (others=>'0'),
239  force_trig_bits => "00000",
240  -- SPS_count_max => "10000",
241  SPS_hist_rd_addr => (others=> (others=>'0')),
242  stream_peds => '0'
243  );
244 
245 
246  -- CONFIGURATION
247  type KlmScrodConfigType is record
248  -- BoardType : std_logic_vector(15 downto 0);
249  -- DummyHitsNumber : std_logic_vector(15 downto 0);
250 
251  TBLookBack : std_logic_vector(15 downto 0);
252  TBLookBackWidth : std_logic_vector(15 downto 0);
253 
254  -- TBHitsNumMax : std_logic_vector(15 downto 0);
255 
256  -- readout mode: 0 -- dummy data, 1 -- simple mode, 2 -- test mode
257  -- ReadoutMode : std_logic_vector(3 downto 0);
258 
259  -- TestModeCntMax : std_logic_vector(31 downto 0);
260 
261  -- period of TB scalers measurement
262  TBScalersPeriod : std_logic_vector(7 downto 0);
263 
264  -- number of ASIC to measure scalers
265  -- ScalersAsicN : std_logic_vector(3 downto 0);
266  -- ScalersChnN : std_logic_vector(3 downto 0);
267 
268 
269  -- TX registers configuration
270  TxLatchPeriod : std_logic_vector(3 downto 0);
271  TxLoadPeriod : std_logic_vector(3 downto 0);
272  TxProcMask : std_logic_vector(9 downto 0);
273 
274  TxRegData : std_logic_vector(TargetRegWidth-1 downto 0);
275  TxRegCtrlMask : std_logic_vector(9 downto 0);
276 
277  -- TxResetParam : std_logic_vector(15 downto 0); -- what is it? -- HDLCompiler:634 does not have driver
278  -- TxWindowNum : std_logic_vector(8 downto 0); -- xst653: is used but never assigned
279 
280 
281  MppcDacCtrl : std_logic_vector(15 downto 0); -- | Num(4) | Addr(4) | Val (8) |
282 
283  -- MppcADCData : std_logic_vector(11 downto 0);
284  -- MppcAdcAsicN : std_logic_vector(3 downto 0);
285  -- MppcAdcChanN : std_logic_vector(3 downto 0);
286 
287  -- ADCdebug : std_logic;
288 
289  AlwaysUpdStat : std_logic;
290  wave_config : wave_config_t;
291 
292  end record;--KlmScrodConfigType
293 
294  constant KlmScrodConfigZero : KlmScrodConfigType := (
295  -- BoardType => (others => '0'),
296  -- DummyHitsNumber => (others => '0'),
297 
298  -- TBLookBack => "0000001000101110",
299  TBLookBack => "0000000111110100",
300 
301  -- TBLookBack => "0000000000000000",
302 
303  TBLookBackWidth => "0000000001000000",
304 
305  -- TBHitsNumMax => (others => '0'),
306 
307  -- readout mode: 0 -- dummy data, 1 -- simple mode, 2 -- test mode
308  -- ReadoutMode => (others => '0'),
309 
310  -- TestModeCntMax => (others => '0'),
311 
312  -- period of TB scalers measurement
313  TBScalersPeriod => x"08",
314 
315  -- number of ASIC to measure scalers
316  -- ScalersAsicN => (others => '0'),
317  -- ScalersChnN => (others => '0'),
318 
319  -- TX registers configuration
320  TxLatchPeriod => x"4",
321  TxLoadPeriod => x"8",
322  TxProcMask => "1111111111",
323 
324  TxRegData => (others => '0'),
325  TxRegCtrlMask => (others => '0'),
326 
327  -- TxResetParam => (others => '0'),
328  -- TxWindowNum => (others => '0'),
329 
330 
331  MppcDacCtrl => (others => '0'),
332 
333  -- MppcADCData => (others => '0'),
334  -- MppcAdcAsicN => (others => '0'),
335  -- MppcAdcChanN => (others => '0'),
336  -- ADCdebug => '0',
337 
338  AlwaysUpdStat => '1',
339 
340  wave_config => default_wave_config
341  );
342 
343 
344  -- CONTROL
345  type KlmScrodControlType is record
346 
347  TBScalersReset : std_logic;
348  -- ADCReset : std_logic;
349  -- RunADC : std_logic;
350  KlmStatusUpdate : std_logic;
351  -- dgb_rd_ena
352  -- force trig
353  force_trig : std_logic;
354  sps_reset : std_logic;
355 
356  TxRegUpdate : std_logic; -- these two not tied to registers
357  MppcDacUpdate : std_logic; -- these two not tied to registers
358 
359  B2ttDbg : std_logic_vector(5 downto 0);
360 
361 
362  end record;
363 
364 
365  type trig_info_type_0 is record
366  bits : slv5(9 downto 0);
367  wr_time : slv9(9 downto 0);
368  ctime : std_logic_vector(15 downto 0);
369  mask : std_logic_vector(9 downto 0); -- valid flags
370  -- ready : std_logic_vector(9 downto 0);
371  end record;
372  constant null_trig_info_t0 : trig_info_type_0 := (
373  bits => (others => (others => '0')),
374  wr_time => (others => (others => '0')),
375  ctime => (others => '0'),
376  mask => (others => '0')
377  -- ready => (others => '0')
378  );
379 
380 
381  type trig_info_type_1 is record
382  bits : slv5(9 downto 0);
383  wr_time : slv9(9 downto 0); -- win[8:0] & samp[4:0]
384  ctime : std_logic_vector(15 downto 0);
385  mask : std_logic_vector(9 downto 0); -- valid flags
386  first_dig_win : std_logic_vector(8 downto 0);
387  last_dig_win : std_logic_vector(8 downto 0);
388  end record;
389  constant null_trig_info_t1 : trig_info_type_1 := (
390  bits => (others => (others => '0')),
391  wr_time => (others => (others => '0')),
392  ctime => (others => '0'),
393  mask => (others => '0'),
394  first_dig_win => (others => '0'),
395  last_dig_win => (others => '0')
396  );
397 
398  type trig_queue_type is array (natural range <>) of trig_info_type_1;
399 
400  type TARGETX_analong_wr_ena_mask_t is record
401  ena : std_logic;
402  mask_bit : std_logic;
403  win_start : std_logic_vector(8 downto 0);
404  n_win : std_logic_vector(3 downto 0);
405  end record;
406  constant null_TX_ana_wr_ena_mask : TARGETX_analong_wr_ena_mask_t := ('0','0',"000000000","0000");
407 
408 end package klm_scint_pkg;
409 
410 package body klm_scint_pkg is
411 
412 
413 end package body klm_scint_pkg;