Belle II KLM Scint Firmware  1
WaveformReadout.vhd
1 library IEEE;
2  use IEEE.STD_LOGIC_1164.ALL;
3  use IEEE.NUMERIC_STD.ALL;
4  use IEEE.STD_LOGIC_MISC.ALL;
5  use IEEE.STD_LOGIC_UNSIGNED.ALL;
6 library unisim;
7  use unisim.vcomponents.all;
8 library unimacro;
9  use unimacro.vcomponents.all;
10 Library work;
11  use work.klm_scint_pkg.all;
12  -- use work.conc_intfc_pkg.all;
13  -- use work.klm_scrod_pkg.all;
14  -- use work.tdc_pkg.all;
15 
65 
66 -- #### Deficiencies:
67 --1. For now, we shift out whole windows only, if we calculate a finer ROI,
68 --then we can perhaps shift out fewer samples to save time.
69 
70 entity WaveformReadout is
71  generic (
72  N_ASICS_g : integer := 10;
73  FORCE_TRIG_BUF_DEPTH_g : integer := 6;
74  TRG_BUFF_DEPTH_g : integer := 4;
75  TRIG_QUEUE_DEPTH_g : integer := 5;
76  TQ_PROG_FULL_THRESH_g : integer := 3;
77  CALC_ROI_LAG_g : integer := 2;
78  T_WAIT_2C_IF_QUEUE_FULL_g : integer := 31;
79  reset_buff_depth_g : integer := 10;
80  SLC_STAT_BUFF_DEPTH_g : integer := 4;
81  packet_type_g : std_logic_vector(7 downto 0):= X"80"; -- marks scintillators hits for DataConcentrator
82  N_readout_samples_g : std_logic_vector(7 downto 0) := "10000000"; -- 128
83  LAST_WINDOW_ADDRESS : std_logic_vector(8 downto 0) := "111111111";
84  N_BITS_AVG_g : integer := 7;
85  T_wait_busy_to_come_up_g : integer := 31;
86  FineLookback_win_g : std_logic_vector(8 downto 0) := "000000001";
87  max_proc_time_g : std_logic_vector(15 downto 0) := "0011000110011100" -- 100us
88  );
89  port (
90  -- main inputs
91  clk : in std_logic := '0';
92  busy : out std_logic := '0';
93  b2tt_runreset : in std_logic := '0';
94  trig : in trig_info_type_0 := null_trig_info_t0;
95 
96  -- signals with SamplingLgc
97  ana_wr_ena_mask : out TARGETX_analong_wr_ena_mask_t := null_TX_ana_wr_ena_mask;
98 
99  -- signals with HitDataSerializer
100  localtrg : in std_logic := '0';
101  force_trig : in std_logic := '0';
102  sps_reset : in std_logic := '0';
103  cur_win : in std_logic_vector(8 downto 0);
104 
105  -- nxt : in std_logic := '0';
106  -- tbfifo_rden : out std_logic_vector(9 downto 0) := (others=>'0');
108  qt_fifo_rd_en : in std_logic := '0';
109  qt_fifo_dout : out std_logic_vector (17 downto 0) := (others=>'0');
110  qt_fifo_empty : out std_logic := '1';
111  qt_fifo_err_cnt : out std_logic_vector(15 downto 0); -- counter for daq data fifo overflows
112  qt_fifo_evt_rdy : out std_logic := '0';
113  full_proc_cnt : out std_logic_vector(15 downto 0) := (others=>'0');
114  simp_proc_cnt : out std_logic_vector(15 downto 0) := (others=>'0');
115  null_proc_cnt : out std_logic_vector(15 downto 0) := (others=>'0');
116 
117  -- pedestal RAM access
118  RAM_IO : inout std_logic_vector(7 downto 0) := (others => '0');
119  RAM_WEb : out std_logic := '1';
120  RAM_OEb : out std_logic := '0';
121  RAM_ADDR : out std_logic_vector(21 downto 0) := (others => '1');
122 
123  -- BusA signals
124  BUSA_DO : in std_logic_vector(14 downto 0) := (others => '0');
125  BUSA_RAMP : out std_logic := '0';
126  BUSA_CLR : out std_logic := '0';
127  BUSA_RD_COLSEL : out std_logic_vector(5 downto 0) := (others => '0');
128  BUSA_RD_ENA : out std_logic := '0';
129  BUSA_RD_ROWSEL : out std_logic_vector(2 downto 0) := (others => '0');
130  BUSA_SAMPLESEL : out std_logic_vector(4 downto 0) := (others => '0');
131  BUSA_SR_CLEAR : out std_logic := '0';
132  BUSA_SR_SEL : out std_logic := '0';
133 
134  -- BusB signals
135  BUSB_DO : in std_logic_vector(14 downto 0) := (others => '0');
136  BUSB_RAMP : out std_logic := '0';
137  BUSB_CLR : out std_logic := '0';
138  BUSB_RD_COLSEL : out std_logic_vector(5 downto 0) := (others => '0');
139  BUSB_RD_ENA : out std_logic := '0';
140  BUSB_RD_ROWSEL : out std_logic_vector(2 downto 0) := (others => '0');
141  BUSB_SAMPLESEL : out std_logic_vector(4 downto 0) := (others => '0');
142  BUSB_SR_CLEAR : out std_logic := '0';
143  BUSB_SR_SEL : out std_logic := '0';
144 
145  -- TargetX DC signals
146  SAMPLESEL_ANY : out std_logic_vector(9 downto 0) := (others => '0');
147  SR_CLOCK : out std_logic_vector(9 downto 0) := (others => '0');
148 
149  -- SCROD config registers
150  wave_config : in wave_config_t := default_wave_config;
151 
152  -- status registers
153  wave_stat : out waveform_stat_t := wave_stat_0;
154  debug_wave_we : out std_logic_vector(1 downto 0) := (others=>'0');
155  debug_wave_din : out slv12(1 downto 0) := (others=> (others=>'0'));
156  SPS_hist_rd_data : out slv16(1 downto 0) := (others=> (others=>'0'))
157  );
158 end WaveformReadout;
159 
160 
161 architecture Behavioral of WaveformReadout is
162 
163  type trig_staging_FSM is (IDLE, WAIT_VALID, PROCESSING_REQ, WAIT_ACK);
164  type modify_sampling_mask_FSM is (IDLE, WAIT_DONE);
165  type ro_states is (IDLE, WAIT_RESET, CHECK_VALID, WAIT_WAVEFORM_READOUT, SEND_HITS, CHECK_DONE, STOP, SEND_SIMPLE);
166 
167 
168 --SYNCHRONOUS SIGNALS BY PROCESS WHICH DRIVES THEM
169 
171  signal wave_stat_i : wave_stat_vec(SLC_STAT_BUFF_DEPTH_g - 1 downto 0) := (others => wave_stat_0);
172 
174  signal wave_config_q1 : wave_config_t := default_wave_config;
175  signal wave_config_q2 : wave_config_t := default_wave_config;
176  signal wave_config_q3 : wave_config_t := default_wave_config;
177  signal wave_config_q4 : wave_config_t := default_wave_config;
178  signal wave_config_q5 : wave_config_t := default_wave_config;
179  signal wave_config_q6 : wave_config_t := default_wave_config;
180 
182  signal i_b2tt_runreset : std_logic_vector(reset_buff_depth_g - 1 downto 0);
183  signal busA_reset : std_logic := '0';
184  signal busB_reset : std_logic := '0';
185 
187  signal or_busy_sr : std_logic_vector(5 downto 0) := (others => '0');
188  signal either_bus_busy : std_logic := '0';
189 
191  signal i_localtrg : std_logic_vector(TRG_BUFF_DEPTH_g - 1 downto 0);
192 
194  signal force_trig_sr : std_logic_vector(FORCE_TRIG_BUF_DEPTH_g-1 downto 0) := (others => '0');
195  signal sps_reset_sr : std_logic_vector(FORCE_TRIG_BUF_DEPTH_g-1 downto 0) := (others => '0');
196 
198  signal meas_peds_ena : std_logic;
199  signal i_N_readout_samples : std_logic_vector(7 downto 0) := "00100000";
200  signal i_RAM_WEb : std_logic := '1';
201  signal i_RAM_din : std_logic_vector(7 downto 0) := (others => '0');
202  signal RAM_din : std_logic_vector(7 downto 0) := (others => '0');
203  signal RAM_rw : std_logic := '1';
204 
206  signal single_bus_ena : std_logic := '0';
207  signal SPS_measure_start : std_logic_vector(1 downto 0) := "00";
208 
210  signal i_trig_bits : slv5(9 downto 0) := (others=>(others=>'0'));
211  signal starting_win_samp : slv14(9 downto 0) := (others => (others=>'0'));
212  signal first_dig_win : std_logic_vector(8 downto 0) := (others=>'0');
213  signal last_dig_win : std_logic_vector(8 downto 0) := (others=>'0');
214  signal asic_mask : std_logic_vector(9 downto 0) := (others => '0');
215 
217  signal trig_staging : trig_staging_FSM := IDLE;
218  signal trig_in_t0 : trig_info_type_0 := null_trig_info_t0;
219  signal calc_roi_ena : std_logic := '0';
220  signal trg_proc_busy : std_logic := '0';
221  signal mask_windows : std_logic := '0';
222  signal trig_queue_wr_ena : std_logic := '0';
223 
225  signal wr_ptr : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
226  signal rd_ptr : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
227  signal wr_ptr_nxt : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
228  signal rd_ptr_nxt : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
229  signal queue_empty : std_logic := '1';
230  signal queue_above_thresh : std_logic := '0';
231  signal queue_full : std_logic := '0';
232  signal start_readout : std_logic := '0';
233  signal trig_queue : trig_queue_type(TRIG_QUEUE_DEPTH_g - 1 downto 0) := (others => null_trig_info_t1); -- triggers on deck
234  signal trig_q0 : trig_info_type_1 := null_trig_info_t1;
235 
237  signal modify_sampling_mask : modify_sampling_mask_FSM := IDLE;
238  signal mask_ack : std_logic := '0';
239  signal unmask_ack : std_logic := '0';
240  signal i_ana_wr_ena_mask : TARGETX_analong_wr_ena_mask_t := null_TX_ana_wr_ena_mask;
241 
243  signal ro_state : ro_states := IDLE;
244  signal hit_bldr_fsm_busy : std_logic := '0';
245  signal ro_reset : std_logic := '0';
246  signal daq_axis_i : std_logic := '0';
247  signal daq_chan_i : std_logic_vector(6 downto 0) := (others => '0');
248  signal daq_chan_base : std_logic_vector(6 downto 0) := (others => '0');
249  signal tb5 : std_logic := '0';
250  signal simp : std_logic := '0';
251  signal le_time_i : std_logic_vector(13 downto 0) := (others => '0');
252  signal peak_i : std_logic_vector(11 downto 0) := (others => '0');
253  signal daq_start_ro : std_logic := '0';
254  signal i_full_proc_cnt : std_logic_vector(15 downto 0) := (others => '0');
255  signal i_simp_proc_cnt : std_logic_vector(15 downto 0) := (others => '0');
256  signal i_null_proc_cnt : std_logic_vector(15 downto 0) := (others => '0');
257  signal daq_asic_mask : std_logic_vector(9 downto 0) := (others => '0');
258  signal simp_asic_mask : std_logic_vector(9 downto 0) := (others => '0');
259  signal unmask_windows : std_logic := '0';
260  signal rx_features_ack : std_logic_vector(1 downto 0) := (others => '0');
261  signal ser_run_i : std_logic := '0';
262  signal HitData_i : KlmScrodHitDataType := KlmScrodHitDataNull;
263 
265  signal ser_run : std_logic := '0';
266  signal HitData : KlmScrodHitDataType := KlmScrodHitDataNull;
267 
268 
269 
271  signal or_dig_busy : std_logic := '0';
272  signal single_bus_reset : std_logic := '0';
273  signal disambig_tb5 : std_logic := '1';
274  signal or_busy_status : std_logic := '0';
275 
276 -- SIGNALS DRIVEN BY INSTANTIATED ENTITIES
277 
279  signal trig_in_t1 : trig_info_type_1 := null_trig_info_t1; -- copy of input trig with ROI added
280 
282  signal i_ped_fetch_asic_no : slv3(1 downto 0);-- := (others => "000");
283  signal ped_fetch_chan : slv4(1 downto 0) := (others => "0000");
284  signal ped_win_samp_start : slv14(1 downto 0) := (others=>(others=>'0'));
285  signal ped_fetch_ena : std_logic_vector(1 downto 0) := (others => '0');
286  signal BUSA_WINSEL : std_logic_vector(8 downto 0) := (others => '0');
287  signal BUSB_WINSEL : std_logic_vector(8 downto 0) := (others => '0');
288  signal rx_features_ena : std_logic_vector(1 downto 0) := (others => '0');
289  signal last_hit : std_logic_vector(1 downto 0) := "00";
290  signal peak : slv12(1 downto 0) := (others => "000000000000");
291  signal le_time : slv14(1 downto 0) := (others => "00000000000000");
292  signal daq_chan : slv7(1 downto 0) := (others => "0000000");
293  signal DigStoreProcBusy : std_logic_vector(1 downto 0) := "00";
294  signal DigNShiftBusy : std_logic_vector(1 downto 0) := "00";
295  signal DigBusy : std_logic_vector(1 downto 0) := "00";
296  signal ShiftOutWinBusy : std_logic_vector(1 downto 0) := "00";
297  signal ShiftOutSampBusy : std_logic_vector(1 downto 0) := "00";
298  signal FeatExtBusy : std_logic_vector(1 downto 0) := "00";
299  signal PedFetchQueueBusy : std_logic_vector(1 downto 0) := "00";
300  signal avg_peds_busy : std_logic_vector(1 downto 0) := "00";
301  signal wr_peds2sram_ena : std_logic_vector(1 downto 0) := (others=>'0');
302  signal even_sample : slv12(1 downto 0) := (others => (others=>'0'));
303  signal odd_sample : slv12(1 downto 0) := (others => (others=>'0'));
304  signal sram_asic_addr : slv3(1 downto 0) := (others=>(others=>'0'));
305  signal sram_chan_addr : slv4(1 downto 0) := (others=>(others=>'0'));
306  signal sram_samp_addr : slv4(1 downto 0) := (others=>(others=>'0'));
307 
309  signal ped_fetch_ack : std_logic_vector(1 downto 0) := (others => '0');
310  signal ped_fifo_asic_sel : std_logic_vector(4 downto 0) := (others => '0');
311  signal ped_fifo_chan_sel : std_logic_vector(3 downto 0) := (others => '0');
312  signal ped_fifo_wr_ena : std_logic_vector(1 downto 0) := (others => '0');
313  signal ped_fifo_din : std_logic_vector(11 downto 0) := (others => '0');
314  signal RAM_rd_addr : std_logic_vector(21 downto 0) := (others => '0');
315 
317  signal RAM_wr_addr : std_logic_vector(21 downto 0) := (others => '0');
318  signal wr_peds2sram_ack : std_logic_vector(1 downto 0) := (others=>'0');
319 
321  signal ped_meas_win : std_logic_vector(8 downto 0) := (others=>'0');
322  signal ped_start_ro : std_logic := '0';
323  signal prime_fifos : std_logic := '0';
324  signal avg_peds_ena : std_logic := '0';
325  signal summing_ena : std_logic := '0';
326 
327  -- HitData_Serializer_i :
328  signal ser_busy : std_logic := '0';
329 
331  signal RAM_do : std_logic_vector(7 downto 0) := (others => '0');
332 
333 begin
334 
335 ------------------- ASYNCHRONOUS LOGIC ---------------------------------------------
336 
337  single_bus_reset <= ro_reset; -- or rst_from_sps_fsm;
338  BUSA_RD_ROWSEL <= BUSA_WINSEL(2 downto 0); -- Kurtis says bit pattern is more complicated...
339  BUSB_RD_ROWSEL <= BUSB_WINSEL(2 downto 0); -- ...may be shuffled in UCF or elsewhere in firmware
340  BUSA_RD_COLSEL <= BUSA_WINSEL(8 downto 3);
341  BUSB_RD_COLSEL <= BUSB_WINSEL(8 downto 3);
342  -- dbg_start_ro <= (force_trig_sr(force_trig_sr'left) and not (wave_config_q6.measure_peds or wave_config_q6.use_loop_trig));
343  -- asic_chan_win_sel <= wave_config_q6.measure_peds & wave_config_q6.use_ftsw_trig;
344  -- bus_mask <= daq_bus_mask or ped_bus_mask;
345  ana_wr_ena_mask <= i_ana_wr_ena_mask;
346  trig_in_t1.wr_time <= trig_in_t0.wr_time;
347  trig_in_t1.mask <= trig_in_t0.mask;
348  trig_in_t1.ctime <= trig_in_t0.ctime;
349  trig_in_t1.bits <= trig_in_t0.bits;
350  or_dig_busy <= DigBusy(0) or DigBusy(1);
351  or_busy_status <= or_reduce(DigStoreProcBusy)
352  or or_reduce(DigNShiftBusy)
353  or or_reduce(DigBusy)
354  or or_reduce(ShiftOutWinBusy)
355  or or_reduce(ShiftOutSampBusy)
356  or or_reduce(FeatExtBusy)
357  or or_reduce(PedFetchQueueBusy);
358  -- trg_proc_cnt <= i_trg_proc_cnt(31 downto 24) & i_trg_proc_cnt(7 downto 0);
359  full_proc_cnt <= i_full_proc_cnt;
360  simp_proc_cnt <= i_simp_proc_cnt;
361  null_proc_cnt <= i_null_proc_cnt;
362  -- or_calc_roi_busy <= or_reduce(calc_roi_busy);
363  disambig_tb5 <= wave_config_q6.use_ftsw_trig;
364 
365 --------------------- SYNCHRONOUS LOGIC ---------------------------------------------
366 
367  ppln_stat: process(clk, wave_stat_i)
368  begin
369  wave_stat <= wave_stat_i(wave_stat_i'left);
370  wave_stat_i(wave_stat_i'left downto 1) <= wave_stat_i(wave_stat_i'left - 1 downto 0);
371  end process;
372 
373  conf_dffs: process(clk, wave_config, wave_config_q1, wave_config_q2,
374  wave_config_q3, wave_config_q4, wave_config_q5)
375  begin
376  if rising_edge(clk) then
377  wave_config_q1 <= wave_config;
378  wave_config_q2 <= wave_config_q1;
379  wave_config_q3 <= wave_config_q2;
380  wave_config_q4 <= wave_config_q3;
381  wave_config_q5 <= wave_config_q4;
382  wave_config_q6 <= wave_config_q5;
383  end if;
384  end process conf_dffs;
385 
386  rst_buff: process(clk, b2tt_runreset, i_b2tt_runreset)
387  begin
388  if rising_edge(clk) then
389  i_b2tt_runreset(reset_buff_depth_g - 1 downto 1) <= i_b2tt_runreset(reset_buff_depth_g - 2 downto 0);
390  i_b2tt_runreset(0) <= b2tt_runreset;
391  busA_reset <= single_bus_reset;
392  busB_reset <= single_bus_reset;
393  end if;
394  end process rst_buff;
395 
396 
397  busy_lgc: process(clk, or_busy_status, queue_full)
398  begin
399  if rising_edge(clk) then
400  or_busy_sr <= or_busy_sr(or_busy_sr'left - 1 downto 0) & or_busy_status;
401  either_bus_busy <= or_busy_sr(or_busy_sr'left) or or_busy_sr(0);
402  wave_stat_i(0).wave_proc_busy <= hit_bldr_fsm_busy;
403  -- busy <= localtrg or calc_roi_busy(0) or calc_roi_busy(1) or queue_full;
404  busy <= trg_proc_busy or queue_full;
405  end if;
406  end process busy_lgc;
407 
408 
409  trg_buff: process(clk, localtrg)
410  begin
411  if rising_edge(clk) then
412  i_localtrg <= i_localtrg(i_localtrg'left - 1 downto 0) & localtrg;
413  end if;
414  end process;
415 
416 
417  force_trig_buffer: process(clk, force_trig)
418  begin
419  if rising_edge(clk) then
420  force_trig_sr <= force_trig_sr(force_trig_sr'left - 1 downto 0) & force_trig;
421  end if;
422  end process;
423 
424 
425  sps_reset_buffer: process(clk, sps_reset)
426  begin
427  if rising_edge(clk) then
428  sps_reset_sr <= sps_reset_sr(sps_reset_sr'left - 1 downto 0) & sps_reset;
429  end if;
430  end process;
431 
432 
433  ----------------------------------------------------------------------------
434  -- ADDRESS MULTIPLEXER AND PIPELINE FOR SRAM CONTROL --
435  ----------------------------------------------------------------------------
436  SRAM_mux: process (clk, wave_config_q6.measure_peds, force_trig_sr, i_RAM_din,
437  RAM_wr_addr, RAM_rd_addr, i_RAM_WEb)
438  begin
439  if rising_edge(clk) then
440  RAM_din <= i_RAM_din; -- DFF for matching phase with address
441  RAM_WEb <= i_RAM_WEb; -- DFF for matching phase with address
442  if wave_config_q6.measure_peds = '1' then
443  RAM_rw <= '0';
444  RAM_OEb <= '1';
445  RAM_ADDR <= RAM_wr_addr;
447  i_N_readout_samples <= "00100000";
448  else
449  RAM_rw <= '1';
450  RAM_OEb <= '0';
451  RAM_ADDR <= RAM_rd_addr;
452  meas_peds_ena <= '0';
453  i_N_readout_samples <= N_readout_samples_g;
454  end if;
455  end if;
456  end process SRAM_mux;
457 
458 
459  ena_logic: process(clk, ped_start_ro, daq_start_ro)
460  begin
461  if rising_edge(clk) then
462  single_bus_ena <= ped_start_ro or daq_start_ro;
463  end if;
464  end process ena_logic;
465 
466 
467  asic_chan_win_mux: process(clk, wave_config_q6.measure_peds, ped_meas_win, daq_asic_mask, trig_q0)
468  begin
469  if rising_edge(clk) then
470  if wave_config_q6.measure_peds = '1' then
471  i_trig_bits <= (others=>(others=>'1'));
472  asic_mask <= (others=>'1');
473  starting_win_samp <= (others=> ped_meas_win & "00000");
474  first_dig_win <= ped_meas_win;
475  last_dig_win <= ped_meas_win;
476  else
477  first_dig_win <= trig_q0.first_dig_win - FineLookback_win_g;
478  last_dig_win <= trig_q0.last_dig_win - FineLookback_win_g + (N_readout_samples_g(7 downto 5) - "001");
479  asic_mask <= daq_asic_mask;
480  for i in 0 to 9 loop
481  starting_win_samp(i) <= (trig_q0.wr_time(i) & "00000") - (FineLookback_win_g & "00000");
482  i_trig_bits(i) <= trig_q0.bits(i); -- used by SingleBusProcessing to make a channel mask
483  end loop;
484  end if;
485  end if;
486  end process asic_chan_win_mux;
487  ----------------------------------------------------------------------------
488 
489 
490 
491  ------------------------------------------------
492  --- Process Triggers: Calc ROI, fill queue, mask windows -- initiated by in port 'localtrg'
493  ------------------------------------------------
494  trg_proc: process(clk, i_localtrg(i_localtrg'left), queue_full, mask_ack, trig)
495  variable count : integer range 0 to (CALC_ROI_LAG_g + N_ASICS_g);
496  begin
497  if rising_edge(clk) then
498  case trig_staging is
499 
500  when IDLE =>
501  count := 0;
502  if i_localtrg(i_localtrg'left) = '1' and queue_full = '0' then
503  trg_proc_busy <= '1';
504  trig_staging <= WAIT_VALID;
505  else
506  trg_proc_busy <= '0';
507  trig_staging <= IDLE;
508  end if;
509 
510  when WAIT_VALID =>
511  -- tbfifo_rden <= "0000000000";
512  -- if trig.ready = "1111111111" then
513  trig_in_t0 <= trig; -- tb_fifo is 1st-wd fall-through, so trig ready before tbfifo_rden
514  -- tbfifo_rden <= trig.mask;
515  -- tbfifo_rden <= "1111111111"; -- mask taken care of in KLMTrigBitsProc
516  calc_roi_ena <= '1';
517  trig_staging <= PROCESSING_REQ;
518  -- else
519  -- trig_staging <= WAIT_VALID;
520  -- end if;
521 
522  when PROCESSING_REQ =>
523  -- tbfifo_rden <= "0000000000";
524  calc_roi_ena <= '0';
525  if count < (CALC_ROI_LAG_g + N_ASICS_g) then
526  count := count + 1;
527  -- if calc_roi_ena = '1' or calc_roi_busy(1) = '1' or calc_roi_busy(0) = '1' then -- wait for calcROI
528  trig_staging <= PROCESSING_REQ;
529  -- elsif or_calc_roi_busy = '1' then
530  -- trig_staging <= PROCESSING_REQ;
531  else
532  mask_windows <= '1'; -- stop TargetX sampling over ROI
533  trig_queue_wr_ena <= '1'; -- trig_in_t1 ready w/ROI info added. Add to queue.
534  trig_staging <= WAIT_ACK;
535  end if;
536 
537  when WAIT_ACK =>
538  trig_queue_wr_ena <= '0';
539  if mask_ack = '1' then -- wait for verification that masking was done
540  mask_windows <= '0';
541  trig_staging <= IDLE;
542  else
543  trig_staging <= WAIT_ACK;
544  end if;
545 
546  end case;
547  end if;
548  end process trg_proc;
549 
550 
551  ------------------------------------------------
552  --- Queue triggers and initiate readout
553  ------------------------------------------------
554  trg_queue: process(clk, i_b2tt_runreset, trig_queue_wr_ena, queue_full, queue_empty, hit_bldr_fsm_busy, trig_in_t1)
555  -- variable wr_ptr : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
556  -- variable rd_ptr : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
557  -- variable wr_ptr_nxt : integer range 0 to TRIG_QUEUE_DEPTH_g - 1 := 0;
558  variable above_thresh_but_not_full : std_logic := '0';
559  begin
560  if rising_edge(clk) then
561  queue_above_thresh <= above_thresh_but_not_full or queue_full;
562  if i_b2tt_runreset(i_b2tt_runreset'left) = '1' then
563  queue_empty <= '1';
564  queue_full <= '0';
565  start_readout <= '0';
566  rd_ptr <= wr_ptr;
567  else
568  if wr_ptr = (TRIG_QUEUE_DEPTH_g - 1) then
569  wr_ptr_nxt <= 0;
570  else
571  wr_ptr_nxt <= wr_ptr + 1;
572  end if;
573  if wr_ptr >= rd_ptr then
574  if (wr_ptr - rd_ptr) >= TQ_PROG_FULL_THRESH_g then
575  above_thresh_but_not_full := '1';
576  else
577  above_thresh_but_not_full := '0';
578  end if;
579  else
580  if (TRIG_QUEUE_DEPTH_g - (rd_ptr - wr_ptr)) >= TQ_PROG_FULL_THRESH_g then
581  above_thresh_but_not_full := '1';
582  else
583  above_thresh_but_not_full := '0';
584  end if;
585  end if;
586  if rd_ptr = (TRIG_QUEUE_DEPTH_g - 1) then
587  rd_ptr_nxt <= 0;
588  else
589  rd_ptr_nxt <= rd_ptr + 1;
590  end if;
591  if trig_queue_wr_ena = '1' and queue_full = '0'then
592  trig_queue(wr_ptr) <= trig_in_t1; -- Add trigger to queue
593  if wr_ptr = (TRIG_QUEUE_DEPTH_g - 1) then -- increment write pointer
594  wr_ptr <= 0;
595  else
596  wr_ptr <= wr_ptr + 1;
597  end if;
598  if wr_ptr_nxt = rd_ptr then
599  queue_full <= '1';
600  end if;
601  queue_empty <= '0';
602  elsif queue_empty = '0' and hit_bldr_fsm_busy = '0' and start_readout = '0' then
603  start_readout <= '1'; -- initiate readout
604  trig_q0 <= trig_queue(rd_ptr); -- trig_q0 is the one being processed
605  if rd_ptr = (TRIG_QUEUE_DEPTH_g - 1) then -- increment read pointer
606  rd_ptr <= 0;
607  else
608  rd_ptr <= rd_ptr + 1;
609  end if;
610  if rd_ptr_nxt = wr_ptr then
611  queue_empty <= '1';
612  end if;
613  queue_full <= '0';
614  else
615  start_readout <= '0';
616  end if;
617  end if;
618  end if;
619  end process trg_queue;
620 
621 
622  ------------------------------------------------
623  --- Mask / Unmask windows for waveform sampling
624  ------------------------------------------------
625  mask_unmask_proc: process(clk, mask_windows, unmask_windows,
626  trig_in_t1.first_dig_win, trig_q0.first_dig_win)
627  variable count : integer range 0 to 3;
628  begin
629  if rising_edge(clk) then
630  case modify_sampling_mask is
631 
632  when IDLE =>
633  count := 0;
634  i_ana_wr_ena_mask <= null_TX_ana_wr_ena_mask;
635  mask_ack <= '0';
636  unmask_ack <= '0';
637  if mask_windows = '1' then -- mask off windows when trigger goes into queue
638  mask_ack <= '1'; -- acknowledge signal to arbitrate collisions
639  i_ana_wr_ena_mask.ena <= '1';
640  i_ana_wr_ena_mask.mask_bit <= '0';
641  i_ana_wr_ena_mask.win_start <= trig_in_t1.first_dig_win;
642  i_ana_wr_ena_mask.n_win <= "0010" + i_N_readout_samples(7 downto 5); --FIXME: use last dig_win
643  modify_sampling_mask <= WAIT_DONE;
644  elsif unmask_windows = '1' then -- unmask windows when current trigger is done processing
645  unmask_ack <= '1';
646  i_ana_wr_ena_mask.ena <= '1';
647  i_ana_wr_ena_mask.mask_bit <= '1';
648  i_ana_wr_ena_mask.win_start <= trig_q0.first_dig_win;
649  i_ana_wr_ena_mask.n_win <= "0010" + i_N_readout_samples(7 downto 5); --FIXME: use last dig_win
650  modify_sampling_mask <= WAIT_DONE;
651  else
652  modify_sampling_mask <= IDLE;
653  end if;
654 
655  when WAIT_DONE =>
656  mask_ack <= '0';
657  unmask_ack <= '0';
658  -- if count = (N_readout_samples_g(7 downto 5) + "010") then
659  if count = 3 then
660  i_ana_wr_ena_mask <= null_TX_ana_wr_ena_mask;
661  modify_sampling_mask <= IDLE;
662  else
663  count := count + 1;
664  modify_sampling_mask <= WAIT_DONE;
665  end if;
666 
667  end case;
668  end if;
669  end process;
670 
671  -----------------------------------------------------------------------------
672  --- KLM Hit Builder -- initiated when HitQueue not empty and this FSM not busy
673  -----------------------------------------------------------------------------
674  hit_bldr: process(clk, i_b2tt_runreset, start_readout, trig_q0,
675  rx_features_ena, peak, le_time, daq_chan, i_full_proc_cnt, i_simp_proc_cnt, i_null_proc_cnt,
676  last_hit, unmask_ack, wave_config_q6.use_ftsw_trig,
677  queue_above_thresh)
678  variable count : integer range 0 to T_WAIT_2C_IF_QUEUE_FULL_g := 0;
679  variable i_last_hit : std_logic_vector(1 downto 0) := "00";
680  variable i_first_hit : std_logic := '1';
681  variable i_queue_getting_full : std_logic := '0';
682  begin
683  if rising_edge(clk) then
684  if i_b2tt_runreset(i_b2tt_runreset'left) = '1' then
685  ro_state <= IDLE;
686  ser_run_i <= '0';
687  qt_fifo_evt_rdy <= '0';
688  ro_reset <= '1';
689  i_full_proc_cnt <= (others=>'0');
690  i_simp_proc_cnt <= (others=>'0');
691  i_null_proc_cnt <= (others=>'0');
692  else
693 
694  case ro_state is
695 
696  WHEN IDLE =>
697  TB5 <= '0';
698  ro_reset <= '0';
699  ser_run_i <= '0';
700  qt_fifo_evt_rdy <= '0';
701  HitData_i.last_hit <= '0';
702  i_first_hit := '1';
703  -- HitData_i.null_hit <= '1';
704  daq_chan_base <= (others=>'0');
705  daq_chan_i <= (others=>'0');
706  le_time_i <= (others=>'0');
707  peak_i <= (others=>'0');
708  if start_readout = '1' then -- initiated by trig_queue whenever queue is nonempty and readout is not busy
709 
710  count := 0;
711  ro_reset <= '1';
712  hit_bldr_fsm_busy <= '1';
713  ro_state <= WAIT_RESET;
714  else
715  hit_bldr_fsm_busy <= '0';
716  ro_state <= IDLE;
717  end if;
718 
719  -- FIXME: CHECK IF STATE CAN BE REMOVED
720  When WAIT_RESET => -- soft reset to make sure staging fifos are empty before processing new trigger
721  if count < 3 then
722  ro_reset <= '1';
723  else
724  ro_reset <= '0';
725  end if;
726  if count < T_WAIT_2C_IF_QUEUE_FULL_g then
727  count := count + 1;
728  ro_state <= WAIT_RESET;
729  else
730  count := 0;
731  ro_state <= CHECK_VALID;
732  end if;
733 
734 
735  -- wait until event data is valid
736  WHEN CHECK_VALID =>
737  i_last_hit(0) := not or_reduce(trig_q0.mask(4 downto 0));
738  i_last_hit(1) := not or_reduce(trig_q0.mask(9 downto 5));
739  daq_asic_mask <= trig_q0.mask;
740  simp_asic_mask <= trig_q0.mask;
741  if or_reduce(trig_q0.mask) = '1' then
742  HitData_i.null_hit <= '0';
743  if queue_above_thresh = '0' then
744  i_queue_getting_full := '0';
745  daq_start_ro <= '1';
746  simp <= '0';
747  i_full_proc_cnt <= i_full_proc_cnt + '1';
748  ro_state <= WAIT_WAVEFORM_READOUT;
749  else
750  i_queue_getting_full := '1';
751  simp <= '1';
752  i_simp_proc_cnt <= i_simp_proc_cnt + '1';
753  ro_state <= SEND_SIMPLE;
754  end if;
755  else
756  HitData_i.null_hit <= '1';
757  i_null_proc_cnt <= i_null_proc_cnt + '1';
758  ro_state <= SEND_HITS;
759  end if;
760 
761 
762  WHEN WAIT_WAVEFORM_READOUT =>
763  daq_start_ro <= '0';
764  if rx_features_ena(0) = '1' then
765  rx_features_ack <= "01";
766  daq_axis_i <= '0';
767  -- HitData_i.null_hit <= null_hit(0);
768  peak_i <= peak(0);
769  le_time_i <= le_time(0);
770  daq_chan_i <= daq_chan(0);
771  i_last_hit(0) := last_hit(0); -- BusA last hit
772  -- HitData_i.last_hit <= last_hit(0) and i_last_hit(1);
773  ro_state <= SEND_HITS;
774  elsif rx_features_ena(1) = '1' then
775  rx_features_ack <= "10";
776  daq_axis_i <= '1';
777  -- HitData_i.null_hit <= null_hit(1);
778  peak_i <= peak(1);
779  le_time_i <= le_time(1);
780  daq_chan_i <= daq_chan(1);
781  i_last_hit(1) := last_hit(1); -- BusB last hit
782  -- HitData_i.last_hit <= last_hit(1) and i_last_hit(0);
783  ro_state <= SEND_HITS;
784  else
785  ro_state <= WAIT_WAVEFORM_READOUT;
786  end if;
787 
788 
789  WHEN SEND_HITS =>
790  if i_queue_getting_full = '1' then
791  i_last_hit(0) := not or_reduce(simp_asic_mask(4 downto 0));
792  i_last_hit(1) := not or_reduce(simp_asic_mask(9 downto 5));
793  end if;
794  rx_features_ack <= "00";
795  if ser_busy = '1' then
796  ro_state <= SEND_HITS;
797  else
798  HitData_i.first_hit <= i_first_hit;
799  HitData_i.last_hit <= i_last_hit(1) and i_last_hit(0);
800  ser_run_i <= wave_config_q6.use_ftsw_trig; -- initiate transaction
801  ro_state <= CHECK_DONE;
802  end if;
803 
804 
805  WHEN CHECK_DONE =>
806  ser_run_i <= '0';
807  i_first_hit := '0';
808  if i_last_hit(1) = '1' and i_last_hit(0) = '1' THEN
809  qt_fifo_evt_rdy <= wave_config_q6.use_ftsw_trig;
810  unmask_windows <= '1';
811  -- i_trg_proc_cnt <= i_trg_proc_cnt + '1';
812  ro_state <= STOP;
813  else
814  if i_queue_getting_full = '1' then
815  ro_state <= SEND_SIMPLE;
816  else
817  ro_state <= WAIT_WAVEFORM_READOUT;
818  end if;
819  end if;
820 
821 
822  WHEN STOP =>
823  ser_run_i <= '0';
824  if unmask_ack = '1' then -- VERY IMPORTANT: stay here until sampling mask is removed.
825  unmask_windows <= '0';
826  ro_state <= IDLE;
827  else
828  ro_state <= STOP;
829  end if;
830 
831  When SEND_SIMPLE =>
832  TB5 <= trig_q0.bits(count)(4);
833  daq_chan_i <= daq_chan_base + ("000" & trig_q0.bits(count)(3 downto 0) - '1');
834  if count < 5 then
835  daq_axis_i <= '0';
836  else
837  daq_axis_i <= '1';
838  end if;
839  if simp_asic_mask(count) = '1' or count = 9 then
840  simp_asic_mask(count) <= '0';
841  ro_state <= SEND_HITS;
842  else
843  ro_state <= SEND_SIMPLE;
844  end if;
845  if count = 4 then
846  daq_chan_base <= "0000000";
847  else
848  daq_chan_base <= daq_chan_base + "0001111";
849  end if;
850  count := count + 1;
851 
852  end case;
853  end if;
854  end if;
855 
856  end process hit_bldr;
857 
858 
859  ppln_hit_data: process(clk, daq_axis_i, daq_chan_i, trig_q0.ctime, simp, TB5,
860  le_time_i, peak_i, HitData_i, ser_run_i)
861  begin
862  if rising_edge(clk) then
863  HitData_i.word1 <= packet_type_g & daq_axis_i & daq_chan_i;
864  HitData_i.word2 <= trig_q0.ctime;
865  HitData_i.word3 <= simp & TB5 & le_time_i;
866  HitData_i.word4 <= "0000" & peak_i;
867  HitData <= HitData_i;
868  ser_run <= ser_run_i;
869  end if;
870  end process;
871 
872 
873 
874 
875 ---------------------BEGIN MODULES ---------------------------------------------
876  CALC_ROI: entity work.CalculateROI
877  generic map (
878  ARR_DEPTH_g => N_ASICS_g,
879  VEC_WIDTH_g => 9
880  )
881  port map (
882  clk => clk,
883  ena => calc_roi_ena,
884  -- busy => calc_roi_busy(i),
885  vec_arr => trig_in_t0.wr_time,
886  arr_mask => trig_in_t0.mask,
887  first_vec => trig_in_t1.first_dig_win,
888  last_vec => trig_in_t1.last_dig_win
889  );
890 
891 
892  busA : entity work.SingleBusProcessing
893  generic map (
894  N_BITS_AVG_g => N_BITS_AVG_g
895  )
896  port map (
897  -- main inputs
898  clk => clk,
899  rst => busA_reset,
900  ped_sub_ena => wave_config_q6.ped_sub_ena,
901  disambig_tb5 => disambig_tb5,
902  measure_peds => wave_config_q6.measure_peds,
903  stream_peds => wave_config_q6.stream_peds,
904  ena => single_bus_ena,
905  win_samp_start => starting_win_samp(4 downto 0),
906  trig_bits => i_trig_bits(4 downto 0),
907  asic_mask => asic_mask(4 downto 0),
908  first_dig_win => first_dig_win,
909  last_dig_win => last_dig_win,
910 
911  -- pedestal data
912  ped_fetch_asic_no => i_ped_fetch_asic_no(0),
913  ped_fetch_chan => ped_fetch_chan(0),
914  ped_win_samp_start => ped_win_samp_start(0),
915  ped_fetch_ena => ped_fetch_ena(0),
916  ped_fetch_ack => ped_fetch_ack(0),
917  ped_fifo_wr_asic => ped_fifo_asic_sel,
918  ped_fifo_wr_chan => ped_fifo_chan_sel,
919  ped_fifo_wr_ena => ped_fifo_wr_ena(0),
920  ped_fifo_din => ped_fifo_din,
921 
922  -- wires to/from TargetX
923  BUS_RD_ENA => BUSA_RD_ENA,
924  BUS_RAMP => BUSA_RAMP,
925  BUS_CLR => BUSA_CLR,
926  BUS_DO => BUSA_DO,
927  SR_CLR => BUSA_SR_CLEAR,
928  SR_CLK => SR_CLOCK(4 downto 0),
929  SR_SEL => BUSA_SR_SEL,
930  BUS_RD_WINSEL => BUSA_WINSEL,
931  SAMPLESEL => BUSA_SAMPLESEL,
932  SAMPLESEL_ANY => SAMPLESEL_ANY(4 downto 0),
933 
934  -- wires to HitDataSerializer
935  rx_features_ack => rx_features_ack(0),
936  rx_features_ena => rx_features_ena(0),
937  last_hit => last_hit(0),
938  -- null_hit => null_hit(0),
939  peak => peak(0),
940  le_time => le_time(0),
941  daq_chan => daq_chan(0),
942 
943  -- SCROD config registers
944  ramp_length => wave_config_q6.ramp_length,
945  -- force_test_pattern => wave_config_q6.force_test_pattern,
946  t_samp_addr_settle => wave_config_q6.t_samp_addr_settle,
947  t_setup_ss_any => wave_config_q6.t_setup_ss_any,
948  t_strobe_settle => wave_config_q6.t_strobe_settle,
949  t_sr_clk_high => wave_config_q6.t_sr_clk_high,
950  t_sr_clk_low => wave_config_q6.t_sr_clk_low,
951  t_sr_clk_strobe => wave_config_q6.t_sr_clk_strobe,
952  N_readout_samples => i_N_readout_samples,
953  LE_time_thresh => wave_config_q6.LE_time_thresh,
954 
955  -- status registers
956  debug_we => debug_wave_we(0),
957  debug_wave => debug_wave_din(0),
958  DigStoreProcBusy => DigStoreProcBusy(0),
959  DigNShiftBusy => DigNShiftBusy(0),
960  DigBusy => DigBusy(0),
961  ShiftOutWinBusy => ShiftOutWinBusy(0),
962  ShiftOutSampBusy => ShiftOutSampBusy(0),
963  FeatExtBusy => FeatExtBusy(0),
964  PedFetchQueueBusy => PedFetchQueueBusy(0),
965 
966  -- wires for ped calc
967  prime_fifos => prime_fifos,
968  summing_ena => summing_ena,
969  avg_peds_ena => avg_peds_ena,
970  avg_peds_busy => avg_peds_busy(0),
971  wr_peds2sram_ena => wr_peds2sram_ena(0),
972  wr_peds2sram_ack => wr_peds2sram_ack(0),
973  even_ped => even_sample(0),
974  odd_ped => odd_sample(0),
975  sram_asic_addr => sram_asic_addr(0),
976  sram_chan_addr => sram_chan_addr(0),
977  sram_samp_addr => sram_samp_addr(0),
978  fe_dbg => wave_stat_i(0).fe_dbg_a,
979  sps_reset => sps_reset_sr(sps_reset_sr'left),
980  SPS_hist_rd_addr => wave_config_q6.SPS_hist_rd_addr(0),
981  SPS_hist_rd_data => SPS_hist_rd_data(0)
982 );
983 
984 
985  busB : entity work.SingleBusProcessing
986  generic map (
987  N_BITS_AVG_g => N_BITS_AVG_g
988  )
989  port map (
990  -- main inputs
991  clk => clk,
992  rst => busB_reset,
993  ped_sub_ena => wave_config_q6.ped_sub_ena,
994  disambig_tb5 => disambig_tb5,
995  measure_peds => wave_config_q6.measure_peds,
996  stream_peds => wave_config_q6.stream_peds,
997  ena => single_bus_ena,
998  win_samp_start => starting_win_samp(9 downto 5),
999  trig_bits => i_trig_bits(9 downto 5),
1000  asic_mask => asic_mask(9 downto 5),
1001  first_dig_win => first_dig_win,
1002  last_dig_win => last_dig_win,
1003 
1004  -- pedestal data
1005  ped_fetch_asic_no => i_ped_fetch_asic_no(1),
1006  ped_fetch_chan => ped_fetch_chan(1),
1007  ped_win_samp_start => ped_win_samp_start(1),
1008  ped_fetch_ena => ped_fetch_ena(1),
1009  ped_fetch_ack => ped_fetch_ack(1),
1010  ped_fifo_wr_asic => ped_fifo_asic_sel,
1011  ped_fifo_wr_chan => ped_fifo_chan_sel,
1012  ped_fifo_wr_ena => ped_fifo_wr_ena(1),
1013  ped_fifo_din => ped_fifo_din,
1014 
1015  -- wires to/from TargetX
1016  BUS_RD_ENA => BUSB_RD_ENA,
1017  BUS_RAMP => BUSB_RAMP,
1018  BUS_CLR => BUSB_CLR,
1019  BUS_DO => BUSB_DO,
1020  SR_CLR => BUSB_SR_CLEAR,
1021  SR_CLK => SR_CLOCK(9 downto 5),
1022  SR_SEL => BUSB_SR_SEL,
1023  BUS_RD_WINSEL => BUSB_WINSEL,
1024  SAMPLESEL => BUSB_SAMPLESEL,
1025  SAMPLESEL_ANY => SAMPLESEL_ANY(9 downto 5),
1026 
1027  -- wires to HitDataSerializer
1028  rx_features_ack => rx_features_ack(1),
1029  rx_features_ena => rx_features_ena(1),
1030  last_hit => last_hit(1),
1031  -- null_hit => null_hit(1),
1032  peak => peak(1),
1033  le_time => le_time(1),
1034  daq_chan => daq_chan(1),
1035 
1036  -- SCROD config registers
1037  ramp_length => wave_config_q6.ramp_length,
1038  -- force_test_pattern => wave_config_q6.force_test_pattern,
1039  t_samp_addr_settle => wave_config_q6.t_samp_addr_settle,
1040  t_setup_ss_any => wave_config_q6.t_setup_ss_any,
1041  t_strobe_settle => wave_config_q6.t_strobe_settle,
1042  t_sr_clk_high => wave_config_q6.t_sr_clk_high,
1043  t_sr_clk_low => wave_config_q6.t_sr_clk_low,
1044  t_sr_clk_strobe => wave_config_q6.t_sr_clk_strobe,
1045  N_readout_samples => i_N_readout_samples,
1046  LE_time_thresh => wave_config_q6.LE_time_thresh,
1047 
1048  -- status registers
1049  debug_we => debug_wave_we(1),
1050  debug_wave => debug_wave_din(1),
1051  DigStoreProcBusy => DigStoreProcBusy(1),
1052  DigNShiftBusy => DigNShiftBusy(1),
1053  DigBusy => DigBusy(1),
1054  ShiftOutWinBusy => ShiftOutWinBusy(1),
1055  ShiftOutSampBusy => ShiftOutSampBusy(1),
1056  FeatExtBusy => FeatExtBusy(1),
1057  PedFetchQueueBusy => PedFetchQueueBusy(1),
1058 
1059  -- wires for ped calc
1060  prime_fifos => prime_fifos,
1061  summing_ena => summing_ena,
1062  avg_peds_ena => avg_peds_ena,
1063  avg_peds_busy => avg_peds_busy(1),
1064  wr_peds2sram_ena => wr_peds2sram_ena(1),
1065  wr_peds2sram_ack => wr_peds2sram_ack(1),
1066  even_ped => even_sample(1),
1067  odd_ped => odd_sample(1),
1068  sram_asic_addr => sram_asic_addr(1),
1069  sram_chan_addr => sram_chan_addr(1),
1070  sram_samp_addr => sram_samp_addr(1),
1071  fe_dbg => wave_stat_i(0).fe_dbg_b,
1072  sps_reset => sps_reset_sr(sps_reset_sr'left),
1073  SPS_hist_rd_addr => wave_config_q6.SPS_hist_rd_addr(1),
1074  SPS_hist_rd_data => SPS_hist_rd_data(1)
1075  );
1076 
1077 
1078  ped_fetcher : entity work.PedestalFetcher
1079  port map (
1080  clk => clk,
1081  rst => ro_reset,
1082  ena => ped_fetch_ena,
1083  ack => ped_fetch_ack,
1084  asic_addr => i_ped_fetch_asic_no,
1085  chan_addr => ped_fetch_chan,
1086  win_samp_start => ped_win_samp_start,
1087  fifo_asic_sel => ped_fifo_asic_sel, -- fanned out to busA/B, wr_ena controlled
1088  fifo_chan_sel => ped_fifo_chan_sel, -- fanned out to busA/B, wr_ena controlled
1089  ped_fifo_wr_ena => ped_fifo_wr_ena, -- slv[1:0]
1090  ped_fifo_din => ped_fifo_din,
1091  N_readout_samples => i_N_readout_samples,
1092  RAM_do => RAM_do,
1093  RAM_ADDR => RAM_rd_addr
1094  );
1095 
1096 
1097  ped_writer : entity work.PedestalWriter
1098  port map (
1099  clk => clk,
1100  ena => wr_peds2sram_ena,
1101  ack => wr_peds2sram_ack,
1102  chan_addr => sram_chan_addr,
1103  asic_addr => sram_asic_addr,
1104  samp_addr => sram_samp_addr,
1105  win_addr => ped_meas_win,
1106  even_sample => even_sample,
1107  odd_sample => odd_sample,
1108  RAM_din => i_RAM_din,
1109  RAM_WEb => i_RAM_WEb,
1110  RAM_ADDR => RAM_wr_addr
1111  );
1112 
1113 
1114  ped_measure : entity work.MeasurePeds
1115  generic map (
1116  LAST_WINDOW_ADDRESS => LAST_WINDOW_ADDRESS,
1117  N_BITS_AVG_g => N_BITS_AVG_g
1118  )
1119  port map (
1120  clk => clk,
1121  ena => meas_peds_ena,
1122  busy => wave_stat_i(0).ped_meas_busy,
1123  force_trig => ped_start_ro,
1124  trig_win => ped_meas_win,
1125  prime_fifos => prime_fifos,
1126  summing_ena => summing_ena,
1127  cur_win => cur_win,
1128  either_bus_busy => either_bus_busy,
1129  avg_peds_ena => avg_peds_ena,
1130  avg_peds_busy => avg_peds_busy,
1131  dig_busy => or_dig_busy--,
1132  -- bus_mask => ped_bus_mask
1133  );
1134 
1135 
1136  HitData_Serializer_i : entity work.KLMHitDataSerializer
1137  port map(
1138  clk => clk,
1139  rst => i_b2tt_runreset(i_b2tt_runreset'left),
1140  run => ser_run,
1141 
1142  -- daq data to be serialized
1143  first_hit => HitData.first_hit, -- hit is the first hit in the event
1144  last_hit => HitData.last_hit, -- hit is the last hit in the event
1145  null_hit => HitData.null_hit, -- hit is null
1146  word1 => HitData.word1, -- in
1147  word2 => HitData.word2, -- in
1148  word3 => HitData.word3, -- in
1149  word4 => HitData.word4, -- in
1150 
1151  -- nxt => nxt,
1152  fifo_empty => qt_fifo_empty,
1153  -- fifo_full => open,
1154  fifo_dout => qt_fifo_dout,
1155  fifo_ren => qt_fifo_rd_en,
1156  fifo_err_cnt => qt_fifo_err_cnt,
1157  busy => ser_busy
1158  );
1159 
1160 
1161  tristate : for i in 0 to 7 generate
1162  sda_buff: IOBUF
1163  -- generic map(IFD_DELAY_VALUE => "0", DRIVE => 12, SLEW => "SLOW") <-- Default values, uncomment and change if needed
1164  port map(o => RAM_do(i), io => RAM_IO(i), i => RAM_din(i), t => RAM_rw);
1165  end generate;
1166 
1167 
1168 end Behavioral;
std_logic_vector( reset_buff_depth_g- 1 downto 0) i_b2tt_runreset
rst_buff:
ro_states := IDLE ro_state
hit_bldr:
std_logic_vector( FORCE_TRIG_BUF_DEPTH_g- 1 downto 0) :=( others => '0') force_trig_sr
force_trig_buffer:
std_logic_vector( 7 downto 0) :=( others => '0') RAM_do
sda_buff:
trig_info_type_1 := null_trig_info_t1 trig_in_t1
CALC_ROI:
integer range 0 to TRIG_QUEUE_DEPTH_g- 1:= 0 wr_ptr
trg_queue:
trig_staging_FSM := IDLE trig_staging
trg_proc:
std_logic := '0' or_dig_busy
ASYNCHRONOUSLY DRIVEN SIGNALS.
wave_config_t := default_wave_config wave_config_q1
conf_dffs:
std_logic_vector( 8 downto 0) :=( others => '0') ped_meas_win
ped_measure:
std_logic := '0' single_bus_ena
ena_logic:
std_logic := '0' ser_run
ppln_hit_data:
modify_sampling_mask_FSM := IDLE modify_sampling_mask
mask_unmask_proc:
slv5( 9 downto 0) :=( others =>( others => '0')) i_trig_bits
asic_chan_win_mux:
wave_stat_vec( SLC_STAT_BUFF_DEPTH_g- 1 downto 0) :=( others => wave_stat_0) wave_stat_i
ppln_stat:
std_logic_vector( 1 downto 0) :=( others => '0') ped_fetch_ack
ped_fetcher:
std_logic_vector( TRG_BUFF_DEPTH_g- 1 downto 0) i_localtrg
trg_buff:
std_logic_vector( 21 downto 0) :=( others => '0') RAM_wr_addr
ped_writer:
in qt_fifo_rd_enstd_logic := '0'
daq data ports
std_logic meas_peds_ena
SRAM_mux:
trig_info_type_0 := null_trig_info_t0 trig_in_t0
copy of input trig without ROI
slv3( 1 downto 0) i_ped_fetch_asic_no
busA/busB:
std_logic_vector( 5 downto 0) :=( others => '0') or_busy_sr
busy_lgc: