2 use ieee.std_logic_1164.
all;
3 use ieee.numeric_std.
all;
4 use ieee.std_logic_unsigned.
all;
5 use ieee.std_logic_misc.
all;
28 CUR_WIN_LATENCY_g : := 5;
-- time between raw TB and TB latch logic 29 CHECK_AND_READ_TIME_g : := 6;
30 TB_LATCH_DELAY_g : := 4 -- time for tb's to mature 37 tb : in (4 downto 0);
-- trigger bits from ASIC 39 ctime : in (26 downto 0);
-- current ctime 40 cur_win : in (8 downto 0);
41 -- ro_busy : in std_logic; 43 localtrg :
in ; -- trigger
is readout from trgfifo
44 ctime_trg : in (26 downto 0);
-- ctime of the trigger 46 -- hit_ren : in std_logic; -- read hit data from fifo 47 sca_rst : in ;
-- reset tb scalers 48 sca_cnt_max : in (7 downto 0);
-- period to measure scalers 51 asic_on : in ;
-- enable processing data for this specific asic 52 lookback : in (15 downto 0);
-- position in time of the lookback window 53 lookback_width : in (15 downto 0);
-- width of the lookback window 54 ctime_max : in (26 downto 0);
-- dynamicaly determined maximum ctime value 57 hit_bits : out (4 downto 0);
58 hit_win : out (8 downto 0);
59 is_hit : out := '0';
-- there is a hit with valid timestamp 60 -- tbfifo_drdy : out std_logic; -- data is ready 61 self_trig : out := '0';
63 sca_busy : out := '0';
-- scalers counting is in progress 64 -- scalers_arr : out slv32(15 downto 0); -- array(0 to 15) of slv32 65 scalers_cnt : out (31 downto 0) := (others => '0');
-- array(0 to 15) of slv32 66 -- fifo_cnt : out std_logic_vector(15 downto 0); -- current fifo write address 67 fifo_full_cnt : out (15 downto 0) := (others => '0') -- fifo overflow counter 74 constant ctime_zero : (26 downto 0) := (others => '0');
75 constant sca_max : (31 downto 0) := (others => '1');
77 -- ! Signals driven by synchronous processes: 79 signal i_ctime : (26 downto 0) := (others => '0');
80 signal i_ctime_trg : (26 downto 0) := (others => '0');
81 signal i_ctime_max : (26 downto 0) := (others => '1');
-- dynamicaly determined maxinum ctime value 82 signal i_localtrg : := '0';
83 signal i_localtrg_r : := '0';
84 signal i_lookback : (15 downto 0) := (others => '0');
85 signal i_lookback_width : (15 downto 0) := (others => '0');
86 signal i_lookback_max : (16 downto 0) := (others => '0');
87 signal i_sca_clk_cnt_max : (7 downto 0) := (others => '0');
88 signal i_sca_rst : := '0';
-- reset scalers 91 signal i_busy : (CHECK_AND_READ_TIME_g - 1 downto 0);
98 signal i_fifo_full_cnt : (15 downto 0) := (others => '0');
101 signal i_tb : (4 downto 0) := (others => '0');
102 signal tb_r : (4 downto 0) := (others=>'0');
103 signal tb_or_r : (TB_LATCH_DELAY_g downto 0) := (others=>'0');
104 signal tb_r_ready : := '0';
107 signal i_cur_win : slv9(TB_LATCH_DELAY_g + CUR_WIN_LATENCY_g downto 0) := (others=>(others => '0'));
110 signal i_tbfifo_din : (40 downto 0) := (others => '0');
-- waddr(9)&trgbits(5)&ctime(27) 111 signal i_tbfifo_wren : := '0';
-- read enable for trigger bits FIFO 114 signal clk_cnt : (23 downto 0):= (others => '1');
115 signal sca_cnt_ena : := '0';
123 signal i_tbfifo_rdstale : := '0';
137 -- signal rd_busy : std_logic; -- data is being read out from TB fifo 138 signal i_tbfifo_rden : := '0';
-- write enable for trigger bits FIFO 139 signal i_hits_rd_cnt : (15 downto 0) := (others => '0');
-- not implemented. TODO 147 signal tb_or_edge : := '0';
148 signal i_tbfifo_rden_res : := '0';
154 signal i_tbfifo_full : := '0';
155 signal i_tbfifo_empty : := '0';
161 --------------------- ASYNCHRONOUS LOGIC --------------------------------------------- 164 -- tb_or_edge <= (not tb_or_2r) and tb_or_r; 165 tb_or_edge <= (not tb_or_r(TB_LATCH_DELAY_g)) 166 and tb_or_r(TB_LATCH_DELAY_g - 1);
167 fifo_full_cnt <= i_fifo_full_cnt;
168 sca_busy <= sca_cnt_ena;
169 i_tbfifo_rden_res <= i_tbfifo_rdstale or i_tbfifo_rden;
174 --------------------- SYNCHRONOUS LOGIC --------------------------------------------- 175 latch_inputs:
process(clk)
177 if rising_edge(clk) then 178 i_ctime_trg <= ctime_trg;
179 i_localtrg <= localtrg;
180 i_localtrg_r <= i_localtrg;
-- delay localtrg for one clock cycle 182 i_ctime_max <= ctime_max;
183 -- latch configuration parameters 184 i_lookback_width <= lookback_width;
185 i_lookback <= lookback;
186 i_lookback_max <= ('0' & i_lookback) + ('0' & i_lookback_width);
187 i_sca_clk_cnt_max <= sca_cnt_max;
188 i_sca_rst <= rst or sca_rst;
192 i_busy_proc:
process(clk, localtrg)
194 if rising_edge(clk) then 195 if localtrg = '1' then 203 ppln_fifo_empty:
process(clk)
205 if rising_edge(clk) then 211 ------------------------------------------------ 213 ------------------------------------------------ 214 count_fifo_fulls:
process(clk, rst)
217 i_fifo_full_cnt <= (others => '0');
218 elsif rising_edge(clk) then 221 i_fifo_full_cnt <= i_fifo_full_cnt + 1;
225 ------------------------------------------------ 228 ------------------------------------------------ 229 -- edge detect for trig bits 230 ------------------------------------------------ 231 TB_EDGE_PROC :
process(clk, asic_on,
i_tb,
tb_or, tb_or_edge)
233 if rising_edge(clk) then 234 if asic_on = '1' then 237 i_tb <= (others => '0');
240 tb_or_r <= tb_or_r(tb_or_r'left - 1 downto 0) & tb_or;
241 tb_r_ready <= tb_or_edge;
243 end process TB_EDGE_PROC;
244 ------------------------------------------------ 247 SYNC_WIN_WITH_TBs:
process(clk, cur_win)
249 if rising_edge(clk) then 255 ------------------------------------------------ 256 -- TB timestamping with ctime 257 ------------------------------------------------ 258 FILL_PROC :
process(clk, tb_r,
i_ctime,
i_cur_win(i_cur_win'left), tb_r_ready)
260 if rising_edge(clk) then 262 if tb_r_ready = '1' then 263 i_tbfifo_wren <= '1';
268 i_tbfifo_wren <= '0';
271 end process FILL_PROC;
272 ------------------------------------------------ 275 ------------------------------------------------ 276 -- Trigger bits scalers 277 ------------------------------------------------ 278 SCA_CNT_PERIOD :
process(clk)
280 if rising_edge(clk) then 281 if i_sca_rst = '1' then 285 if clk_cnt(23 downto 16) < i_sca_clk_cnt_max then --count scalers for 65,536*(2^sca_cnt_max) clock cycles 297 SCALERS_PROC :
process(clk, i_sca_rst, sca_cnt_ena)
--, tb_chan_2r) 299 if rising_edge(clk) then 300 if i_sca_rst = '1' then 301 -- i_scalers_arr <= (others => (others => '0')); 304 if sca_cnt_ena = '1' and tb_r_ready = '1' and tb_r(4) = '0' then -- 5th bit is omitted here 308 -- if i_scalers_arr(tb_chan_2r) <= sca_max then 309 -- i_scalers_arr(tb_chan_2r) <= i_scalers_arr(tb_chan_2r) + 1; 314 end process SCALERS_PROC;
317 ppln_scalers_out:
process(clk)
319 if rising_edge(clk) then 320 -- scalers_arr <= i_scalers_arr; 324 ------------------------------------------------ 327 ------------------------------------------------ 328 -- track number of hits in the FIFO 329 ------------------------------------------------ 333 -- i_fifo_cnt <= (others => '0'); 334 -- elsif rising_edge(clk) then 335 -- if i_tbfifo_wren = '1' and i_tbfifo_rden_res = '0' then 336 -- i_fifo_cnt <= i_fifo_cnt + 1; 337 -- elsif i_tbfifo_wren = '0' and i_tbfifo_rden_res = '1' then 338 -- i_fifo_cnt <= i_fifo_cnt - 1; 342 -- fifo_cnt <= i_fifo_cnt; 343 ------------------------------------------------ 346 ------------------------------------------------ 347 -- flush stale data from the fifo 348 ------------------------------------------------ 349 flush_stale_tbs:
process(clk)
350 variable count : range 0 to 3 := 0;
352 if rising_edge(clk) then 353 case chk_stale_state is 359 i_tbfifo_rdstale <= not (i_busy(i_busy'left) or localtrg);
360 chk_stale_state <= LET_FIFO_SETTLE;
364 when LET_FIFO_SETTLE => 365 i_tbfifo_rdstale <= '0';
367 chk_stale_state <= IDLE;
370 chk_stale_state <= LET_FIFO_SETTLE;
378 -- calculate difference between current time and tb timestamp 379 calc_ctime_diff_drain:
process(clk)
381 if rising_edge(clk) then 391 ------------------------------------------------ 392 -- calculate difference between trg time and tb timestamp 393 ------------------------------------------------ 394 calc_ctime_diff_trig:
process(clk)
396 if rising_edge(clk) then 404 ------------------------------------------------ 407 ------------------------------------------------ 408 -- check if hit timestamp is within a lookback window 409 ------------------------------------------------ 410 eval_ctime_diff_trig:
process(clk)
412 if rising_edge(clk) then 413 if ctime_diff <= ("0000000000" & i_lookback_max) and ctime_diff >= ("00000000000" & i_lookback) then 420 ------------------------------------------------ 423 ------------------------------------------------ 424 -- read data fifo when triggered 425 ------------------------------------------------ 426 proc_trig_FSM:
process(clk, rst)
430 -- tbfifo_drdy <= '0'; 431 i_tbfifo_rden <= '0';
432 i_hits_rd_cnt <= (others => '0');
433 -- i_trgbit_data <= (others => '0'); 434 elsif rising_edge(clk) then 438 -- tbfifo_drdy <= '0'; 440 i_tbfifo_rden <= '0';
441 if i_localtrg_r = '1' then 452 -- tbfifo_drdy <= '0'; 454 -- tbfifo_drdy <= '1'; 457 i_tbfifo_rden <= '1';
458 i_hits_rd_cnt <= i_hits_rd_cnt + 1;
460 hit_bits <= (others=>'0');
461 hit_win <= (others=>'0');
462 i_tbfifo_rden <= '0';
475 mark_valid_hits:
process(clk)
477 if rising_edge (clk) then 479 if i_tbfifo_empty = '0' and i_tbfifo_full = '0' then 490 --------------------- MODULE INSTANTIATIONS --------------------------------------------- 492 ------------------------------------------------ 493 --- FIFO for trigger bits 494 ------------------------------------------------ 495 tb_fifo_i :
entity work.
fifo_cc 504 wen => i_tbfifo_wren,
505 ren => i_tbfifo_rden_res,
507 full => i_tbfifo_full,
508 empty => i_tbfifo_empty
std_logic_vector( 23 downto 0) :=( others => '1') clk_cnt
SCA_CNT_PERIOD :
std_logic_vector( 26 downto 0) :=( others => '0') i_ctime
latch_inputs:
std_logic_vector( 40 downto 0) :=( others => '0') i_tbfifo_dout
std_logic := '0' i_tbfifo_full_r
count_fifo_fulls:
std_logic_vector( 26 downto 0) :=( others => '0') ctime_diff
calc_ctime_diff_trig:
std_logic := '0' i_tbfifo_empty_r
ppln_fifo_empty:
std_logic := '0' i_is_hit
mark_valid_hits:
std_logic := '0' tb_or
Asynchronously driven signals.
std_logic_vector( 31 downto 0) :=( others => '0') i_scalers_cnt
SCALERS_PROC :
std_logic := '0' hit_not_too_old
eval_ctime_diff_trig:
slv9( TB_LATCH_DELAY_g+ CUR_WIN_LATENCY_g downto 0) :=( others =>( others => '0')) i_cur_win
SYNC_WIN_WITH_TBs:
(IDLE,CHECK,READ) proc_states
proc_trig_FSM:
std_logic_vector( 4 downto 0) :=( others => '0') i_tb
TB_EDGE_PROC :
std_logic_vector( 26 downto 0) :=( others => '0') ctime_diff_drain
calc_ctime_diff_drain:
std_logic_vector( CHECK_AND_READ_TIME_g- 1 downto 0) i_busy
i_busy_proc:
std_logic_vector( 40 downto 0) :=( others => '0') i_tbfifo_din
FILL_PROC :
(IDLE,LET_FIFO_SETTLE) stale_hit_flushing_FSM
flush_stale_tbs: