eFEX firmware  1.7.3
ATLAS l1-calo - electron and tau feature extraction firmware for eFEX boards

Back to eFEX documentation
ttc_fifo_block.vhd
Go to the documentation of this file.
1 
8 
10 LIBRARY ieee;
11 USE ieee.std_logic_1164.all;
12 use ieee.numeric_std.all;
13 
15 ENTITY ttc_fifo_block IS
16  generic(
17  DELAY_DEPTH : Integer range 0 to 255 := 3 -- Number of SRLC32E to cascade for delayed L1A strobe over and above ftm_ttc_mode delay
18  );
19  PORT (
20 -- clocks etc
21  clk40 : in std_logic;
22  clk_320 : in std_logic;
23 -- TTC input FIFO
24  rst_ttc : in std_logic;
25  ttc_wr_en : in std_logic;
26  ttc_rd_en : in std_logic;
27  ttc_din : in std_logic_vector(49 DOWNTO 0);
28 -- TTC output FIFOs
29  ttc_rd_en_A : in std_logic;
30  ttc_empty_A : out std_logic;
31  ttc_dout_A : out std_logic_vector(49 DOWNTO 0);
32  ttc_rd_en_B : in std_logic;
33  ttc_empty_B : out std_logic;
34  ttc_dout_B : out std_logic_vector(49 DOWNTO 0);
35 -- input and output control
36  destination_enable : in std_logic_vector(1 downto 0) := (Others => '0');
37  readout_delay : in std_logic_vector(7 downto 0)
38  );
39 END ENTITY ttc_fifo_block;
40 
42 Architecture rtl of ttc_fifo_block is
43 
44 COMPONENT SRLC32E is
45  generic(
46  INIT : std_logic_vector(31 downto 0) := (Others => '0')
47  );
48  port(
49  CLK : in std_logic;
50  D : in std_logic;
51  CE : in std_logic;
52  A : in std_logic_vector(4 downto 0);
53  Q : out std_logic;
54  Q31 : out std_logic
55  );
56 end COMPONENT SRLC32E;
57 
58 COMPONENT fifo_40M_160M is
59  PORT (
60  rst : IN STD_LOGIC;
61  wr_clk : IN STD_LOGIC;
62  rd_clk : IN STD_LOGIC;
63  din : IN STD_LOGIC_VECTOR(49 DOWNTO 0);
64  wr_en : IN STD_LOGIC;
65  rd_en : IN STD_LOGIC;
66  dout : OUT STD_LOGIC_VECTOR(49 DOWNTO 0);
67  full : OUT STD_LOGIC;
68  empty : OUT STD_LOGIC
69  );
70 END COMPONENT fifo_40M_160M;
71 
72  signal ttc_delay_d: std_logic_vector(49 DOWNTO 0);
73  signal ttc_delay_q: std_logic_vector(49 DOWNTO 0);
74  signal ttc_fifo_rd, ttc_fifo_wr, ttc_fifo_wait: std_logic;
75  signal ttc_delay_wr_A, ttc_delay_wr_B: std_logic;
76  signal ttc_fifo_rd_A, ttc_fifo_rd_B: std_logic;
77  signal ttc_fifo_empty_A, ttc_fifo_empty_B: std_logic;
78  signal ttc_veto_clk40, ttc_veto_clk320: std_logic := '1';
79  signal q_i: std_logic_vector(DELAY_DEPTH DOWNTO 0);
80  signal actual_delay: integer range 0 to 255;
81 
82 BEGIN
83 
84 -- TTC offset in SRL32 is bottom byte of readout_delay...
85 actual_delay_block: process(clk_320)
86 variable input_delay: integer range 0 to 255;
87 begin
88  if rising_edge(clk_320) then
89  input_delay := to_integer(unsigned(readout_delay));
90  if (input_delay > DELAY_DEPTH) then
91  input_delay := DELAY_DEPTH;
92  end if;
93  actual_delay <= input_delay;
94  end if;
95 end process actual_delay_block;
96 
97 -- generate a stretched 40 MHz veto out of the original 'reset' signal
98 ttc_veto_block_clk40 : process(clk40)
99  Variable stretch: std_logic_vector(15 downto 0) := (Others => '1');
100  begin
101  if rising_edge(clk40) then
102  if (rst_ttc /= '0') then
103  stretch := (Others => '1');
104  ttc_veto_clk40 <= '1';
105  else
106  stretch := stretch(14 downto 0) & "0";
107  ttc_veto_clk40 <= stretch(15);
108  end if;
109  end if;
110  end process ttc_veto_block_clk40;
111 
112 -- generate a 320 MHz veto out of the clk40 signals
113 ttc_veto_block_clk320 : process(clk_320)
114  begin
115  if rising_edge(clk_320) then
116  if (rst_ttc /= '0') or (ttc_veto_clk40 /= '0') then
117  ttc_veto_clk320 <= '1';
118  else
119  ttc_veto_clk320 <= '0';
120  end if;
121  end if;
122  end process ttc_veto_block_clk320;
123 
124 q_i(0) <= ttc_rd_en when ttc_veto_clk40 = '0' else '0';
125 ttc_fifo_wr <= ttc_wr_en when ttc_veto_clk40 = '0' else '0';
126 ttc_fifo_rd_A <= ttc_rd_en_A when ttc_veto_clk320 = '0' else '0';
127 ttc_fifo_rd_B <= ttc_rd_en_B when ttc_veto_clk320 = '0' else '0';
128 ttc_empty_A <= ttc_fifo_empty_A when ttc_veto_clk320 = '0' else '1';
129 ttc_empty_B <= ttc_fifo_empty_B when ttc_veto_clk320 = '0' else '1';
130 
131 ttc_delay_strobe : for i in 0 to DELAY_DEPTH - 1 generate
132  SRLC32E_delay_strobe : SRLC32E
133  generic map (
134  INIT => X"00000000")
135  port map (
136  Q => Open,
137  Q31 => q_i(i+1), -- SRL cascaded data output
138  A => (Others => '1'), -- Select input
139  CE => '1', -- Clock enable input
140  CLK => CLK40, -- Clock input
141  D => q_i(i) -- SRL data input
142  );
143  end generate ttc_delay_strobe;
144 
145 ttc_fifo_delay: fifo_40M_160M
146  port map (
147  rst => rst_ttc,
148  wr_clk => clk40,
149  rd_clk => clk40,
150  din => ttc_din,
151  wr_en => ttc_fifo_wr,
152  rd_en => ttc_fifo_rd,
153  dout => ttc_delay_q,
154  full => OPEN,
155  empty => Open
156  );
157 
158 ttc_fifo_A: fifo_40M_160M
159  port map (
160  rst => rst_ttc,
161  wr_clk => clk40,
162  rd_clk => clk_320,
163  din => ttc_delay_d,
164  wr_en => ttc_delay_wr_A,
165  rd_en => ttc_fifo_rd_A,
166  dout => ttc_dout_A,
167  full => OPEN,
168  empty => ttc_fifo_empty_A
169  );
170 
171 ttc_fifo_B: fifo_40M_160M
172  port map (
173  rst => rst_ttc,
174  wr_clk => clk40,
175  rd_clk => clk_320,
176  din => ttc_delay_d,
177  wr_en => ttc_delay_wr_B,
178  rd_en => ttc_fifo_rd_B,
179  dout => ttc_dout_B,
180  full => OPEN,
181  empty => ttc_fifo_empty_B
182  );
183 
184 ttc_fifo_connect: process(clk40)
185  Begin
186  if rising_edge(clk40) then
187  ttc_fifo_rd <= q_i(actual_delay) and not ttc_veto_clk40
188 -- pragma translate_off
189  after 2 ns
190 -- pragma translate_on
191  ;
192  ttc_fifo_wait <= ttc_fifo_rd and not ttc_veto_clk40
193 -- pragma translate_off
194  after 2 ns
195 -- pragma translate_on
196  ;
197  ttc_delay_d <= ttc_delay_q
198 -- pragma translate_off
199  after 2 ns
200 -- pragma translate_on
201  ;
202  case destination_enable is
203  when "01" =>
204  ttc_delay_wr_A <= ttc_fifo_wait and not ttc_veto_clk40
205 -- pragma translate_off
206  after 2 ns
207 -- pragma translate_on
208  ;
209  ttc_delay_wr_B <= '0'
210 -- pragma translate_off
211  after 2 ns
212 -- pragma translate_on
213  ;
214  when "10" =>
215  ttc_delay_wr_A <= '0'
216 -- pragma translate_off
217  after 2 ns
218 -- pragma translate_on
219  ;
220  ttc_delay_wr_B <= ttc_fifo_wait and not ttc_veto_clk40
221 -- pragma translate_off
222  after 2 ns
223 -- pragma translate_on
224  ;
225 -- Odd events to A, even to B
226  when "11" =>
227  ttc_delay_wr_A <= ttc_fifo_wait and ttc_delay_q(12) and not ttc_veto_clk40
228 -- pragma translate_off
229  after 2 ns
230 -- pragma translate_on
231  ;
232  ttc_delay_wr_B <= ttc_fifo_wait and not ttc_delay_q(12) and not ttc_veto_clk40
233 -- pragma translate_off
234  after 2 ns
235 -- pragma translate_on
236  ;
237  when Others =>
238  ttc_delay_wr_A <= '0'
239 -- pragma translate_off
240  after 2 ns
241 -- pragma translate_on
242  ;
243  ttc_delay_wr_B <= '0'
244 -- pragma translate_off
245  after 2 ns
246 -- pragma translate_on
247  ;
248  end case;
249  end if;
250  End process ttc_fifo_connect;
251 
252 END Architecture rtl;
Switch TTC FIFO data to correct stream depending on destination_enable...
Switch TTC FIFO data to correct stream depending on destination_enable...