AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Files Variables
trigger_gen.vhd
1 ------------------------------------------------------
2 -- remove CMC slink status word until the first Header on L0 & L1 before each event
3 --
4 -- Ver 1.00
5 --
6 -- Dominique Gigi Jan 2011
7 ------------------------------------------------------
8 --
9 --
10 --
11 --
12 ------------------------------------------------------
13 LIBRARY ieee;
14 --LIBRARY altera_mf;
15 --LIBRARY altera;
16 
17 
18 USE ieee.std_logic_1164.all;
19 use ieee.numeric_std.all;
20 use ieee.std_logic_unsigned.all;
21 --LIBRARY lpm;
22 --USE lpm.lpm_components.all;
23 --USE altera_mf.altera_mf_components.all;
24 --USE altera.altera_primitives_components.all;
25 
26 entity trigger_gen is
27 
28 port (
29  reset : IN std_logic;
30  PCIe_clk : IN std_logic;
31  PCIe_func : IN std_logic_vector(15 downto 0);
32  PCIe_wen : IN std_logic;
33  PCIe_dti : IN std_logic_vector(31 downto 0);
34  PCIe_dto : OUT std_logic_vector(31 downto 0);
35  PCIe_cs : IN std_logic;
36 
37  ttc_trigger : IN std_logic;
38 
39  evt_clk : IN std_logic;
40  ena_PCIe : OUT std_logic;
41  run_mode : OUT std_logic;
42  trig_nb : OUT std_logic_vector(23 downto 0);
43  trigger : OUT std_logic;
44  end_evt : IN std_logic;
45  Back_p : IN std_logic
46  );
47 end trigger_gen;
48 
49 architecture behavioral of trigger_gen is
50 
51 component resync
52 port (
53  reset : in std_logic;
54  Free_clki : in std_logic;
55  clocki : in std_logic;
56  clocko : in std_logic;
57  input : in std_logic;
58  output : out std_logic
59  );
60 end component;
61 signal delay_end_evt : std_logic_vector(3 downto 0);
62 signal pre_trig_loop : std_logic;
63 signal pre_trig_TTC : std_logic;
64 signal delay_pre_trg_TTC : std_logic;
65 signal trigger_mux : std_logic;
66 signal trig_sync : std_logic;
67 signal trigger_cnt : std_logic_vector(8 downto 0);
68 signal evt_cnt : std_logic_vector(63 downto 0);
69 signal check_trig : std_logic;
70 signal evt_working : std_logic;
71 signal pulse_trigger : std_logic;
72 signal mem_evt_num : std_logic_vector(23 downto 0);
73 signal pcie_ld : std_logic;
74 signal ld_evt_nm : std_logic;
75 signal start : std_logic;
76 signal ena_PCI_trigger : std_logic;
77 signal go_round : std_logic;
78 signal reset_func : std_logic;
79 signal PCI_trig : std_logic;
80 
81 --*********************************************************************
82 --**********************<< BEGIN >>***********************************
83 --*********************************************************************
84 begin
85 
86 -- PCIe decoding function
87 process(reset,PCIe_clk)
88 begin
89  if reset = '0' then
90  go_round <= '0';
91  ena_PCI_trigger <= '0';
92  start <= '0';
93 
94  pre_trig_loop <= '0';
95  pre_trig_TTC <= '0';
96  elsif rising_edge(PCIe_clk) then
97  -- set the loop trigger mode
98  if PCIe_cs = '1' and PCIe_func(0) = '1' and PCIe_dti(1) = '1' AND PCIe_wen = '1' then
99  go_round <= '1';
100  elsif PCIe_cs = '1' and PCIe_func(0) = '1' and PCIe_dti(2) = '1' AND PCIe_wen = '1' then
101  go_round <= '0';
102  end if;
103  -- select the trigger
104  if PCIe_cs = '1' and PCIe_func(0) = '1' AND PCIe_wen = '1' then
105  ena_PCI_trigger <= PCIe_dti(3);
106  end if;
107  -- generate a PCI trigger
108  PCI_trig <= '0';
109  if PCIe_cs = '1' and PCIe_func(0) = '1' and PCIe_dti(0) = '1' AND PCIe_wen = '1' then
110  PCI_trig <= '1';
111  end if;
112  -- start to generate triggers
113  if PCIe_cs = '1' and PCIe_func(0) = '1' AND PCIe_wen = '1' then
114  start <= PCIe_dti(4);
115  end if;
116 
117  pre_trig_loop <= '0'; -- pre trigger when loop mode
118  if PCIe_cs = '1' and PCIe_func(0) = '1' and PCIe_dti(1) = '1' AND PCIe_wen = '1' then
119  pre_trig_loop <= '1';
120  end if;
121 
122  delay_pre_trg_TTC <= pre_trig_TTC;
123  pre_trig_TTC <= '0'; -- pre trigger when TTC trigger used
124  if PCIe_cs = '1' and PCIe_func(0) = '1' and PCIe_dti(4) = '1' AND PCIe_wen = '1' then
125  pre_trig_TTC <= '1';
126  end if;
127 
128  pcie_ld <= '0';
129  if PCIe_cs = '1' and PCIe_func(1) = '1' AND PCIe_wen = '1' then
130  pcie_ld <= '1';
131  mem_evt_num <= PCIe_dti(23 downto 0);
132  end if;
133  end if;
134 end process;
135 
136 
137 process(PCIe_clk)
138 begin
139  if rising_edge(PCIe_clk) then
140  PCIe_dto <= (others => '0');
141  if PCIe_func(0) = '1' then
142  PCIe_dto(0) <= '0';
143  PCIe_dto(1) <= go_round;
144  PCIe_dto(2) <= go_round;
145  PCIe_dto(3) <= ena_PCI_trigger;
146  PCIe_dto(4) <= start;
147  PCIe_dto(5) <= '0';
148  PCIe_dto(7 downto 6) <= (others => '0');
149  PCIe_dto(8) <= evt_working;
150  PCIe_dto(9) <= Back_p;
151  PCIe_dto(31 downto 10) <= (others => '0');
152  elsif PCIe_func(1) = '1' then
153  PCIe_dto(31 downto 0) <= evt_cnt(31 downto 0);
154  elsif PCIe_func(2) = '1' then
155  PCIe_dto(31 downto 0) <= evt_cnt(63 downto 32);
156 
157  end if;
158 
159  end if;
160 end process;
161 
162 
163 -- if '1' the trigger and wc are from PCIe access (if '0' trigger s and WC comes form FIFO memory_RND)
164 ena_PCIe <= ena_PCI_trigger;
165 -- specify that the event can be generated (all parametes should be set before going to this mode
166 run_mode <= start ;
167 
168 trigger_mux <= '1' when start = '1' and ((PCI_trig = '1' AND ena_PCI_trigger= '1') or ( (ttc_trigger = '1' or delay_pre_trg_TTC = '1') AND ena_PCI_trigger= '0')) else '0';
169 
170 trg_gen:resync
171 port map(
172  reset => reset,
173  Free_clki => '1',
174  clocki => PCIe_clk,
175  input => trigger_mux,
176  clocko => evt_clk,
177  output => trig_sync
178  );
179 
180 -- trigger counter
181 process(reset,start,evt_clk)
182 begin
183  if reset = '0' or start = '0' then
184  trigger_cnt <= (others => '0');
185  elsif rising_edge(evt_clk) then
186  if trig_sync = '1' and end_evt = '0' then
187  trigger_cnt <= trigger_cnt + "1";
188  elsif trig_sync = '0' and end_evt = '1' then
189  trigger_cnt <= trigger_cnt - "1";
190  end if;
191  end if;
192 end process;
193 
194 -- create a delay at the end of the event before starting the new one's
195 process(pre_trig_loop,evt_clk)
196 begin
197 if pre_trig_loop = '1' then
198  delay_end_evt(0) <= '1';
199 elsif rising_edge(evt_clk) then
200  delay_end_evt(3 downto 1) <= delay_end_evt(2 downto 0);
201  delay_end_evt(0) <= end_evt;
202 end if;
203 end process;
204 
205 process(reset,evt_clk)
206 begin
207 if reset = '0' then
208  check_trig <= '0';
209  evt_working <= '0';
210  pulse_trigger <= '0';
211 elsif rising_edge(evt_clk) then
212  check_trig <= '0';
213  if start = '1' AND check_trig = '0' AND evt_working = '0' AND trigger_cnt /= "000000000" AND Back_p = '1' then
214  check_trig <= '1';
215  end if;
216 
217  pulse_trigger <= evt_working;
218  if (delay_end_evt(3) = '1' AND go_round = '1' AND start = '1' ) OR (go_round = '0' AND check_trig = '1' ) then
219  evt_working <= '1' ;
220  elsif end_evt = '1' then
221  evt_working <= '0' ;
222  end if;
223 
224 end if;
225 end process;
226 ld_evt_sync:resync
227 port map(
228  reset => reset,
229  Free_clki => '1',
230  clocki => PCIe_clk,
231  input => pcie_ld,
232  clocko => evt_clk,
233  output => ld_evt_nm
234  );
235 
236 -- event counter managment
237 process(reset,evt_clk)
238 begin
239 if reset = '0' then
240  evt_cnt <= (others => '0');
241 elsif rising_edge(evt_clk) then
242  if ld_evt_nm = '1' then
243  evt_cnt(63 downto 24) <= (others => '0');
244  evt_cnt(23 downto 00) <= mem_evt_num;
245  elsif end_evt = '1' then
246  evt_cnt <= evt_cnt + "1";
247  end if;
248 end if;
249 end process;
250 
251 trigger <= '1' when evt_working = '1' AND pulse_trigger = '0' else '0';
252 trig_nb <= evt_cnt(23 downto 0);
253 
254 
255 
256 end behavioral;