1 ----------------------------------------------------------------------------------
5 -- Create Date: 11:
06:
56 07/09/2014
7 -- Module Name: HCAL_trig - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
19 -- 0 Comma (
0xBC k-char)
20 -- 1 BX0 [7] VER[6:4]=1 BX ID [11:8]
22 -- 3 local trigger word
24 ----------------------------------------------------------------------------------
26 use IEEE.STD_LOGIC_1164.
ALL;
27 use IEEE.STD_LOGIC_ARITH.
ALL;
28 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
29 use IEEE.std_logic_misc.
all;
32 -- Uncomment the following library declaration if using
33 -- arithmetic functions with or values
34 --use IEEE.NUMERIC_STD.ALL;
36 -- Uncomment the following library declaration if instantiating
37 -- any Xilinx primitives in this code.
39 use UNISIM.VComponents.
all;
48 Trigdata : in array12x8;
53 ipb_addr : in (31 downto 0);
54 ipb_wdata : in (31 downto 0);
55 ipb_rdata : out (31 downto 0);
78 -- Simulation attributes
79 EXAMPLE_SIM_GTRESET_SPEEDUP : :=
"FALSE";
-- Set to 1 to speed up sim reset
80 EXAMPLE_SIMULATION : :=
0;
-- Set to 1 for simulation
81 STABLE_CLOCK_PERIOD : :=
20;
--Period of the stable clock driving this state-machine, unit is [ns]
82 EXAMPLE_USE_CHIPSCOPE : :=
0 -- Set to 1 to use Chipscope
to drive resets
89 DONT_RESET_ON_DATA_ERROR_IN :
in ;
90 GT0_TX_FSM_RESET_DONE_OUT :
out ;
91 GT0_RX_FSM_RESET_DONE_OUT :
out ;
92 GT0_DATA_VALID_IN :
in ;
94 --_________________________________________________________________________
96 --____________________________CHANNEL PORTS________________________________
97 --------------------------------- CPLL Ports -------------------------------
98 GT0_CPLLFBCLKLOST_OUT :
out ;
99 GT0_CPLLLOCK_OUT :
out ;
100 GT0_CPLLLOCKDETCLK_IN :
in ;
101 GT0_CPLLRESET_IN :
in ;
102 -------------------------- Channel - Clocking Ports ------------------------
103 GT0_GTREFCLK0_IN :
in ;
104 ---------------------------- Channel - DRP Ports --------------------------
105 GT0_DRPADDR_IN :
in (
8 downto 0);
107 GT0_DRPDI_IN :
in (
15 downto 0);
108 GT0_DRPDO_OUT :
out (
15 downto 0);
110 GT0_DRPRDY_OUT :
out ;
112 --------------------- RX Initialization and Reset Ports --------------------
113 GT0_RXUSERRDY_IN :
in ;
114 -------------------------- RX Margin Analysis Ports ------------------------
115 GT0_EYESCANDATAERROR_OUT :
out ;
116 ------------------------- Receive Ports - CDR Ports ------------------------
117 GT0_RXCDRLOCK_OUT :
out ;
118 ------------------ Receive Ports - FPGA RX Interface Ports -----------------
119 GT0_RXUSRCLK_IN :
in ;
120 GT0_RXUSRCLK2_IN :
in ;
121 ------------------ Receive Ports - FPGA RX interface Ports -----------------
122 GT0_RXDATA_OUT :
out (
31 downto 0);
123 ------------------- Receive Ports - Pattern Checker Ports ------------------
124 GT0_RXPRBSERR_OUT :
out ;
125 GT0_RXPRBSSEL_IN :
in (
2 downto 0);
126 ------------------- Receive Ports - Pattern Checker ports ------------------
127 GT0_RXPRBSCNTRESET_IN :
in ;
128 ------------------ Receive Ports - RX 8B/10B Decoder Ports -----------------
129 GT0_RXDISPERR_OUT :
out (
3 downto 0);
130 GT0_RXNOTINTABLE_OUT :
out (
3 downto 0);
131 --------------------------- Receive Ports - RX AFE -------------------------
133 ------------------------ Receive Ports - RX AFE Ports ----------------------
135 ------------- Receive Ports - RX Initialization and Reset Ports ------------
136 GT0_GTRXRESET_IN :
in ;
137 GT0_RXPMARESET_IN :
in ;
138 ------------------- Receive Ports - RX8B/10B Decoder Ports -----------------
139 GT0_RXCHARISK_OUT :
out (
3 downto 0);
140 -------------- Receive Ports -RX Initialization and Reset Ports ------------
141 GT0_RXRESETDONE_OUT :
out ;
142 --------------------- TX Initialization and Reset Ports --------------------
143 GT0_GTTXRESET_IN :
in ;
144 GT0_TXUSERRDY_IN :
in ;
145 ------------------ Transmit Ports - FPGA TX Interface Ports ----------------
146 GT0_TXUSRCLK_IN :
in ;
147 GT0_TXUSRCLK2_IN :
in ;
148 ------------------ Transmit Ports - TX Data Path interface -----------------
149 GT0_TXDATA_IN :
in (
31 downto 0);
150 ---------------- Transmit Ports - TX Driver and OOB signaling --------------
151 GT0_GTXTXN_OUT :
out ;
152 GT0_GTXTXP_OUT :
out ;
153 ----------- Transmit Ports - TX Fabric Clock Output Control Ports ----------
154 GT0_TXOUTCLK_OUT :
out ;
155 GT0_TXOUTCLKFABRIC_OUT :
out ;
156 GT0_TXOUTCLKPCS_OUT :
out ;
157 --------------------- Transmit Ports - TX Gearbox Ports --------------------
158 GT0_TXCHARISK_IN :
in (
3 downto 0);
159 ------------- Transmit Ports - TX Initialization and Reset Ports -----------
160 GT0_TXRESETDONE_OUT :
out ;
161 ------------------ Transmit Ports - pattern Generator Ports ----------------
162 GT0_TXPRBSSEL_IN :
in (
2 downto 0);
165 --____________________________COMMON PORTS________________________________
166 ---------------------- Common Block - Ref Clock Ports ---------------------
167 GT0_GTREFCLK0_COMMON_IN :
in ;
168 ------------------------- Common Block - QPLL Ports ------------------------
169 GT0_QPLLLOCK_OUT :
out ;
170 GT0_QPLLLOCKDETCLK_IN :
in ;
171 GT0_QPLLRESET_IN :
in
176 signal version : (2 downto 0) := "001";
177 signal MaskedTrigdata : array24x32 := (others => (others => '0'));
178 signal mask : array24x32 := (others => (others => '0'));
179 signal threshold : array8x4 := (others => (others => '0'));
180 signal NonZeroByteCnt : array16x4 := (others => (others => '0'));
181 signal NonZeroByte : (95 downto 0) := (others => '0');
182 signal TrigDataOut : (7 downto 0) := (others => '0');
183 signal RXDATA : (31 downto 0) := (others => '0');
184 signal TXDATA : (31 downto 0) := (others => '0');
185 signal Sample : := '0';
186 signal SampleSyncRegs : (3 downto 0) := (others => '0');
187 signal RXBUF_we : := '0';
188 signal RXBUF_wa : (4 downto 0) := (others => '0');
189 signal RXBUF_di : (29 downto 0) := (others => '0');
190 signal RXBUF : (29 downto 0) := (others => '0');
191 signal PRBSSEL : (2 downto 0) := (others => '0');
192 signal PRBSERR_cnt : (7 downto 0) := (others => '0');
193 signal RXCHARISK : (3 downto 0) := (others => '0');
194 signal txfsmresetdone : := '0';
195 signal DATA_VALID : := '0';
196 signal CPLLLOCK : := '0';
197 signal CPLLRESET : := '0';
198 signal REFCLK : := '0';
199 signal PRBSERR : := '0';
200 signal GTRXRESET : := '0';
201 signal RXRESETDONE : := '0';
202 signal GTTXRESET : := '0';
203 signal bcnt : (11 downto 0) := (others => '0');
204 signal trigmask : (7 downto 0) := (others => '0');
205 --signal : (31 downto 0) := (
others => '0');
206 --signal : (31 downto 0) := (
others => '0');
207 --signal : (31 downto 0) := (
others => '0');
208 signal en_BC0_dl : := '0';
209 signal got_BC0 : := '0';
210 signal catchBC0 : := '0';
211 signal BC0_gated : := '0';
212 signal BC0_dl : := '0';
216 if(TTC_Clk'event and TTC_Clk = '1')then
219 elsif(bcnt = x"deb")then
225 if(en_HCAL_trig = '1' and (NonZeroByteCnt(i*2) + NonZeroByteCnt(i*2+1)) > threshold(i))then
226 TrigDataOut(i) <= '1';
228 TrigDataOut(i) <= '0';
231 DATA_VALID <= not RXBUF_di(24);
232 if(PRBSSEL = "000")then
233 PRBSERR_cnt <= (others => '0');
234 elsif(PRBSERR = '1')then
235 PRBSERR_cnt <= PRBSERR_cnt + 1;
237 triggerOut <= or_reduce(trigmask and TrigDataOut);
238 SampleSyncRegs <= SampleSyncRegs(2 downto 0) & Sample;
239 if(SampleSyncRegs(3) /= SampleSyncRegs(2))then
241 elsif((CatchBC0 = '0' and and_reduce(RXBUF_wa) = '1') or BC0_dl = '1')then
244 if(RXBUF_we = '0')then
246 elsif(and_reduce(RXBUF_wa) = '1')then
249 RXBUF_wa <= RXBUF_wa + 1;
251 if(got_BC0 = '1' or RXBUF_we = '0')then
253 elsif(RXBUF_wa(4) = '1')then
256 if(RXBUF_we = '0')then
258 elsif(BC0_gated = '1')then
261 BC0_gated <= RXDATA(15) and en_BC0_dl;
266 Q => BC0_dl ,
-- SRL data output
267 A0 => '0',
-- Select[0] input
268 A1 => '1',
-- Select[1] input
269 A2 => '1',
-- Select[2] input
270 A3 => '1',
-- Select[3] input
271 CE => '1',
-- Clock enable input
272 CLK => TTC_Clk,
-- Clock input
273 D => BC0_gated
-- SRL data input
275 g_RXBUF : for i in 0 to 4 generate
278 di => RXBUF_di
(i*6+5
downto i*6
),
281 ra => ipb_addr
(4 downto 0),
282 do => RXBUF
(i*6+5
downto i*6
)
285 TXDATA <= TrigDataOut & bcnt(7 downto 0) & BC0 & version & bcnt(11 downto 8) & x"bc";
286 RXBUF_di(24) <= '0' when RXDATA(7 downto 0) = x"bc" and RXCHARISK = x"1" else '1';
287 RXBUF_di(23 downto 0) <= RXDATA(31 downto 24) & RXDATA(15 downto 8) & RXDATA(23 downto 16);
290 if(ipb_clk'event and ipb_clk = '1')then
291 if(ipb_addr(27) = '0' and ipb_addr(15 downto 4) = x"100" and ipb_write = '1' and ipb_strobe = '1')then
292 mask(conv_integer(ipb_addr(3 downto 0))) <= ipb_wdata;
294 if(ipb_addr(27) = '0' and ipb_addr(15 downto 4) = x"101" and ipb_write = '1' and ipb_strobe = '1')then
295 if(ipb_addr(3) = '0')then
296 mask(16+conv_integer(ipb_addr(2 downto 0))) <= ipb_wdata;
298 threshold(conv_integer(ipb_addr(2 downto 0))) <= ipb_wdata(3 downto 0);
301 if(ipb_addr(27) = '0' and ipb_addr(15 downto 0) = x"1020" and ipb_write = '1' and ipb_strobe = '1')then
302 PRBSSEL <= ipb_wdata(2 downto 0);
304 if(ipb_addr(27) = '0' and ipb_addr(15 downto 0) = x"1021" and ipb_write = '1' and ipb_strobe = '1')then
305 Sample <= Sample xor ipb_wdata(0);
306 CatchBC0 <= ipb_wdata(1);
308 if(ipb_addr(27) = '0' and ipb_addr(15 downto 0) = x"1040" and ipb_write = '1' and ipb_strobe = '1')then
309 trigmask <= ipb_wdata(7 downto 0);
313 process(ipb_addr, mask, threshold)
315 if(ipb_addr(15 downto 7) = "000100000")then
316 if(ipb_addr(6 downto 0) = "1000000")then
317 ipb_rdata <= x"000000" & trigmask;
318 elsif(ipb_addr(5 downto 4) = "00")then
319 ipb_rdata <= mask(conv_integer(ipb_addr(3 downto 0)));
320 elsif(ipb_addr(5 downto 3) = "010")then
321 ipb_rdata <= mask(16+conv_integer(ipb_addr(2 downto 0)));
322 elsif(ipb_addr(5 downto 3) = "011")then
323 ipb_rdata <= x"0000000" & threshold(conv_integer(ipb_addr(2 downto 0)));
324 elsif(ipb_addr(5 downto 0) = "100000")then
325 ipb_rdata <= x"0000000" & '0' & PRBSSEL;
326 elsif(ipb_addr(5 downto 0) = "100001")then
327 ipb_rdata <= x"000000" & PRBSERR_cnt;
328 elsif(ipb_addr(5) = '1')then
329 ipb_rdata <= RXBUF(24) & "0000000" & RXBUF(23 downto 0);
331 ipb_rdata <= (others => '0');
334 ipb_rdata <= (others => '0');
337 g_MaskedTrigdata : for i in 0 to 7 generate
338 g_MaskedTrigdataJ : for j in 0 to 2 generate
339 g_MaskedTrigdataK : for k in 0 to 3 generate
340 MaskedTrigdata(i*3+j)(k*8+7 downto k*8) <= not mask(i*3+j)(k*8+7 downto k*8) and Trigdata(j*4+k);
344 g_NonZeroByte : for i in 0 to 23 generate
345 g_NonZeroByteJ : for j in 0 to 3 generate
346 NonZeroByte(i*4+j) <= '0' when MaskedTrigdata(i)(j*8+7 downto j*8) = x"00" else '1';
349 g_NonZeroByteCnt_i : for i in 0 to 1 generate
350 g_NonZeroByteCnt_j : for j in 0 to 7 generate
351 i_bitcount0 : ROM64X1
353 INIT => X"6996966996696996"
) -- 0
355 O => NonZeroByteCnt
(j*2+i
)(0),
-- ROM output
356 A0 => NonZeroByte
(i*6+j*12
),
-- ROM address[0]
357 A1 => NonZeroByte
(i*6+1+j*12
),
-- ROM address[1]
358 A2 => NonZeroByte
(i*6+2+j*12
),
-- ROM address[2]
359 A3 => NonZeroByte
(i*6+3+j*12
),
-- ROM address[3]
360 A4 => NonZeroByte
(i*6+4+j*12
),
-- ROM address[4]
361 A5 => NonZeroByte
(i*6+5+j*12
) -- ROM address[5]
363 i_bitcount1 : ROM64X1
365 INIT => X"8117177e177e7ee8"
) -- 1
367 O => NonZeroByteCnt
(j*2+i
)(1),
-- ROM output
368 A0 => NonZeroByte
(i*6+j*12
),
-- ROM address[0]
369 A1 => NonZeroByte
(i*6+1+j*12
),
-- ROM address[1]
370 A2 => NonZeroByte
(i*6+2+j*12
),
-- ROM address[2]
371 A3 => NonZeroByte
(i*6+3+j*12
),
-- ROM address[3]
372 A4 => NonZeroByte
(i*6+4+j*12
),
-- ROM address[4]
373 A5 => NonZeroByte
(i*6+5+j*12
) -- ROM address[5]
375 i_bitcount2 : ROM64X1
377 INIT => X"fee8e880e8808000"
) -- 2
379 O => NonZeroByteCnt
(j*2+i
)(2),
-- ROM output
380 A0 => NonZeroByte
(i*6+j*12
),
-- ROM address[0]
381 A1 => NonZeroByte
(i*6+1+j*12
),
-- ROM address[1]
382 A2 => NonZeroByte
(i*6+2+j*12
),
-- ROM address[2]
383 A3 => NonZeroByte
(i*6+3+j*12
),
-- ROM address[3]
384 A4 => NonZeroByte
(i*6+4+j*12
),
-- ROM address[4]
385 A5 => NonZeroByte
(i*6+5+j*12
) -- ROM address[5]
392 EXAMPLE_SIM_GTRESET_SPEEDUP =>
"TRUE",
393 EXAMPLE_SIMULATION =>
0,
394 STABLE_CLOCK_PERIOD =>
20,
395 EXAMPLE_USE_CHIPSCOPE =>
0
400 SOFT_RESET_IN => '0',
401 DONT_RESET_ON_DATA_ERROR_IN => '0',
402 GT0_TX_FSM_RESET_DONE_OUT => txfsmresetdone,
403 GT0_RX_FSM_RESET_DONE_OUT =>
open,
404 GT0_DATA_VALID_IN => DATA_VALID,
410 --_____________________________________________________________________
411 --_____________________________________________________________________
414 --------------------------------- CPLL Ports -------------------------------
415 GT0_CPLLFBCLKLOST_OUT =>
open,
416 GT0_CPLLLOCK_OUT => CPLLLOCK,
417 GT0_CPLLLOCKDETCLK_IN => DRPCLK,
418 GT0_CPLLRESET_IN => CPLLRESET,
419 -------------------------- Channel - Clocking Ports ------------------------
420 GT0_GTREFCLK0_IN => REFCLK,
421 ---------------------------- Channel - DRP Ports --------------------------
422 GT0_DRPADDR_IN =>
(others => '0'
),
423 GT0_DRPCLK_IN => DRPCLK,
424 GT0_DRPDI_IN =>
(others => '0'
),
425 GT0_DRPDO_OUT =>
open,
427 GT0_DRPRDY_OUT =>
open,
429 --------------------- RX Initialization and Reset Ports --------------------
430 GT0_RXUSERRDY_IN => '0',
431 -------------------------- RX Margin Analysis Ports ------------------------
432 GT0_EYESCANDATAERROR_OUT =>
open,
433 ------------------------- Receive Ports - CDR Ports ------------------------
434 GT0_RXCDRLOCK_OUT =>
open,
435 ------------------ Receive Ports - FPGA RX Interface Ports -----------------
436 GT0_RXUSRCLK_IN => TTC_clk,
437 GT0_RXUSRCLK2_IN => TTC_clk,
438 ------------------ Receive Ports - FPGA RX interface Ports -----------------
439 GT0_RXDATA_OUT => RXDATA,
440 ------------------- Receive Ports - Pattern Checker Ports ------------------
441 GT0_RXPRBSERR_OUT => PRBSERR,
442 GT0_RXPRBSSEL_IN => PRBSSEL,
443 ------------------- Receive Ports - Pattern Checker ports ------------------
444 GT0_RXPRBSCNTRESET_IN => '0',
445 ------------------ Receive Ports - RX 8B/10B Decoder Ports -----------------
446 GT0_RXDISPERR_OUT =>
open,
447 GT0_RXNOTINTABLE_OUT =>
open,
448 --------------------------- Receive Ports - RX AFE -------------------------
449 GT0_GTXRXP_IN => GTX_RXp,
450 ------------------------ Receive Ports - RX AFE Ports ----------------------
451 GT0_GTXRXN_IN => GTX_RXn,
452 ------------- Receive Ports - RX Initialization and Reset Ports ------------
453 GT0_GTRXRESET_IN => GTRXRESET,
454 GT0_RXPMARESET_IN => '0',
455 ------------------- Receive Ports - RX8B/10B Decoder Ports -----------------
456 GT0_RXCHARISK_OUT => RXCHARISK,
457 -------------- Receive Ports -RX Initialization and Reset Ports ------------
458 GT0_RXRESETDONE_OUT => RXRESETDONE ,
459 --------------------- TX Initialization and Reset Ports --------------------
460 GT0_GTTXRESET_IN => GTTXRESET,
461 GT0_TXUSERRDY_IN => '0',
462 ------------------ Transmit Ports - FPGA TX Interface Ports ----------------
463 GT0_TXUSRCLK_IN => TTC_Clk,
464 GT0_TXUSRCLK2_IN => TTC_Clk,
465 ------------------ Transmit Ports - TX Data Path interface -----------------
466 GT0_TXDATA_IN => TXDATA,
467 ---------------- Transmit Ports - TX Driver and OOB signaling --------------
468 GT0_GTXTXN_OUT => GTX_TXn,
469 GT0_GTXTXP_OUT => GTX_TXp,
470 ----------- Transmit Ports - TX Fabric Clock Output Control Ports ----------
471 GT0_TXOUTCLK_OUT =>
open,
472 GT0_TXOUTCLKFABRIC_OUT =>
open,
473 GT0_TXOUTCLKPCS_OUT =>
open,
474 --------------------- Transmit Ports - TX Gearbox Ports --------------------
475 GT0_TXCHARISK_IN => x"1",
476 ------------- Transmit Ports - TX Initialization and Reset Ports -----------
477 GT0_TXRESETDONE_OUT =>
open,
478 ------------------ Transmit Ports - pattern Generator Ports ----------------
479 GT0_TXPRBSSEL_IN => PRBSSEL,
484 --____________________________COMMON PORTS________________________________
485 ---------------------- Common Block - Ref Clock Ports ---------------------
486 GT0_GTREFCLK0_COMMON_IN => '0',
487 ------------------------- Common Block - QPLL Ports ------------------------
488 GT0_QPLLLOCK_OUT =>
open,
489 GT0_QPLLLOCKDETCLK_IN => '0',
490 GT0_QPLLRESET_IN => '0'
494 GTTXRESET <= not CPLLLOCK;
495 GTRXRESET <= not CPLLLOCK;
497 i_REFCLK : IBUFDS_GTE2