AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
Main Page
Design Unit List
Files
File List
All
Classes
Variables
src
CMS_DAQ_if
10Gb
slink
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
Rst_Pciclk
:
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
Rst_Evtclk
:
IN
std_logic
;
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
signal
Start_rsync
:
std_logic_vector
(
1
downto
0
)
;
81
signal
Loop_rsync
:
std_logic
;
82
--*********************************************************************
83
--**********************<<
BEGIN
>>***********************************
84
--*********************************************************************
85
begin
86
87
-- PCIe decoding
function
88
process
(Rst_Pciclk,PCIe_clk)
89
begin
90
if
Rst_Pciclk
=
'
0
'
then
91
go_round
<=
'
0
'
;
92
ena_PCI_trigger
<=
'
0
'
;
93
start
<=
'
0
'
;
94
95
pre_trig_loop
<=
'
0
'
;
96
pre_trig_TTC
<=
'
0
'
;
97
elsif
rising_edge
(
PCIe_clk
)
then
98
-- set the
loop
trigger mode
99
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
and
PCIe_dti
(
1
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
100
go_round
<=
'
1
'
;
101
elsif
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
and
PCIe_dti
(
2
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
102
go_round
<=
'
0
'
;
103
end
if
;
104
--
select
the trigger
105
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
106
ena_PCI_trigger
<=
PCIe_dti
(
3
)
;
107
end
if
;
108
--
generate
a PCI trigger
109
PCI_trig
<=
'
0
'
;
110
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
and
PCIe_dti
(
0
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
111
PCI_trig
<=
'
1
'
;
112
end
if
;
113
-- start
to
generate
triggers
114
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
115
start
<=
PCIe_dti
(
4
)
;
116
end
if
;
117
118
pre_trig_loop
<=
'
0
'
;
-- pre trigger
when
loop
mode
119
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
and
PCIe_dti
(
1
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
120
pre_trig_loop
<=
'
1
'
;
121
end
if
;
122
123
delay_pre_trg_TTC
<=
pre_trig_TTC
;
124
pre_trig_TTC
<=
'
0
'
;
-- pre trigger
when
TTC trigger used
125
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
0
)
=
'
1
'
and
PCIe_dti
(
4
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
126
pre_trig_TTC
<=
'
1
'
;
127
end
if
;
128
129
pcie_ld
<=
'
0
'
;
130
if
PCIe_cs
=
'
1
'
and
PCIe_func
(
1
)
=
'
1
'
AND
PCIe_wen
=
'
1
'
then
131
pcie_ld
<=
'
1
'
;
132
mem_evt_num
<=
PCIe_dti
(
23
downto
0
)
;
133
end
if
;
134
end
if
;
135
end
process
;
136
137
138
process
(PCIe_clk)
139
begin
140
if
rising_edge
(
PCIe_clk
)
then
141
PCIe_dto
<=
(
others
=
>
'
0
'
)
;
142
if
PCIe_func
(
0
)
=
'
1
'
then
143
PCIe_dto
(
0
)
<=
'
0
'
;
144
PCIe_dto
(
1
)
<=
go_round
;
145
PCIe_dto
(
2
)
<=
go_round
;
146
PCIe_dto
(
3
)
<=
ena_PCI_trigger
;
147
PCIe_dto
(
4
)
<=
start
;
148
PCIe_dto
(
5
)
<=
'
0
'
;
149
PCIe_dto
(
7
downto
6
)
<=
(
others
=
>
'
0
'
)
;
150
PCIe_dto
(
8
)
<=
evt_working
;
151
PCIe_dto
(
9
)
<=
Back_p
;
152
PCIe_dto
(
31
downto
10
)
<=
(
others
=
>
'
0
'
)
;
153
elsif
PCIe_func
(
1
)
=
'
1
'
then
154
PCIe_dto
(
31
downto
0
)
<=
evt_cnt
(
31
downto
0
)
;
155
elsif
PCIe_func
(
2
)
=
'
1
'
then
156
PCIe_dto
(
31
downto
0
)
<=
evt_cnt
(
63
downto
32
)
;
157
elsif
PCIe_func
(
7
)
=
'
1
'
then
158
PCIe_dto
(
8
downto
0
)
<=
trigger_cnt
;
-- pending triggers
159
end
if
;
160
161
end
if
;
162
end
process
;
163
164
165
--
if
'1' the trigger
and
wc are from PCIe
access
(
if
'0' trigger s
and
WC comes form FIFO memory_RND)
166
ena_PCIe
<=
ena_PCI_trigger
;
167
-- specify that the event can be generated (
all
parametes should be set before going
to
this mode
168
run_mode
<=
start
;
169
170
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
'
;
171
172
trg_gen:
resync
173
port
map
(
174
reset => Rst_Pciclk,
175
Free_clki => '1',
176
clocki => PCIe_clk,
177
input => trigger_mux,
178
clocko => evt_clk,
179
output => trig_sync
180
)
;
181
182
-- resync two signals
to
Evt_CK
183
Process
(evt_clk)
184
begin
185
if
rising_edge
(
evt_clk
)
then
186
Start_rsync
(
1
)
<=
Start_rsync
(
0
)
;
187
Start_rsync
(
0
)
<=
start
;
188
end
if
;
189
end
process
;
190
191
-- trigger counter
192
process
(Rst_Evtclk,Start_rsync(
1
),evt_clk)
193
begin
194
if
Rst_Evtclk
=
'
0
'
or
Start_rsync
(
1
)
=
'
0
'
then
195
trigger_cnt
<=
(
others
=
>
'
0
'
)
;
196
elsif
rising_edge
(
evt_clk
)
then
197
if
trig_sync
=
'
1
'
and
end_evt
=
'
0
'
then
198
trigger_cnt
<=
trigger_cnt
+
"1"
;
199
elsif
trig_sync
=
'
0
'
and
end_evt
=
'
1
'
then
200
trigger_cnt
<=
trigger_cnt
-
"1"
;
201
end
if
;
202
end
if
;
203
end
process
;
204
205
pre_trig_loop_i1:
resync
206
port
map
(
207
reset => Rst_PCIclk,
208
Free_clki => '1',
209
clocki => PCIe_clk,
210
input => pre_trig_loop,
211
clocko => evt_clk,
212
output => Loop_rsync
213
)
;
214
-- create a delay at the
end
of
the event before starting the
new
one's
215
process
(evt_clk)
216
begin
217
if
rising_edge
(
evt_clk
)
then
218
delay_end_evt
(
3
downto
1
)
<=
delay_end_evt
(
2
downto
0
)
;
219
delay_end_evt
(
0
)
<=
end_evt
or
Loop_rsync
;
220
end
if
;
221
end
process
;
222
223
process
(Rst_Evtclk,evt_clk)
224
begin
225
if
Rst_Evtclk
=
'
0
'
then
226
check_trig
<=
'
0
'
;
227
evt_working
<=
'
0
'
;
228
pulse_trigger
<=
'
0
'
;
229
elsif
rising_edge
(
evt_clk
)
then
230
check_trig
<=
'
0
'
;
231
if
start
=
'
1
'
AND
check_trig
=
'
0
'
AND
evt_working
=
'
0
'
AND
trigger_cnt
/=
"000000000"
AND
Back_p
=
'
1
'
then
232
check_trig
<=
'
1
'
;
233
end
if
;
234
235
pulse_trigger
<=
evt_working
;
236
if
(
delay_end_evt
(
3
)
=
'
1
'
AND
go_round
=
'
1
'
AND
start
=
'
1
'
)
OR
(
go_round
=
'
0
'
AND
check_trig
=
'
1
'
)
then
237
evt_working
<=
'
1
'
;
238
elsif
end_evt
=
'
1
'
then
239
evt_working
<=
'
0
'
;
240
end
if
;
241
242
end
if
;
243
end
process
;
244
ld_evt_sync:
resync
245
port
map
(
246
reset => Rst_Pciclk,
247
Free_clki => '1',
248
clocki => PCIe_clk,
249
input => pcie_ld,
250
clocko => evt_clk,
251
output => ld_evt_nm
252
)
;
253
254
-- event counter managment
255
process
(Rst_Evtclk,evt_clk)
256
begin
257
if
Rst_Evtclk
=
'
0
'
then
258
evt_cnt
<=
(
others
=
>
'
0
'
)
;
259
elsif
rising_edge
(
evt_clk
)
then
260
if
ld_evt_nm
=
'
1
'
then
261
evt_cnt
(
63
downto
24
)
<=
(
others
=
>
'
0
'
)
;
262
evt_cnt
(
23
downto
00
)
<=
mem_evt_num
;
263
elsif
end_evt
=
'
1
'
then
264
evt_cnt
<=
evt_cnt
+
"1"
;
265
end
if
;
266
end
if
;
267
end
process
;
268
269
trigger
<=
'
1
'
when
evt_working
=
'
1
'
AND
pulse_trigger
=
'
0
'
else
'
0
'
;
270
trig_nb
<=
evt_cnt
(
23
downto
0
)
;
271
272
273
274
end
behavioral
;
Generated on Wed Apr 18 2018 10:55:26 for AMC13 by
1.8.1