1 ----------------------------------------------------------------------------------
5 -- Create Date: 15:
55:
15 07/09/2010
7 -- Module Name: AMC_Link - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
18 ----------------------------------------------------------------------------------
20 use IEEE.STD_LOGIC_1164.
ALL;
21 use IEEE.STD_LOGIC_ARITH.
ALL;
22 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
23 use IEEE.std_logic_misc.
all;
26 -- Uncomment the following library declaration if using
27 -- arithmetic functions with or values
28 --use IEEE.NUMERIC_STD.ALL;
30 -- Uncomment the following library declaration if instantiating
31 -- any Xilinx primitives in this code.
33 use UNISIM.VComponents.
all;
35 use UNIMACRO.vcomponents.
all;
38 generic(N : := 14;
useTRIG : := false;
simulation : := false);
-- M controls FIFO size, N controls timeout
40 sysclk : in ;
-- 200MHz
48 Ready : out ;
-- Link to AMC established
49 AMC_ID : in (3 downto 0);
53 rxcommaalignen : out ;
55 RXDATA : in (15 downto 0);
56 RXCHARISCOMMA : in (1 downto 0);
57 RXCHARISK : in (1 downto 0);
58 RXNOTINTABLE : in (1 downto 0);
59 TXDATA : out (15 downto 0);
60 TXCHARISK : out (1 downto 0);
62 AMCinfo : out (15 downto 0);
63 EventInfo : out (31 downto 0);
66 AMC_DATA_RdEn : in ;
-- enable reading AMC event
67 EventInfoRdDone : in ;
-- end of reading AMC event
68 AMC_DATA : out (63 downto 0);
69 L1A_DATA : in (15 downto 0);
73 fake_DATA : in (15 downto 0);
74 -- fake_evn : in (3 downto 0);
83 Cntr_ADDR : in (11 downto 0);
84 Cntr_DATA : out (15 downto 0);
86 -- ipb_addr : in (15 downto 0);
87 -- ipb_rdata : out (31 downto 0);
88 debug_out : out (255 downto 0);
91 BC0 : in ;
-- AMC13 BC0 delayed by four TTC_clk cycles
94 TTC_status : out (127 downto 0);
95 TrigData : out (7 downto 0);
96 -- TTS is in the UsrClk domain
97 TTS_coded : out (4 downto 0)-- Disconnected, Error, Sync Lost, Busy and Overflow Warning
106 din :
IN (
23 downto 0);
108 dout :
OUT (
17 downto 0);
118 d :
IN (
15 downto 0);
119 crc :
OUT (
15 downto 0)
129 d :
IN (
15 downto 0);
130 crc :
OUT (
31 downto 0);
142 Di :
IN (
63 downto 0);
143 Do :
OUT (
63 downto 0);
144 WRERR_OUT :
OUT (
7 downto 0);
145 RDERR_OUT :
OUT (
7 downto 0);
150 generic(simulation : := false);
155 HammingData_in :
IN (
17 downto 0);
156 HammingDataValid :
IN ;
161 TrigData :
OUT (
7 downto 0)
164 constant Acknowledge : (7 downto 0) := x"12";
165 constant data : (7 downto 0) := x"34";
166 constant InitRqst : (7 downto 0) := x"56";
167 constant Counter : (7 downto 0) := x"78";
168 constant K_word : (15 downto 0) := x"3cbc";
-- sequence K28.5 K28.
1
169 constant R_word : (15 downto 0) := x"dcfb";
-- sequence K27.7 K28.
6
170 constant eof_word : (15 downto 0) := x"5cf7";
-- sequence K23.7 K28.
2
171 constant IDLE : (3 downto 0) := x"0";
-- TxState
172 constant SendK : (3 downto 0) := x"1";
-- TxState sending comma
173 constant SendType : (3 downto 0) := x"2";
-- TxState sending event data words
174 constant SendSEQ : (3 downto 0) := x"3";
-- TxState sending sequence number
175 constant SendWC : (3 downto 0) := x"4";
-- TxState sending payload word count
176 constant WaitCRC : (3 downto 0) := x"5";
-- TxState same as IDLE
177 constant SendCRC : (3 downto 0) := x"6";
-- TxState sending CRC
178 constant SendData : (3 downto 0) := x"7";
-- TxState sending event data words
179 signal AMCRdy : := '0';
180 signal AMC_IDp1: (3 downto 0) := (others => '0');
181 signal AMC_IDp4: (3 downto 0) := (others => '0');
182 signal TxState: (3 downto 0) := (others => '0');
183 signal InitLink : := '0';
184 signal RxResetDoneSyncRegs : (2 downto 0) := (others => '0');
185 signal RXDATA_q : (15 downto 0) := (others => '0');
186 signal TXDATA_i : (15 downto 0) := (others => '0');
187 signal reset_SyncRegs : (3 downto 0) := (others => '0');
188 signal fake_evn : (3 downto 0) := (others => '0');
189 signal sgl_err : := '0';
190 signal dbl_err : := '0';
191 signal sel_TTC : := '0';
192 signal is_TTS : := '0';
193 signal update_TTS : := '0';
194 signal SendTTS : := '0';
195 signal TTS_in : (3 downto 0) := (others => '0');
196 signal TTS_tmp : (7 downto 0) := (others => '0');
197 signal TTS : (7 downto 0) := (others => '0');
198 signal TTS_coded_i : (4 downto 0) := (others => '0');
199 signal TTS_valid : := '0';
200 signal TTC_lock : := '0';
201 signal BC0_lock : := '0';
202 signal BcntMm : := '0';
203 signal BC0_link : := '0';
204 signal BC0_matchCntr : (8 downto 0) := (others => '0');
205 signal TTC_missingCntr : (3 downto 0) := (others => '0');
206 signal HammingOutValid : := '0';
207 signal bcnt_link : (11 downto 0) := (others => '0');
208 signal ec_delta_BC0 : := '0';
209 signal delta_BC0 : (3 downto 0) := (others => '0');
210 signal MmCntr : (3 downto 0) := (others => '0');
211 signal TTC_DataValid : := '0';
212 signal TTC_Data : (23 downto 0) := (others => '0');
213 signal TTC_FIFO_we : := '0';
214 signal HammingOut : (17 downto 0) := (others => '0');
215 signal TTC_FIFO_Di : (11 downto 0) := (others => '0');
216 signal TTC_FIFO_Do : (11 downto 0) := (others => '0');
217 signal TTC_FIFO_Do_dl : (8 downto 0) := (others => '0');
218 signal TTC_FIFO_DoValid : := '0';
219 signal TTC_FIFO_wa : (4 downto 0) := (others => '0');
220 signal TTC_FIFO_wa0_SyncRegs : (2 downto 0) := (others => '0');
221 signal TTC_FIFO_ra : (4 downto 0) := (others => '0');
222 signal BC0_offset : (3 downto 0) := (others => '0');
223 signal check_packet : := '0';
225 signal Abort : := '0';
226 signal CntrAbort : := '0';
227 signal bad_K : := '0';
228 signal SEQ_OK : := '0';
229 signal CRC_OK : := '0';
230 signal frame_OK : := '0';
231 signal ACK_OK : := '0';
232 signal WC_OKp : := '0';
233 signal WC_OK : := '0';
234 signal TypeInit : := '0';
235 signal TypeACK : := '0';
236 signal TypeData : := '0';
237 signal TypeData_q : := '0';
238 signal TypeCntr : := '0';
239 signal Receiving : := '0';
240 signal Receiving_q : := '0';
241 signal Header2 : := '0';
242 signal IsACK : := '0';
243 signal ACKNUM_full : := '0';
244 signal ACKNUM_empty : := '0';
245 signal ACKNUM_IN : (7 downto 0) := (others => '0');
246 signal RxSEQNUM : (7 downto 0) :=(others => '0');
247 signal SEQNUM : (7 downto 0) :=(others => '0');
248 signal NextSEQNUM : (7 downto 0) :=(others => '0');
249 signal ACKNUM : (7 downto 0) := (others => '0');
250 signal CntrACKNUM : (7 downto 0) := (others => '0');
251 signal ACKNUM_MUX : (7 downto 0) := (others => '0');
252 signal ACKNUM_l : (7 downto 0) := (others => '0');
253 signal ACKNUM_a : (1 downto 0) := (others => '1');
254 signal RxType : (15 downto 0) := (others => '0');
255 signal RxWC : (11 downto 0) := (others => '0');
256 signal LinkVersion : (7 downto 0) := (others => '0');
257 signal accept : := '0';
258 signal CntrAccept : := '0';
259 signal we_ACKNUM : := '0';
260 signal save_start_addr : := '0';
262 signal got_eof : := '0';
263 signal fake_got_eof : := '0';
265 signal AMCinfo_word : := '0';
266 signal saved_BOE : := '0';
267 signal dl_cntr : (2 downto 0) := (others => '0');
268 signal we_rfifo : := '0';
269 signal rfifo : (15 downto 0) := (others => '0');
270 signal rfifo_a : (1 downto 0) := (others => '1');
271 signal EventBuf_ovf : := '0';
272 signal EventBuf_full : := '0';
273 signal ec_EventBuf_ra : := '0';
274 signal ec_EventBuf_ra_q : := '0';
275 signal evn_word : (2 downto 0) := (others => '0');
276 signal get_evn : := '0';
277 signal evn_OK : (5 downto 0) := (others => '0');
278 signal evn : (7 downto 0) := (others => '0');
279 signal LengthMatch : := '0';
280 signal UnknownLength : := '0';
281 signal bad_EventLength : := '0';
282 signal bad_AMCCRC : := '0';
283 signal InitAMCCRC : := '0';
284 signal AMCCRC : (31 downto 0) := (others => '0');
285 signal EventBuf_we : (0 downto 0) := (others => '0');
286 signal EventBuf_start : (12 downto 0) := (others => '0');
287 signal EventBuf_wa : (12 downto 0) := (others => '0');
288 signal EventBuf_ra : (10 downto 0) := (others => '0');
289 signal EventBuf_wc : (10 downto 0) := (others => '0');
290 signal EventBuf_space : (10 downto 0) := (others => '0');
291 signal EventBuf_Di : (15 downto 0) := (others => '0');
292 signal EventBuf_Do : (63 downto 0) := (others => '0');
293 signal EventWC : (19 downto 0) := (others => '0');
294 signal AMCinfoDi : (15 downto 0) := (others => '0');
295 signal EventInfoDi : (31 downto 0) := (others => '0');
296 signal EventInfoDo : (31 downto 0) := (others => '0');
297 signal EventInfo_a : (3 downto 0) := (others => '1');
298 signal EventInfo_ovfl : (1 downto 0) := (others => '1');
299 signal EventInfoToggleSyncRegs : (3 downto 0) := (others => '0');
300 signal EventInfo_full : := '0';
301 signal EventInfo_dav_i : := '0';
302 signal we_EventInfo : := '0';
303 signal end_of_block : := '0';
304 signal end_of_event : := '0';
305 signal EventInfoToggle : := '0';
306 signal EventInfoToggle_q : := '0';
307 signal re_EventInfo : := '0';
308 signal EventInfoRdDoneToggle : := '0';
309 signal EventInfoRdDoneToggleSyncRegs : (3 downto 0) := (others => '0');
310 signal we_RxCRC : := '0';
311 signal Init_RxCRC : := '0';
312 signal RxCRC : (15 downto 0) := (others => '0');
313 signal L1Ainfo_we : (0 downto 0) := (others => '0');
314 signal L1Ainfo_wa : (9 downto 0) := (others => '0');
315 signal L1Ainfo_ra : (9 downto 0) := (others => '0');
316 signal L1Ainfo_start : (7 downto 0) := (others => '0');
317 signal L1AinfoDo : (15 downto 0) := (others => '0');
318 signal L1Ainfo_wa2SyncRegs : (3 downto 0) := (others => '0');
319 signal L1Ainfo_wap : (7 downto 0) := (others => '0');
320 signal ec_L1Ainfo_ra : := '0';
321 signal re_L1AinfoDo : := '0';
322 signal L1Ainfo_empty : := '0';
323 signal timer : (N downto 0) := (others => '0');
324 signal ReSend : := '0';
325 signal ReSend_l : := '0';
326 signal ReSendQueIn : (15 downto 0) := (others => '0');
327 signal ReSendQueOut : (15 downto 0) := (others => '0');
328 signal we_ReSendQue : := '0';
329 signal ReSendQue_a : (1 downto 0) := (others => '1');
330 signal ReSendQue_empty : := '0';
331 signal ReSendQue_full : := '0';
332 signal got_comma : := '0';
333 signal GotCntr : := '0';
334 signal L1Asent : := '0';
335 signal TxType : (7 downto 0) := (others => '0');
336 signal packet_wc : (1 downto 0) := (others => '0');
337 signal we_TxCRC : := '0';
338 signal Init_TxCRC : := '0';
339 signal TxCRC : (15 downto 0) := (others => '0');
340 signal TxIsK : := '0';
341 signal Cntr_RdEn : := '0';
342 signal we_CntrBuf : := '0';
343 signal CntrBuf_Di : (15 downto 0) := (others => '0');
344 signal CntrBuf_Do : (15 downto 0) := (others => '0');
345 signal CntrBuf_wa : (5 downto 0) := (others => '0');
346 signal CntrBuf_ra : (5 downto 0) := (others => '0');
347 signal we_CntrBuf2p : := '0';
348 signal we_CntrBuf2 : := '0';
349 signal CntrBuf2_Di : (15 downto 0) := (others => '0');
350 signal CntrBuf2_SPO : (15 downto 0) := (others => '0');
351 signal CntrBuf2_SPO_q : (15 downto 0) := (others => '0');
352 signal CntrBuf2_Do : (15 downto 0) := (others => '0');
353 signal CntrBuf2_wa : (5 downto 0) := (others => '0');
354 signal resetCntrCycle : := '0';
355 signal CntrBuf_valid : := '0';
356 signal cntrs : (6 downto 0) := (others => '0');
357 signal sglErrCntr : (6 downto 0) := (others => '0');
358 signal dblErrCntr : (6 downto 0) := (others => '0');
359 signal BC0mmCntr : (6 downto 0) := (others => '0');
360 signal BcntMmCntr : (6 downto 0) := (others => '0');
361 signal ResendCntr : (6 downto 0) := (others => '0');
362 signal AcceptCntr : (6 downto 0) := (others => '0');
363 signal CntrAcceptCntr : (6 downto 0) := (others => '0');
364 signal TotalWordCntr : (15 downto 0) := (others => '0');
365 signal ACKcntr : (6 downto 0) := (others => '0');
366 signal AbortCntr : (6 downto 0) := (others => '0');
367 signal RxEventCntr : (6 downto 0) := (others => '0');
368 signal RdEventCntr : (6 downto 0) := (others => '0');
369 signal DataAbortCntr : (6 downto 0) := (others => '0');
370 signal CntrAbortCntr : (6 downto 0) := (others => '0');
371 signal BUSYCntr : (6 downto 0) := (others => '0');
372 signal EvtEVNmmCntr : (6 downto 0) := (others => '0');
373 signal EvtBCNmmCntr : (6 downto 0) := (others => '0');
374 signal EvtOCNmmCntr : (6 downto 0) := (others => '0');
375 signal ACKNUM_fullAbortCntr : (6 downto 0) := (others => '0');
376 signal EventInfo_fullAbortCntr : (6 downto 0) := (others => '0');
377 signal EventBuf_fullAbortCntr : (6 downto 0) := (others => '0');
378 signal SEQAbortCntr : (6 downto 0) := (others => '0');
379 signal CRCAbortCntr : (6 downto 0) := (others => '0');
380 signal frameAbortCntr : (6 downto 0) := (others => '0');
381 signal bad_KAbortCntr : (6 downto 0) := (others => '0');
382 signal bad_EventLengthCntr : (6 downto 0) := (others => '0');
383 signal BlockCntr : (6 downto 0) := (others => '0');
384 signal badCRCCntr : (6 downto 0) := (others => '0');
385 signal TTSCntr : (6 downto 0) := (others => '0');
386 signal TTCCntr : (6 downto 0) := (others => '0');
387 signal TTS_ERRcntr : (6 downto 0) := (others => '0');
388 signal TTS_DCcntr : (6 downto 0) := (others => '0');
389 signal TTS_OOScntr : (6 downto 0) := (others => '0');
390 signal TTS_BSYcntr : (6 downto 0) := (others => '0');
391 signal TTS_OFWcntr : (6 downto 0) := (others => '0');
392 signal WordCntr : (15 downto 0) := (others => '0');
393 signal WordCntr_q : (15 downto 0) := (others => '0');
394 signal AllZero : := '0';
395 signal zeroWordCntr : (15 downto 0) := (others => '0');
396 signal Cntr_ra : (8 downto 0) := (others => '0');
397 signal TTS_wa : (1 downto 0) := (others =>'0');
398 signal TTS_wa0_SyncRegs : (1 downto 0) := (others =>'0');
399 signal TTS_wa1_SyncRegs : (1 downto 0) := (others =>'0');
400 signal TTS_InvalidCntr : (15 downto 0) := (others =>'0');
401 signal TTS_UpdateCntr : (15 downto 0) := (others =>'0');
402 signal RxNotInTableCntr : (15 downto 0) := (others =>'0');
403 signal EofMissingCntr : (15 downto 0) := (others =>'0');
404 signal WC11p : := '0';
405 signal WC11 : := '0';
406 signal RxNotInTableErr : := '0';
407 signal fake_CRC_q : := '0';
408 signal fake_CRC_q2 : := '0';
409 signal AMCCRC_q : (15 downto 0) := (others => '0');
410 signal AMC_DATA_full : := '0';
411 signal AMC_DATA_WrEn : := '0';
412 signal AMC_DATA_Di : (63 downto 0) := (others => '0');
413 signal WRERR : (7 downto 0) := (others => '0');
414 signal RDERR : (7 downto 0) := (others => '0');
415 signal RDCOUNT : array8x12;
416 signal WRCOUNT : array8x12;
417 signal block32K : := '0';
418 signal EventWC_carry : := '0';
419 signal LengthInHeader : (19 downto 0) := (others => '0');
420 signal LengthInTrailer : (19 downto 0) := (others => '0');
421 signal Ready_i : := '0';
422 signal TTS_wait : (7 downto 0) := (others => '0');
423 signal TTS_DC_cntr : (6 downto 0) := (others => '0');
424 signal TTS_SL_cntr : (6 downto 0) := (others => '0');
425 signal TTS_ERR_cntr : (6 downto 0) := (others => '0');
426 signal critical_TTS : (1 downto 0) := (others =>'0');
427 signal critical_TTS_cntr : (1 downto 0) := (others =>'0');
428 signal GotMismatch : := '0';
429 signal FirstMismatch : (31 downto 0) := (others => '0');
431 --debug_out(255 downto 83) <= (
others => '0');
432 --debug_out(82) <= L1ASent;
433 --debug_out(81) <= AMC_DATA_WrEn;
434 --debug_out(80 downto 17) <= AMC_DATA_Di;
435 --debug_out(16) <= EventBuf_we(
0);
436 --debug_out(15 downto 0) <= EventBuf_Di;
437 rxcommaalignen <= RxResetDoneSyncRegs(2);
439 EventInfo_dav <= EventInfo_dav_i;
442 TTC_status(0) <= BC0_lock when useTRIG else '0';
443 TTC_status(1) <= TTC_lock when useTRIG else '0';
444 --TTC_status(5 downto 2) <= TTC_FIFO_ra(
3 downto 0);
445 --TTC_status(14 downto 6) <= TTC_FIFO_Di(
8 downto 0);
446 --TTC_status(18 downto 15) <= TTC_FIFO_wa(
3 downto 0);
447 --TTC_status(27 downto 19) <= TTC_FIFO_Do(
8 downto 0);
448 --TTC_status(45 downto 28) <= HammingOut
when HammingOutValid = '1'
else (
others => '0');
449 --TTC_status(49 downto 46) <= delta_BC0;
450 --TTC_status(53 downto 50) <= MmCntr;
451 --TTC_status(54) <= TTC_DataValid;
452 --TTC_status(78 downto 55) <= TTC_Data;
453 --TTC_status(79) <= TTC_FIFO_we;
454 --TTC_status(80) <= sgl_err;
455 --TTC_status(81) <= dbl_err;
456 --TTC_status(127 downto 82) <= (
others => '0');
457 debug_out(0) <= EventInfoDi(21);
458 debug_out(6 downto 1) <= evn_OK;
459 debug_out(14 downto 7) <= evn;
460 debug_out(30 downto 15) <= RXDATA;
461 debug_out(32 downto 31) <= RXCHARISK;
462 debug_out(34 downto 33) <= RXCHARISCOMMA;
463 debug_out(35) <= check_packet;
464 debug_out(36) <= accept;
465 debug_out(37) <= eof;
466 debug_out(38) <= got_eof;
467 debug_out(39) <= get_evn;
468 debug_out(40) <= header2;
469 debug_out(41) <= end_of_event;
470 debug_out(42) <= end_of_block;
471 debug_out(43) <= we_EventInfo;
472 debug_out(44) <= TypeDATA;
473 debug_out(45) <= sel_TTC;
474 debug_out(46) <= Receiving;
475 debug_out(49 downto 47) <= evn_word;
476 debug_out(61 downto 50) <= RxWC;
477 debug_out(255 downto 62) <= (others => '0');
478 TTS_coded <= TTS_coded_i;
480 variable c : (3 downto 0);
481 variable s : (3 downto 0);
483 c(0) := RXDATA(8) xor RXDATA(9) xor RXDATA(11) xor RXDATA(12);
484 c(1) := RXDATA(8) xor RXDATA(10) xor RXDATA(11) xor RXDATA(13);
485 c(2) := RXDATA(9) xor RXDATA(10) xor RXDATA(11) xor RXDATA(14);
486 c(3) := not RXDATA(11) xor RXDATA(12) xor RXDATA(13) xor RXDATA(14) xor RXDATA(15);
487 s(0) := TTS_in(0) xor TTS_in(1) xor TTS_in(3);
488 s(1) := TTS_in(0) xor TTS_in(2) xor TTS_in(3);
489 s(2) := TTS_in(1) xor TTS_in(2) xor TTS_in(3);
490 s(3) := not TTS_in(0) xor TTS_in(1) xor TTS_in(2);
491 if(UsrClk'event and UsrClk = '1')then
492 if(AMC_en = '0' or TTS_disable = '1' or test = '1')then
493 TTS_coded_i <= "00000";
-- default is Ready
494 elsif(Ready_i = '0')then
495 TTS_coded_i <= "00010";
-- default is Busy
497 case TTS(3 downto 0) is
498 when x"0" | x"f" => TTS_coded_i(4 downto 0) <= "10000";
-- disconnected
499 when x"1" => TTS_coded_i <= "00001";
-- Overflow warning
500 when x"2" => TTS_coded_i <= "00100";
-- Out of Sync
501 when x"4" => TTS_coded_i <= "00010";
-- Busy
502 when x"c" => TTS_coded_i <= "01000";
-- error
503 when x"8" => TTS_coded_i <= "00000";
-- ready
507 if(not useTRIG and RXCHARISK = "01" and RXDATA(7 downto 0) = x"5c")then
512 if((c(0) = c(3)) and or_reduce(c(2 downto 0)) = '1')then
518 TTS_in(0) <= not RXDATA(8);
520 TTS_in(0) <= RXDATA(8);
523 TTS_in(1) <= not RXDATA(9);
525 TTS_in(1) <= RXDATA(9);
528 TTS_in(2) <= not RXDATA(10);
530 TTS_in(2) <= RXDATA(10);
533 TTS_in(3) <= not RXDATA(11);
535 TTS_in(3) <= RXDATA(11);
537 if(is_TTS = '1' and TTS_valid = '1')then
539 when x"0" | x"2" | x"c" | x"f" => critical_TTS(0) <= '1';
540 when others => critical_TTS(0) <= '0';
543 critical_TTS(0) <= '0';
545 if(InitLink = '1' or Ready_i = '0')then
546 critical_TTS_cntr <= "00";
547 elsif(update_TTS = '1')then
548 if(critical_TTS = "00")then
549 critical_TTS_cntr <= "00";
551 critical_TTS_cntr <= critical_TTS_cntr + 1;
554 if(HammingOutValid = '1')then
555 case HammingOut(11 downto 8) is
556 when x"0" | x"2" | x"c" | x"f" => critical_TTS(1) <= '1';
557 when others => critical_TTS(1) <= '0';
560 critical_TTS(1) <= '0';
562 if((is_TTS = '1' and TTS_valid = '1') or HammingOutValid = '1')then
567 if(InitLink = '1' or Ready_i = '0')then
569 elsif(update_TTS = '1' and (critical_TTS = "00" or critical_TTS_cntr = "11"))then
572 if(is_TTS = '1' and TTS_valid = '1')then
573 TTS_tmp <= s & TTS_in;
574 elsif(HammingOutValid = '1')then
575 TTS_tmp(3 downto 0) <= HammingOut(11 downto 8);
579 process(UsrClk,BC0_lock)
581 if(BC0_lock = '0')then
582 BcntMmCntr <= (others => '0');
583 elsif(UsrClk'event and UsrClk = '1')then
584 if(resetCntr = '1')then
585 BcntMmCntr <= (others => '0');
586 elsif(BcntMm = '1')then
587 BcntMmCntr <= BcntMmCntr + 1;
591 AMC_IDp1 <= AMC_ID + 1;
592 AMC_IDp4(3) <= AMC_ID(3) or AMC_ID(2);
593 AMC_IDp4(2) <= not AMC_ID(2);
594 AMC_IDp4(1 downto 0) <= AMC_ID(1 downto 0);
597 if(UsrClk'event and UsrClk = '1')then
598 if(resetCntr = '1')then
599 BC0mmCntr <= (others => '0');
600 elsif(HammingOutValid = '1' and HammingOut(17) /= HammingOut(16))then
601 BC0mmCntr <= BC0mmCntr + 1;
605 elsif(Cntr_ADDR(11 downto 8) = AMC_ID or (Cntr_ADDR(11 downto 10) = "11" and Cntr_ADDR(8 downto 5) = AMC_IDp4))then
610 if(Cntr_ADDR(11 downto 8) /= AMC_ID and (Cntr_ADDR(11 downto 10) /= "11" or Cntr_ADDR(8 downto 5) /= AMC_IDp4))then
611 Cntr_ra <= (others => '0');
612 elsif(Cntr_ADDR(11 downto 10) = "11")then
613 Cntr_ra <= '1' & Cntr_ADDR(9) & "11" & Cntr_ADDR(4 downto 0);
615 Cntr_ra <= '0' & Cntr_ADDR(7 downto 2) & "00";
617 if(Cntr_RdEn = '0')then
618 Cntr_DATA <= (others => '0');
619 elsif(Cntr_ra(8 downto 7) = "00")then
620 if(CntrBuf_valid = '1')then
621 Cntr_DATA <= CntrBuf_Do;
623 Cntr_DATA <= (others => '0');
625 elsif(Cntr_ra(8 downto 2) = "0100000")then
626 Cntr_DATA <= TotalWordCntr;
627 elsif(Cntr_ra(8 downto 7) = "10")then
628 case Cntr_ra(4 downto 0) is
629 when "00000" => Cntr_DATA <= "000" & EventBuf_wa;
630 when "00001" => Cntr_DATA <= "000" & EventBuf_ra & "00";
631 when "00010" => Cntr_DATA <= "000000" & L1Ainfo_wa;
632 when "00011" => Cntr_DATA <= "000000" & L1Ainfo_ra;
633 when "00100" => Cntr_DATA <= x"00" & L1Ainfo_wap;
634 when "00101" => Cntr_DATA <= ReSendQue_a & rfifo_a & ACKNUM_a & reset_SyncRegs(3) & AMCRdy & txfsmresetdone & RxResetDone & qpll_lock & InitLink & TxState;
635 when "00110" => Cntr_DATA <= EventInfo_a & "00000" & AMCRdy & EventInfo_ovfl & TTC_lock & BC0_lock & EventInfoRdDoneToggle & EventInfoToggle;
636 when "01000" => Cntr_DATA <= EventWC(15 downto 0);
637 when "01001" => Cntr_DATA <= block32K & AMC_DATA_full & "0000000000" & EventWC(19 downto 16);
638 when "01010" => Cntr_DATA <= WordCntr_q;
639 when "01011" => Cntr_DATA <= zeroWordCntr;
640 when "01100" => Cntr_DATA <= "000" & EventBuf_start;
641 when "01101" => Cntr_DATA <= "000" & EventBuf_wc & "00";
642 when "01110" => Cntr_DATA <= x"000" & TTS_tmp(3 downto 0);
643 when "10000" => Cntr_DATA <= x"00" & LinkVersion;
644 when "10001" => Cntr_DATA <= x"00" & CTRversion;
645 when "10010" => Cntr_DATA <= FirstMismatch(15 downto 0);
646 when "10011" => Cntr_DATA <= FirstMismatch(31 downto 16);
647 when "10100" => Cntr_DATA <= x"00" & WRERR;
648 when "10110" => Cntr_DATA <= x"00" & RDERR;
649 when "11000" => Cntr_DATA <= TTS_InvalidCntr;
650 when "11001" => Cntr_DATA <= TTS_UpdateCntr;
651 when "11010" => Cntr_DATA <= RxNotInTableCntr;
652 when "11011" => Cntr_DATA <= EofMissingCntr;
653 when others => Cntr_DATA <= x"0000";
656 Cntr_DATA <= CntrBuf2_Do;
658 if(resetCntr = '1')then
659 sglErrCntr <= (others => '0');
660 elsif(sgl_err = '1')then
661 sglErrCntr <= sglErrCntr + 1;
663 if(resetCntr = '1')then
664 dblErrCntr <= (others => '0');
665 elsif(dbl_err = '1')then
666 dblErrCntr <= dblErrCntr + 1;
668 if(resetCntr = '1')then
669 ResendCntr <= (others => '0');
670 elsif(Resend = '1')then
671 ResendCntr <= ResendCntr + 1;
673 if(resetCntr = '1')then
674 AcceptCntr <= (others => '0');
675 elsif(accept = '1')then
676 AcceptCntr <= AcceptCntr + 1;
678 if(resetCntr = '1')then
679 CntrAcceptCntr <= (others => '0');
680 elsif(CntrAccept = '1')then
681 CntrAcceptCntr <= CntrAcceptCntr + 1;
683 if(resetCntr = '1')then
684 ACKcntr <= (others => '0');
686 ACKcntr <= ACKcntr + 1;
688 if(resetCntr = '1')then
689 TotalWordcntr <= (others => '0');
690 elsif(accept = '1')then
691 if(EventWC_carry = '1')then
692 TotalWordcntr <= TotalWordcntr + x"0200";
694 TotalWordcntr <= TotalWordcntr + EventWC(8 downto 0);
697 if(resetCntr = '1')then
698 RxEventCntr <= (others => '0');
699 elsif(end_of_event = '1')then
700 RxEventCntr <= RxEventCntr + 1;
702 if(resetCntr = '1')then
703 RdEventCntr <= (others => '0');
704 elsif(re_EventInfo = '1' and EventInfoDo(25) = '0')then
705 RdEventCntr <= RdEventCntr + 1;
707 TypeData_q <= TypeData;
708 if(resetCntr = '1')then
709 DataAbortCntr <= (others => '0');
710 elsif(Abort = '1')then
711 DataAbortCntr <= DataAbortCntr + 1;
713 if(resetCntr = '1')then
714 CntrAbortCntr <= (others => '0');
715 elsif(CntrAbort = '1')then
716 CntrAbortCntr <= CntrAbortCntr + 1;
718 if(resetCntr = '1')then
719 ACKNUM_fullAbortCntr <= (others => '0');
720 elsif(Abort = '1' and ACKNUM_full = '1')then
721 ACKNUM_fullAbortCntr <= ACKNUM_fullAbortCntr + 1;
723 if(resetCntr = '1')then
724 EventInfo_fullAbortCntr <= (others => '0');
725 elsif(Abort = '1' and EventInfo_full = '1')then
726 EventInfo_fullAbortCntr <= EventInfo_fullAbortCntr + 1;
728 if(resetCntr = '1')then
729 EventBuf_fullAbortCntr <= (others => '0');
730 elsif(Abort = '1' and EventBuf_full = '1')then
731 EventBuf_fullAbortCntr <= EventBuf_fullAbortCntr + 1;
733 if(resetCntr = '1')then
734 SEQAbortCntr <= (others => '0');
735 elsif((Abort = '1' or CntrAbort = '1') and SEQ_OK = '0')then
736 SEQAbortCntr <= SEQAbortCntr + 1;
738 if(resetCntr = '1')then
739 CRCAbortCntr <= (others => '0');
740 elsif((Abort = '1' or CntrAbort = '1') and CRC_OK = '0')then
741 CRCAbortCntr <= CRCAbortCntr + 1;
743 if(resetCntr = '1')then
744 frameAbortCntr <= (others => '0');
745 elsif((Abort = '1' or CntrAbort = '1') and frame_OK = '0')then
746 frameAbortCntr <= frameAbortCntr + 1;
748 if(resetCntr = '1')then
749 bad_KAbortCntr <= (others => '0');
750 elsif((Abort = '1' or CntrAbort = '1') and bad_K = '1')then
751 bad_KAbortCntr <= bad_KAbortCntr + 1;
753 if(resetCntr = '1')then
754 BlockCntr <= (others => '0');
755 elsif(we_EventInfo = '1')then
756 BlockCntr <= BlockCntr + 1;
758 if(resetCntr = '1')then
759 badCRCCntr <= (others => '0');
760 elsif(end_of_event = '1' and bad_AMCCRC = '1' and test = '0' and AMC_en = '1')then
761 badCRCCntr <= badCRCCntr + 1;
763 if(resetCntr = '1')then
764 TTSCntr <= (others => '0');
765 elsif(is_TTS = '1')then
766 TTSCntr <= TTSCntr + 1;
768 if(resetCntr = '1')then
769 TTS_DCcntr <= (others => '0');
770 TTS_ERRcntr <= (others => '0');
771 TTS_OOScntr <= (others => '0');
772 TTS_BSYcntr <= (others => '0');
773 TTS_OFWcntr <= (others => '0');
774 elsif(Ready_i = '1')then
775 if(TTS_coded_i(4) = '1')then
776 TTS_DCcntr <= TTS_DCcntr + 1;
778 if(TTS_coded_i(3) = '1')then
779 TTS_ERRcntr <= TTS_ERRcntr + 1;
781 if(TTS_coded_i(2) = '1')then
782 TTS_OOScntr <= TTS_OOScntr + 1;
784 if(TTS_coded_i(1) = '1')then
785 TTS_BSYcntr <= TTS_BSYcntr + 1;
787 if(TTS_coded_i(0) = '1')then
788 TTS_OFWcntr <= TTS_OFWcntr + 1;
791 if(resetCntr = '1')then
792 TTCCntr <= (others => '0');
793 elsif(TTC_DataValid = '1')then
794 TTCCntr <= TTCCntr + 1;
796 if(resetCntr = '1')then
797 bad_EventLengthCntr <= (others => '0');
798 elsif(end_of_event = '1' and bad_EventLength = '1')then
799 bad_EventLengthCntr <= bad_EventLengthCntr + 1;
801 if(resetCntr = '1' or test = '1' or AMC_en = '0')then
802 EvtEVNmmCntr <= (others => '0');
803 elsif(end_of_event = '1' and RxType(0) = '0')then
804 EvtEVNmmCntr <= EvtEVNmmCntr + 1;
806 if(resetCntr = '1' or test = '1' or AMC_en = '0')then
807 EvtBCNmmCntr <= (others => '0');
808 elsif(end_of_event = '1' and RxType(2) = '0')then
809 EvtBCNmmCntr <= EvtBCNmmCntr + 1;
811 if(resetCntr = '1' or test = '1' or AMC_en = '0')then
812 EvtOCNmmCntr <= (others => '0');
813 elsif(end_of_event = '1' and RxType(1) = '0')then
814 EvtOCNmmCntr <= EvtOCNmmCntr + 1;
816 if(reset = '1' or test = '1' or AMC_en = '0')then
817 FirstMismatch <= (others => '0');
819 elsif(end_of_event = '1' and GotMismatch = '0')then
820 FirstMismatch(31 downto 28) <= TTS(3 downto 0);
821 FirstMismatch(27 downto 25) <= RxType(2 downto 0);
822 FirstMismatch(24 downto 0) <= FirstMismatch(24 downto 0) + 1;
823 if(RxType(2 downto 0) /= "000")then
827 if(resetCntr = '1' or InitLink = '1')then
828 TTS_InvalidCntr <= (others => '0');
829 elsif(is_TTS = '1' and TTS_valid = '0')then
830 TTS_InvalidCntr <= TTS_InvalidCntr + 1;
832 if(resetCntr = '1' or InitLink = '1')then
833 TTS_UpdateCntr <= (others => '0');
834 elsif(update_TTS = '1')then
835 TTS_UpdateCntr <= TTS_UpdateCntr + 1;
837 if(Receiving = '1' and RxNotInTable /= "00")then
838 RxNotInTableErr <= '1';
840 RxNotInTableErr <= '0';
842 if(resetCntr = '1' or InitLink = '1')then
843 RxNotInTableCntr <= (others => '0');
844 elsif(RxNotInTableErr = '1')then
845 RxNotInTableCntr <= RxNotInTableCntr + 1;
847 if(resetCntr = '1' or InitLink = '1')then
848 EofMissingCntr <= (others => '0');
849 elsif(check_packet = '1' and eof = '0' and WC11 = '0')then
850 EofMissingCntr <= EofMissingCntr + 1;
852 if(resetCntr = '1' or Ready_i = '0')then
853 TTS_SL_cntr <= (others => '0');
854 elsif(update_TTS = '1' and TTS_tmp(3 downto 0) = x"2")then
855 TTS_SL_cntr <= TTS_SL_cntr + 1;
857 if(resetCntr = '1' or Ready_i = '0')then
858 TTS_DC_cntr <= (others => '0');
859 elsif(update_TTS = '1' and (TTS_tmp(3 downto 0) = x"0" or TTS_tmp(3 downto 0) = x"f"))then
860 TTS_DC_cntr <= TTS_DC_cntr + 1;
862 if(resetCntr = '1' or Ready_i = '0')then
863 TTS_ERR_cntr <= (others => '0');
864 elsif(update_TTS = '1' and TTS_tmp(3 downto 0) = x"c")then
865 TTS_ERR_cntr <= TTS_ERR_cntr + 1;
871 if(UsrClk'event and UsrClk = '1')then
872 if(not useTRIG or RXCHARISK = "00")then
874 elsif(RXCHARISK = "01" and RXDATA(7 downto 0) = x"bc")then
877 if(RXCHARISK(1) = '0')then
878 TTC_Data(23 downto 8) <= RXDATA;
879 TTC_Data(7 downto 0) <= TTC_Data(23 downto 16);
881 if(sel_TTC = '1' and RXCHARISK = "00" and AMCRdy = '1')then
882 TTC_DataValid <= '1';
884 TTC_DataValid <= '0';
888 i_TTC_trigger:
TTC_trigger generic map(simulation => simulation
) PORT MAP(
892 HammingData_in => HammingOut,
893 HammingDataValid => HammingOutValid,
896 TTC_lock => TTC_lock,
897 BC0_lock => BC0_lock,
902 din_valid => TTC_DataValid,
904 dout_valid => HammingOutValid ,
909 process(UsrClk,RxResetDone)
911 if(RxResetDone = '0')then
912 RxResetDoneSyncRegs <= (others => '0');
914 elsif(UsrClk'event and UsrClk = '1')then
915 RxResetDoneSyncRegs <= RxResetDoneSyncRegs(1 downto 0) & '1';
916 if(txfsmresetdone = '1')then
921 process(UsrClk,reset,RxResetDone,txfsmresetdone,qpll_lock)
923 if(reset = '1' or RxResetDone = '0' or txfsmresetdone = '0' or qpll_lock = '0')then
924 reset_SyncRegs <= (others => '1');
925 EventInfoToggle <= '0';
926 EventInfoToggle_q <= '0';
927 elsif(UsrClk'event and UsrClk = '1')then
928 reset_SyncRegs <= reset_SyncRegs(2 downto 0) & '0';
929 if((we_EventInfo = '1' and EventInfo_a = x"f") or (re_EventInfo = '1' and (EventInfo_a /= x"0" or we_EventInfo = '1')))then
930 EventInfoToggle <= not EventInfoToggle;
932 EventInfoToggle_q <= EventInfoToggle;
937 if(UsrClk'event and UsrClk = '1')then
939 EventInfo <= (others => '0');
941 EventInfo <= EventInfoDo;
943 if(RxResetDoneSyncRegs(2) = '0' or or_reduce(RxNotInTable) = '1' or bad_K = '1')then
945 elsif(RXCHARISK(0) = '1' and RXDATA(7 downto 0) = x"bc")then
948 if(InitLink = '1' or AMC_en = '0')then
950 elsif((is_TTS = '1' and TTS_valid = '1') or HammingOutValid = '1' or test = '1')then
953 if(InitLink = '1' or Ready_i = '1' or TTS_wait(7) = '1')then
956 TTS_wait <= TTS_wait + 1;
963 if(UsrClk'event and UsrClk = '1')then
964 if(timer(N) = '1' or ACK = '1' or (ReSendQue_empty = '1' and (got_comma = '0' or InitLink = '0')))then
965 timer <= (others => '0');
971 elsif(TxState = SendSEQ)then
974 -- Comma ends a packet and after that, any D-word marks the beginning of a packet
975 if((RXCHARISCOMMA = "11" and RXDATA /= R_word) or test = '1' or AMCRdy = '0')then
977 elsif(sel_TTC = '0' and RXCHARISK = "00")then
980 if(sel_TTC = '0')then
981 if(RxNotInTable /= "00")then
983 elsif(RXCHARISK = "00")then
985 if(Receiving = '0')then
987 RxSEQNUM <= RXDATA(15 downto 8);
988 if(RXDATA(7 downto 0) = InitRqst and InitLink = '1')then
993 if(RXDATA(7 downto 0) = Acknowledge)then
998 if(RXDATA(7 downto 0) = data)then
1003 if(RXDATA(7 downto 0) = Counter)then
1011 evn_word <= evn_word(1 downto 0) & Header2;
1012 if(evn_word(2) = '1' and get_evn = '1' and TypeData = '1')then
1013 evn <= RxData(7 downto 0);
1015 if(Header2 = '1')then
1016 RxWC <= (others => '0');
1021 if(RxWC(11 downto 2) = RxData(11 downto 2) and RxWC(1 downto 0) = "00")then
1027 WC11p <= RxData(11);
1029 if(evn = RxData(15 downto 8))then
1034 evn_OK(4 downto 1) <= evn_OK(3 downto 0);
1036 elsif(RXCHARISK = "10" or (RXCHARISK = "11" and RXDATA /= R_word and RXDATA /= eof_word and RXCHARISCOMMA /= "11") or (RXCHARISK = "01" and RXDATA(7 downto 0) /= x"5c" and RXDATA(7 downto 0) /= x"bc"))then
1040 if((TypeACK = '1' or TypeInit = '1') and RXType(15 downto 8) = ReSendQueOut(15 downto 8) and ReSendQue_empty = '0' and ReSend = '0')then -- incoming acknowledge number is what waited for
1045 if(Receiving = '0')then
1046 ACKNUM_IN <= RxSEQNUM;
1048 if(RxSEQNUM = NextSEQNUM)then -- incoming sequence number is what waited for
1053 if(or_reduce(RxCRC) = '0')then
1058 if(WC_OK = '1' and (((TypeData = '1' or TypeCntr = '1' or TypeACK = '1') and InitLink = '0') or (TypeInit = '1' and InitLink = '1')))then
1063 if(RXCHARISCOMMA = "11" and RXDATA /= R_word and Receiving = '1')then
1064 check_packet <= '1';
1066 check_packet <= '0';
1068 accept <= check_packet and SEQ_OK and CRC_OK and frame_OK and not EventInfo_full and not EventBuf_ovf and not bad_K and not ACKNUM_full and (eof or WC11) and TypeData;
1069 CntrAccept <= check_packet and SEQ_OK and CRC_OK and frame_OK and not bad_K and TypeCntr;
1070 we_ACKNUM <= check_packet and CRC_OK and frame_OK and not bad_K and not ACKNUM_full and not EventInfo_full and not EventBuf_ovf and (eof or WC11) and TypeData;
1071 ACK <= check_packet and ACK_OK and CRC_OK and frame_OK and not bad_K;
1072 -- Abort <= check_packet and (TypeData or TypeCntr) and not(SEQ_OK and CRC_OK and frame_OK and not bad_K and not((ACKNUM_full or EventInfo_full or EventBuf_ovf) and TypeData));
1073 -- Abort <= check_packet and (TypeData or TypeCntr) and not(SEQ_OK and CRC_OK and frame_OK and not bad_K and
1074 -- not((ACKNUM_full or EventInfo_full or EventBuf_ovf or (not eof and not WC11)) and TypeData));
1075 Abort <= check_packet and TypeData and not(SEQ_OK and CRC_OK and frame_OK and not bad_K and not ACKNUM_full and not EventInfo_full and not EventBuf_ovf and (eof or WC11));
1076 CntrAbort <= check_packet and TypeCntr and not(SEQ_OK and CRC_OK and frame_OK and not bad_K);
1077 if(InitLink = '1')then
1079 elsif(accept = '1')then
1083 EventInfoDi(30 downto 27) <= fake_evn;
1084 elsif(accept = '1')then
1085 EventInfoDi(30 downto 27) <= evn(3 downto 0);
1087 if(TxState = SendCRC and TxType = Counter)then
1089 elsif(CntrAccept = '1')then
1092 if(InitLink = '1')then
1093 CntrACKNUM <= x"00";
1094 elsif(CntrAccept = '1')then
1095 CntrACKNUM <= RxSEQNUM;
1097 if(reset_SyncRegs(3) = '1')then
1098 ACKNUM_a <= (others => '1');
1099 elsif(we_ACKNUM = '1' and (TxState /= SendCRC or SendTTS = '1' or IsACK = '0'))then
1100 ACKNUM_a <= ACKNUM_a + 1;
1101 elsif(we_ACKNUM = '0' and TxState = SendCRC and IsACK = '1' and SendTTS = '0')then
1102 ACKNUM_a <= ACKNUM_a - 1;
1104 if(ACKNUM_a = "11")then
1105 ACKNUM_empty <= '1';
1107 ACKNUM_empty <= '0';
1109 if(ACKNUM_a = "10")then
1114 if(InitLink = '1')then
1116 elsif(ACKNUM_a /= "11")then
1119 if(reset_SyncRegs(3) = '1')then
1120 NextSEQNUM <= x"00";
1121 elsif(accept = '1')then
1122 NextSEQNUM <= NextSEQNUM(6 downto 0) & not(NextSEQNUM(7) xor NextSEQNUM(5) xor NextSEQNUM(4) xor NextSEQNUM(3));
1124 -- Receiving of eof K-word in a packet marks the end of the event
1125 -- if(Receiving = '0' or InitLink = '1')then
1126 if(check_packet = '1' or InitLink = '1')then
1128 elsif(RXCHARISK = "11" and RXDATA = eof_word)then
1131 -- latches eof signal
1132 if(check_packet = '1')then
1135 -- if buffer is getting full during packet receiving, buffer overflow error is set
1136 if(Receiving = '0')then
1137 EventBuf_ovf <= '0';
1138 elsif(EventBuf_full = '1')then
1139 EventBuf_ovf <= '1';
1141 Receiving_q <= Receiving;
1142 if(InitLink = '1')then
1143 EventBuf_wa <= (others => '0');
1144 elsif(abort = '1')then
1145 EventBuf_wa <= EventBuf_start;
1146 elsif(EventBuf_we(0) = '1')then
1147 EventBuf_wa <= EventBuf_wa + 1;
1149 if(InitLink = '1')then
1150 EventBuf_ra <= (others => '0');
1151 elsif(ec_EventBuf_ra = '1')then
1152 EventBuf_ra <= EventBuf_ra + 1;
1154 -- packet starting write address is recorded before the first data is written to the buffer
1155 if(InitLink = '1')then
1156 EventBuf_start <= (others => '0');
1157 elsif(save_start_addr = '1')then
1158 EventBuf_start <= EventBuf_wa;
1160 -- accepted data in EventBuf available for read out
1161 if(InitLink = '1')then
1162 EventBuf_wc <= (others => '0');
1163 elsif(ec_EventBuf_ra = '1')then
1164 EventBuf_wc <= EventBuf_wc - 1;
1166 EventBuf_wc <= EventBuf_start(12 downto 2) - EventBuf_ra;
1168 EventBuf_space <= EventBuf_wa(12 downto 2) - EventBuf_ra;
1169 -- buffer almost full
1170 if(and_reduce(EventBuf_space(10 downto 5)) = '1')then
1171 EventBuf_full <= '1';
1173 EventBuf_full <= '0';
1175 fake_full <= EventBuf_full or EventInfo_full;
1180 init_crc => Init_RxCRC,
1185 we_RxCRC <= '1' when RXCHARISK = "00" and sel_TTC = '0' else '0';
1186 Init_RxCRC <= '1' when RXCHARISCOMMA = "11" else '0';
1189 init => InitAMCCRC ,
1192 ce => EventBuf_we
(0),
1195 bad_crc => bad_AMCCRC
1199 if(UsrClk'event and UsrClk = '1')then
1200 if(InitLink = '1' or end_of_event = '1')then
1207 g_ACKNUM : for i in 0 to 7 generate
1210 Q => ACKNUM
(i
),
-- SRL data output
1211 A0 => ACKNUM_a
(0),
-- Select[0] input
1212 A1 => ACKNUM_a
(1),
-- Select[1] input
1213 A2 => '0',
-- Select[2] input
1214 A3 => '0',
-- Select[3] input
1215 CE => we_ACKNUM,
-- Clock enable input
1216 CLK => UsrClk,
-- Clock input
1217 D => ACKNUM_IN
(i
) -- SRL data input
1220 -- this fifo is used to hold the last couple of received data words before writing to the data buffer.
1221 -- this is because 1. word count
and CRC
of the packet should
not be written
to the
buffer and more importantly,
1222 -- if the packet is the last packet of the event, the last data word must be properly marked with the LinkCtrl
1223 -- before being written to the buffer. 3.
next packet data may arrive before a decision being made
to accept
or reject a packet.
1224 g_rfifo: for i in 0 to 15 generate
1227 Q => rfifo
(i
),
-- SRL data output
1228 A0 => '1',
-- Select[0] input
1229 A1 => '0',
-- Select[1] input
1230 A2 => '0',
-- Select[2] input
1231 A3 => '0',
-- Select[3] input
1232 CE => we_rfifo,
-- Clock enable input
1233 CLK => UsrClk,
-- Clock input
1234 D => RXDATA_q
(i
) -- SRL data input
1239 if(UsrClk'event and UsrClk = '1')then
1240 if(sel_TTC = '0' and RXCHARISK = "00")then
1245 if(InitLink = '1' or check_packet = '1')then
1247 elsif(we_rfifo = '1')then
1248 dl_cntr(2) <= dl_cntr(2) or (dl_cntr(1) and dl_cntr(0));
1249 dl_cntr(1) <= dl_cntr(1) xor dl_cntr(0);
1250 dl_cntr(0) <= not dl_cntr(2) and not dl_cntr(0);
1254 g_EventBuffer : for i in 0 to 3 generate
1255 i_EventBuffer : BRAM_SDP_MACRO
1257 BRAM_SIZE =>
"36Kb",
-- Target BRAM, "18Kb" or "36Kb"
1258 DEVICE =>
"7SERIES",
-- Target device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
1259 WRITE_WIDTH =>
4,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
1260 READ_WIDTH =>
16,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
1261 DO_REG =>
1,
-- Optional output register (0 or 1)
1262 SIM_COLLISION_CHECK =>
"NONE") -- Collision check enable "ALL",
"WARNING_ONLY",
1263 -- "GENERATE_X_ONLY" or "NONE"
1265 DO => EventBuf_Do
(i*16+15
downto i*16
),
-- Output read data port, width defined by READ_WIDTH parameter
1266 DI => EventBuf_Di
(i*4+3
downto i*4
),
-- Input write data port, width defined by WRITE_WIDTH parameter
1267 RDADDR => EventBuf_ra,
-- Input read address, width defined by read port depth
1268 RDCLK => UsrClk,
-- 1-bit input read clock
1269 RDEN => '1',
-- 1-bit input read port enable
1270 REGCE => '1',
-- 1-bit input read output register enable
1271 RST => '0',
-- 1-bit input reset
1272 WE => "
1",
-- Input write enable, width defined by write port depth
1273 WRADDR => EventBuf_wa,
-- Input write address, width defined by write port depth
1274 WRCLK => UsrClk,
-- 1-bit input write clock
1275 WREN => EventBuf_we
(0) -- 1-bit input write port enable
1278 g_MC_DATA_Di : for i in 0 to 3 generate
1279 g_AMC_DATA_Dij: for j in 0 to 3 generate
1280 AMC_DATA_Di(i*16+j*4+3 downto i*16+j*4) <= EventBuf_Do(i*4+j*16+3 downto i*4+j*16);
1288 we => AMC_DATA_WrEn,
1289 re => AMC_DATA_RdEn,
1294 full => AMC_DATA_full
1296 --AMC_DATA_WrEn <= fifo_en and not AMC_DATA_full(0)
and AMC_DATA_Di_vld;
1299 if(UsrClk'event and UsrClk = '1')then
1300 if(reset_SyncRegs(3) = '1' or fifo_en = '0' or AMC_DATA_full = '1')then
1301 ec_EventBuf_ra <= '0';
1302 elsif(or_reduce(EventBuf_wc(10 downto 1)) = '0' and (EventBuf_wc(0) = '0' or ec_EventBuf_ra = '1'))then
1303 ec_EventBuf_ra <= '0';
1305 ec_EventBuf_ra <= '1';
1307 ec_EventBuf_ra_q <= fifo_en and ec_EventBuf_ra;
1308 AMC_DATA_WrEn <= fifo_en and ec_EventBuf_ra_q;
1313 if(UsrClk'event and UsrClk = '1')then
1314 if(InitLink = '1' or (test = '1' and fake_got_eof = '1') or (test = '0' and ((abort = '1' and saved_BOE = '1') or (accept = '1' and got_eof = '1'))))then
1316 elsif(EventBuf_we(0) = '1' and EventBuf_wa(0) = '1')then
1319 if(InitLink = '1' or accept = '1')then
1321 elsif(BOE = '1')then
1325 AMCinfo_word <= '1';
1326 elsif(AMCinfo_word = '1' and EventBuf_we(0) = '1' and EventBuf_wa(1 downto 0) = "00")then
1327 AMCinfo_word <= '0';
1328 AMCinfoDi <= EventBuf_Di;
1330 -- if(InitLink = '1' or end_of_block = '1' or end_of_event = '1')then
1331 if(InitLink = '1' or (accept = '1' and end_of_block = '1') or end_of_event = '1')then
1333 elsif(EventWC_carry = '1' and EventWC(11 downto 9) = "111" and(test = '1' or accept = '1'))then
1336 -- if(InitLink = '0' and AMC_en = '1' and block32K = '1' and end_of_block = '0' and and_reduce(EventWC(9 downto 1)) = '1'
and EventBuf_we(
0) = '1')
then
1337 -- end_of_block <= '1';
1339 -- end_of_block <= '0';
1341 if(EventBuf_we(0) = '1')then
1342 if(block32K = '1' and and_reduce(EventWC(9 downto 1)) = '1')then
1343 end_of_block <= '1';
1345 end_of_block <= '0';
1348 if(InitLink = '0' and ((test = '1' and fake_got_eof = '1') or (test = '0' and accept = '1' and got_eof = '1')))then
1349 end_of_event <= '1';
1351 end_of_event <= '0';
1353 -- we_EventInfo <= not InitLink and not(NoReSyncFake and EventInfoDi(31))
and (end_of_block
or end_of_event);
1354 if(InitLink = '1' or (NoReSyncFake = '1' and EventInfoDi(31) = '1') or AMC_en = '0')then
1355 we_EventInfo <= '0';
1356 elsif(accept = '1' and end_of_block = '1')then
1357 we_EventInfo <= '1';
1358 elsif(end_of_event = '1')then
1359 we_EventInfo <= '1';
1361 we_EventInfo <= '0';
1363 if(InitLink = '1' or (test = '0' and abort = '1') or end_of_event = '1')then
1364 EventWC(8 downto 0) <= (others => '0');
1365 elsif(EventBuf_we(0) = '1' and EventBuf_wa(1 downto 0) = "11")then
1366 EventWC(8 downto 0) <= EventWC(8 downto 0) + 1;
1368 if(InitLink = '1' or (test = '0' and (abort = '1' or accept = '1')) or (test = '1' and EventWC_carry = '1'))then
1369 EventWC_carry <= '0';
1370 elsif(EventBuf_we(0) = '1' and EventBuf_wa(1 downto 0) = "11" and and_reduce(EventWC(8 downto 0)) = '1')then
1371 EventWC_carry <= '1';
1373 if(EventBuf_we(0) = '1' and EventBuf_wa(1 downto 0) = "00")then
1374 LengthInTrailer(15 downto 0) <= EventBuf_Di;
1376 if(EventBuf_we(0) = '1' and EventBuf_wa(1 downto 0) = "01")then
1377 LengthInTrailer(19 downto 16) <= EventBuf_Di(3 downto 0);
1379 if(InitLink = '1' or end_of_event = '1')then
1380 EventWC(19 downto 9) <= (others => '0');
1381 elsif(EventWC_carry = '1' and(test = '1' or accept = '1'))then
1382 EventWC(19 downto 9) <= EventWC(19 downto 9) + 1;
1384 UnknownLength <= and_reduce(LengthInHeader);
1385 if(LengthInHeader = LengthInTrailer or UnknownLength = '1')then
1390 if(EventWC = LengthInTrailer and LengthMatch = '1')then
1391 bad_EventLength <= '0';
1393 bad_EventLength <= '1';
1395 if(end_of_event = '1')then
1396 EventInfoDi(19 downto 0) <= "0000000" & block32K & EventWC(11 downto 0);
1397 EventInfoDi(25) <= '0';
-- M
1398 EventInfoDi(26) <= bad_EventLength;
-- EventLengthErr
1399 elsif(BOE = '1' and EventBuf_we(0) = '1')then
1400 if(EventBuf_wa(0) = '0')then
1401 EventInfoDi(15 downto 0) <= EventBuf_Di;
1402 LengthInHeader(15 downto 0) <= EventBuf_Di;
1404 EventInfoDi(19 downto 16) <= EventBuf_Di(3 downto 0);
1405 LengthInHeader(19 downto 16) <= EventBuf_Di(3 downto 0);
1407 EventInfoDi(24) <= '0';
-- S
1408 EventInfoDi(25) <= '1';
-- M
1409 EventInfoDi(26) <= '0';
-- EventLengthErr
1410 elsif(we_EventInfo = '1')then
1411 EventInfoDi(19 downto 0) <= x"01000";
1412 EventInfoDi(24) <= '1';
-- S
1413 EventInfoDi(25) <= '1';
-- M
1415 if(InitLink = '1' or we_EventInfo = '1')then
1416 EventInfoDi(20) <= '0';
1417 elsif(end_of_event = '1')then
1418 EventInfoDi(20) <= (not bad_AMCCRC or test) and AMC_en;
1420 if(AMC_en = '0')then
1422 LinkVersion <= x"00";
1423 elsif(InitLink = '1')then
1424 if(ACK = '1' and CTRversion = RxType(7 downto 0))then
1430 LinkVersion <= RxType(7 downto 0);
1433 if(check_packet = '1')then
1434 evn_OK(5) <= evn_OK(4) or not eof;
1436 -- EventInfoDi(21) <=
not(RxType(
2)
and RxType(
1)
and RxType(
0))
and not test
and AMC_en;
1437 EventInfoDi(31) <= RxType(3) and AMC_en and not test;
-- got faked data during ReSync
1438 EventInfoDi(21) <= ((RxType(2) and RxType(1) and RxType(0) and evn_OK(5)) or test) and AMC_en;
1439 EventInfoDi(22) <= AMC_en;
1440 EventInfoDi(23) <= AMC_en;
1441 fake_CRC_q <= not InitLink and AMC_en and fake_CRC;
1442 fake_CRC_q2 <= not InitLink and fake_CRC_q;
1443 AMCCRC_q <= AMCCRC(31 downto 16);
1445 if(fake_header = '1')then
1446 EventBuf_Di <= x"0" & AMC_IDp1 & fake_DATA(7 downto 0);
1447 fake_evn <= fake_DATA(3 downto 0);
1448 elsif(fake_CRC_q = '1')then
1449 EventBuf_Di <= AMCCRC(15 downto 0);
1450 elsif(fake_CRC_q2 = '1')then
1451 EventBuf_Di <= AMCCRC_q;
1453 EventBuf_Di <= fake_DATA;
1456 EventBuf_Di <= rfifo;
1459 EventBuf_we(0) <= (fake_WrEn or fake_CRC_q2) and not fake_CRC and AMC_en;
1460 elsif(we_rfifo = '1' and dl_cntr(2) = '1' and TypeData = '1' and abort = '0' and EventBuf_full = '0')then
1461 EventBuf_we(0) <= '1';
1463 EventBuf_we(0) <= '0';
1465 if(test = '1' or (InitLink = '0' and accept = '1'))then
1466 save_start_addr <= '1';
1468 save_start_addr <= '0';
1470 if(InitLink = '1')then
1471 EventInfo_a <= (others => '1');
1472 EventInfo_ovfl <= (others => '0');
1473 elsif(we_EventInfo = '1' and re_EventInfo = '0')then
1474 EventInfo_a <= EventInfo_a + 1;
1475 if(EventInfo_a = x"e")then
1476 EventInfo_ovfl(0) <= '1';
1478 elsif(we_EventInfo = '0' and re_EventInfo = '1')then
1479 EventInfo_a <= EventInfo_a - 1;
1480 if(EventInfo_a = x"f")then
1481 EventInfo_ovfl(1) <= '1';
1484 if(EventInfo_a = x"d" or EventInfo_a = x"e" or (test = '1' and EventInfo_a(3) = '1' and EventInfo_a(2 downto 0) /= "111"))then
1485 EventInfo_full <= '1';
1487 EventInfo_full <= '0';
1489 re_EventInfo <= not InitLink and (EventInfoRdDoneToggleSyncRegs(3) xor EventInfoRdDoneToggleSyncRegs(2));
1490 if(InitLink = '1')then
1491 EventInfoRdDoneToggleSyncRegs <= (others => '0');
1493 EventInfoRdDoneToggleSyncRegs <= EventInfoRdDoneToggleSyncRegs(2 downto 0) & EventInfoRdDoneToggle;
1495 if(resetCntrCycle = '1')then
1496 CntrBuf_Di <= (others => '0');
1499 CntrBuf_Di <= rfifo;
1500 we_CntrBuf <= we_rfifo and dl_cntr(2) and TypeCntr and not Cntrabort;
1502 if(Receiving = '0')then
1503 CntrBuf_wa(4 downto 0) <= (others => '0');
1504 elsif(we_CntrBuf = '1')then
1505 CntrBuf_wa(4 downto 0) <= CntrBuf_wa(4 downto 0) + 1;
1507 if(InitLink = '1')then
1508 CntrBuf_wa(5) <= '0';
1509 elsif(CntrAccept = '1')then
1510 CntrBuf_wa(5) <= not CntrBuf_wa(5);
1512 if(InitLink = '1' or resetCntr = '1')then
1513 CntrBuf_valid <= '0';
1514 elsif(CntrAccept = '1')then
1515 CntrBuf_valid <= '1';
1519 i_fake_got_eof : SRL16E
1521 Q => fake_got_eof,
-- SRL data output
1522 A0 => '0',
-- Select[0] input
1523 A1 => '1',
-- Select[1] input
1524 A2 => '0',
-- Select[2] input
1525 A3 => '0',
-- Select[3] input
1526 CE => '1',
-- Clock enable input
1527 CLK => UsrClk,
-- Clock input
1528 D => fake_CRC_q
-- SRL data input
1530 g_AMCinfo : for i in 0 to 15 generate
1533 Q => AMCinfo
(i
),
-- SRL data output
1534 A0 => EventInfo_a
(0),
-- Select[0] input
1535 A1 => EventInfo_a
(1),
-- Select[1] input
1536 A2 => EventInfo_a
(2),
-- Select[2] input
1537 A3 => EventInfo_a
(3),
-- Select[3] input
1538 CE => we_EventInfo,
-- Clock enable input
1539 CLK => UsrClk,
-- Clock input
1540 D => AMCinfoDi
(i
) -- SRL data input
1543 g_EventInfo : for i in 0 to 31 generate
1544 i_EventInfo : SRL16E
1546 Q => EventInfoDo
(i
),
-- SRL data output
1547 A0 => EventInfo_a
(0),
-- Select[0] input
1548 A1 => EventInfo_a
(1),
-- Select[1] input
1549 A2 => EventInfo_a
(2),
-- Select[2] input
1550 A3 => EventInfo_a
(3),
-- Select[3] input
1551 CE => we_EventInfo,
-- Clock enable input
1552 CLK => UsrClk,
-- Clock input
1553 D => EventInfoDi
(i
) -- SRL data input
1556 g_CntrBuf : for i in 0 to 15 generate
1557 i_CntrBuf : RAM64X1D
1559 DPO => CntrBuf_Do
(i
),
-- Read-only 1-bit data output
1560 SPO =>
open,
-- R/W 1-bit data output
1561 A0 => CntrBuf_wa
(0),
-- R/W address[0] input
1562 A1 => CntrBuf_wa
(1),
-- R/W address[1] input
1563 A2 => CntrBuf_wa
(2),
-- R/W address[2] input
1564 A3 => CntrBuf_wa
(3),
-- R/W address[3] input
1565 A4 => CntrBuf_wa
(4),
-- R/W address[4] input
1566 A5 => CntrBuf_wa
(5),
-- R/W address[5] input
1567 D => CntrBuf_Di
(i
),
-- Write 1-bit data input
1568 DPRA0 => CntrBuf_ra
(0),
-- Read-only address[0] input
1569 DPRA1 => CntrBuf_ra
(1),
-- Read-only address[1] input
1570 DPRA2 => CntrBuf_ra
(2),
-- Read-only address[2] input
1571 DPRA3 => CntrBuf_ra
(3),
-- Read-only address[3] input
1572 DPRA4 => CntrBuf_ra
(4),
-- Read-only address[4] input
1573 DPRA5 => CntrBuf_ra
(5),
-- Read-only address[5] input
1574 WCLK => UsrClk,
-- Write clock input
1575 WE => we_CntrBuf
-- Write enable input
1578 CntrBuf_ra <= not CntrBuf_wa(5) & Cntr_ra(6 downto 2);
1579 g_CntrBuf2 : for i in 0 to 15 generate
1580 i_CntrBuf2 : RAM64X1D
1582 DPO => CntrBuf2_Do
(i
),
-- Read-only 1-bit data output
1583 SPO => CntrBuf2_SPO
(i
),
-- R/W 1-bit data output
1584 A0 => CntrBuf2_wa
(0),
-- R/W address[0] input
1585 A1 => CntrBuf2_wa
(1),
-- R/W address[1] input
1586 A2 => CntrBuf2_wa
(2),
-- R/W address[2] input
1587 A3 => CntrBuf2_wa
(3),
-- R/W address[3] input
1588 A4 => CntrBuf2_wa
(4),
-- R/W address[4] input
1589 A5 => CntrBuf2_wa
(5),
-- R/W address[5] input
1590 D => CntrBuf2_Di
(i
),
-- Write 1-bit data input
1591 DPRA0 => Cntr_ra
(2),
-- Read-only address[0] input
1592 DPRA1 => Cntr_ra
(3),
-- Read-only address[1] input
1593 DPRA2 => Cntr_ra
(4),
-- Read-only address[2] input
1594 DPRA3 => Cntr_ra
(5),
-- Read-only address[3] input
1595 DPRA4 => Cntr_ra
(6),
-- Read-only address[4] input
1596 DPRA5 => Cntr_ra
(8),
-- Read-only address[5] input
1597 WCLK => UsrClk,
-- Write clock input
1598 WE => we_CntrBuf2
-- Write enable input
1603 if(UsrClk'event and UsrClk = '1')then
1604 if(resetCntr = '1')then
1605 zeroWordCntr <= (others => '0');
1606 elsif(or_reduce(EventBuf_Di) = '0' and EventBuf_wa(1 downto 0) = "11" and AllZero = '1' and EventBuf_we(0) = '1')then
1607 zeroWordCntr <= zeroWordCntr + 1;
1609 if(resetCntr = '1')then
1611 elsif(EventBuf_we(0) = '1')then
1612 if(EventBuf_wa(1 downto 0) = "11")then
1614 elsif(or_reduce(EventBuf_Di) = '1')then
1618 we_CntrBuf2p <= not we_CntrBuf2;
1619 we_CntrBuf2 <= we_CntrBuf2p and not we_CntrBuf2;
1620 if(resetCntr = '1')then
1621 CntrBuf2_wa <= "111000";
1622 elsif(we_CntrBuf2 = '1')then
1623 if(CntrBuf2_wa = "011111")then -- 40 counters
3 is 120 <
128 and 7 counters won't overflow
1624 CntrBuf2_wa <= "111000";
1626 CntrBuf2_wa <= CntrBuf2_wa + 1;
1629 if(resetCntr = '1')then
1630 resetCntrCycle <= '1';
1631 elsif(we_CntrBuf2 = '1' and CntrBuf2_wa = "011111")then
1632 resetCntrCycle <= '0';
1634 if(CntrBuf2_wa(5) = '1')then
1635 case CntrBuf2_wa(2 downto 0) is
1636 when "000" => Cntrs <= TTS_OFWcntr;
1637 when "001" => Cntrs <= TTS_BSYcntr;
1638 when "010" => Cntrs <= TTS_OOScntr;
1639 when "011" => Cntrs <= TTS_ERRcntr;
1640 when "100" => Cntrs <= TTS_DCcntr;
1641 when others => Cntrs <= (others=> '0');
1643 elsif(CntrBuf2_wa(4) = '0')then
1644 case CntrBuf2_wa(3 downto 0) is
1645 when x"1" => Cntrs <= sglErrCntr;
1646 when x"2" => Cntrs <= dblErrCntr;
1647 when x"3" => Cntrs <= BC0mmCntr;
1648 when x"4" => Cntrs <= BcntMmCntr;
1649 when x"5" => Cntrs <= ResendCntr;
1650 when x"6" => Cntrs <= AcceptCntr;
1651 when x"7" => Cntrs <= CntrAcceptCntr;
1652 when x"8" => Cntrs <= ACKcntr;
1653 when x"9" => Cntrs <= RxEventCntr;
1654 when x"a" => Cntrs <= RdEventCntr;
1655 when x"b" => Cntrs <= DataAbortCntr;
1656 when x"c" => Cntrs <= CntrAbortCntr;
1657 when x"d" => Cntrs <= ACKNUM_fullAbortCntr;
1658 when x"e" => Cntrs <= EventBuf_fullAbortCntr;
1659 when others => Cntrs <= EventInfo_fullAbortCntr;
1662 case CntrBuf2_wa(3 downto 0) is
1663 when x"0" => Cntrs <= SEQAbortCntr;
1664 when x"1" => Cntrs <= CRCAbortCntr;
1665 when x"2" => Cntrs <= frameAbortCntr;
1666 when x"3" => Cntrs <= bad_KAbortCntr;
1667 when x"4" => Cntrs <= BUSYCntr;
1668 when x"5" => Cntrs <= EvtEVNmmCntr;
1669 when x"6" => Cntrs <= EvtBCNmmCntr;
1670 when x"7" => Cntrs <= EvtOCNmmCntr;
1671 when x"8" => Cntrs <= bad_EventLengthCntr;
1672 when x"9" => Cntrs <= BlockCntr;
-- we_EventInfo count
1673 when x"a" => Cntrs <= TTSCntr;
-- IS_TTS count
1674 when x"b" => Cntrs <= TTCCntr;
-- TTC_DataValid count
1675 when x"c" => Cntrs <= badCRCCntr;
-- bad AMC event CRC count
1676 when x"d" => Cntrs <= TTS_ERR_cntr;
-- TTC_DataValid count
1677 when x"e" => Cntrs <= TTS_SL_cntr;
-- bad AMC event CRC count
1678 when others => Cntrs <= TTS_DC_cntr;
1681 CntrBuf2_SPO_q <= CntrBuf2_SPO;
1682 if(resetCntrCycle = '1')then
1683 CntrBuf2_Di(15 downto 7) <= (others => '0');
1684 elsif(Cntrs < CntrBuf2_SPO_q(6 downto 0))then
1685 CntrBuf2_Di(15 downto 7) <= CntrBuf2_SPO_q(15 downto 7) + 1;
1687 CntrBuf2_Di(15 downto 7) <= CntrBuf2_SPO_q(15 downto 7);
1689 if(resetCntrCycle = '1')then
1690 CntrBuf2_Di(6 downto 0) <= (others => '0');
1692 CntrBuf2_Di(6 downto 0) <= Cntrs;
1696 process(sysclk,resetCntr)
1698 if(resetCntr = '1')then
1699 WordCntr <= (others => '0');
1700 WordCntr_q <= (others => '0');
1701 elsif(sysclk'event and sysclk = '1')then
1702 if(AMC_DATA_RdEn = '1')then
1703 WordCntr <= WordCntr + 1;
1705 if(Cntr_RdEn = '0' or Cntr_ra(8 downto 7) /= "10")then
1706 WordCntr_q <= WordCntr;
1710 process(sysclk,InitLink)
1712 if(InitLink = '1')then
1713 EventInfoRdDoneToggle <= '0';
1714 EventInfo_dav_i <= '0';
1715 EventInfoToggleSyncRegs <= (others => '0');
1716 L1Ainfo_wa <= (others => '0');
1717 elsif(sysclk'event and sysclk = '1')then
1719 EventInfoRdDoneToggle <= '0';
1720 EventInfo_dav_i <= '0';
1721 EventInfoToggleSyncRegs <= (others => '0');
1722 L1Ainfo_wa <= (others => '0');
1724 if(EventInfoRdDone = '1')then
1725 EventInfoRdDoneToggle <= not EventInfoRdDoneToggle;
1727 if(AMC_en = '0' or EventInfoRdDone = '1')then
1728 EventInfo_dav_i <= '0';
1729 elsif(EventInfoToggleSyncRegs(3) /= EventInfoToggleSyncRegs(2))then
1730 EventInfo_dav_i <= '1';
1732 EventInfoToggleSyncRegs <= EventInfoToggleSyncRegs(2 downto 0) & EventInfoToggle;
1733 if(L1A_WrEn = '1' and AMC_en = '1')then
1734 L1Ainfo_wa <= L1Ainfo_wa + 1;
1739 i_L1Ainfo : BRAM_SDP_MACRO
1741 BRAM_SIZE =>
"18Kb",
-- Target BRAM, "18Kb" or "36Kb"
1742 DEVICE =>
"7SERIES",
-- Target device: "VIRTEX5",
"VIRTEX6",
"7SERIES",
"SPARTAN6"
1743 WRITE_WIDTH =>
16,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
1744 READ_WIDTH =>
16,
-- Valid values are 1-72 (37-72 only valid when BRAM_SIZE="36Kb")
1745 DO_REG =>
1,
-- Optional output register (0 or 1)
1746 SIM_COLLISION_CHECK =>
"NONE",
-- Collision check enable "ALL",
"WARNING_ONLY",
1747 -- "GENERATE_X_ONLY" or "NONE"
1748 WRITE_MODE =>
"WRITE_FIRST",
-- Specify "READ_FIRST" for same clock
or synchronous clocks
1749 -- Specify "WRITE_FIRST for asynchrononous clocks on ports
1750 INIT => X"000000000000000000"
) -- Initial values on output port
1752 DO => L1AinfoDo,
-- Output read data port, width defined by READ_WIDTH parameter
1753 DI => L1A_DATA,
-- Input write data port, width defined by WRITE_WIDTH parameter
1754 RDADDR => L1Ainfo_ra,
-- Input read address, width defined by read port depth
1755 RDCLK => UsrClk,
-- 1-bit input read clock
1756 RDEN => re_L1AinfoDo,
-- 1-bit input read port enable
1757 REGCE => re_L1AinfoDo,
-- 1-bit input read output register enable
1758 RST => '0',
-- 1-bit input reset
1759 WE => "
11",
-- Input write enable, width defined by write port depth
1760 WRADDR => L1Ainfo_wa,
-- Input write address, width defined by write port depth
1761 WRCLK => sysclk,
-- 1-bit input write clock
1762 WREN => L1A_WrEn
-- 1-bit input write port enable
1764 re_L1AinfoDo <= not SendTTS;
1765 g_ReSendQueue : for i in 0 to 15 generate
1766 i_ReSendQueue : SRL16E
1768 Q => ReSendQueOut
(i
),
-- SRL data output
1769 A0 => ReSendQue_a
(0),
-- Select[0] input
1770 A1 => ReSendQue_a
(1),
-- Select[1] input
1771 A2 => '0',
-- Select[2] input
1772 A3 => '0',
-- Select[3] input
1773 CE => we_ReSendQue,
-- Clock enable input
1774 CLK => UsrClk,
-- Clock input
1775 D => ReSendQueIn
(i
) -- SRL data input
1778 ReSendQueIn <= SEQNUM & L1Ainfo_start;
1782 if(UsrClk'event and UsrClk = '1')then
1783 if(InitLink = '1')then
1784 L1Ainfo_ra <= (others => '0');
1785 elsif(ReSend = '1')then
1786 L1Ainfo_ra <= ReSendQueOut(7 downto 0) & "00";
1787 elsif(ec_L1Ainfo_ra = '1' and SendTTS = '0')then
1788 L1Ainfo_ra <= L1Ainfo_ra + 1;
1790 if(InitLink = '1')then
1791 L1Ainfo_start <= (others => '0');
1792 elsif(ReSend = '1')then
1793 L1Ainfo_start <= ReSendQueOut(7 downto 0);
1794 elsif(we_ReSendQue = '1')then
1795 L1Ainfo_start <= L1Ainfo_ra(9 downto 2);
1797 if(InitLink = '1')then
1798 L1Ainfo_wa2SyncRegs <= (others => '0');
1800 L1Ainfo_wa2SyncRegs <= L1Ainfo_wa2SyncRegs(2 downto 0) & L1Ainfo_wa(2);
1802 if(InitLink = '1')then
1803 L1Ainfo_wap <= (others => '0');
1804 elsif(L1Ainfo_wa2SyncRegs(3) /= L1Ainfo_wa2SyncRegs(2))then
1805 L1Ainfo_wap <= L1Ainfo_wap + 1;
1807 if(InitLink = '1' or L1Ainfo_wap = L1Ainfo_ra(9 downto 2))then
1808 L1Ainfo_empty <= '1';
1810 L1Ainfo_empty <= '0';
1812 if(reset_SyncRegs(3) = '1')then
1814 elsif(ACK = '1' or test = '1')then
1817 if(reset_SyncRegs(3) = '1' or ReSend = '1')then
1818 ReSendQue_a <= (others => '1');
1819 elsif(we_ReSendQue = '1' and ACK = '0')then
1820 ReSendQue_a <= ReSendQue_a + 1;
1821 elsif(we_ReSendQue = '0' and ACK = '1' and ReSendQue_a /= "11")then
1822 ReSendQue_a <= ReSendQue_a - 1;
1824 if(TxState = SendWC and Resend = '0'and SendTTS = '0' and (L1ASent = '1' or InitLink = '1'))then
1825 we_ReSendQue <= '1';
1827 we_ReSendQue <= '0';
1829 if(ReSendQue_a = "10")then
1830 ReSendQue_full <= '1';
1832 ReSendQue_full <= '0';
1834 if(reset_SyncRegs(3) = '1' or ReSend = '1')then
1835 ReSendQue_empty <= '1';
1836 elsif(we_ReSendQue = '1')then
1837 ReSendQue_empty <= '0';
1838 elsif(ACK = '1' and ReSendQue_a = "00")then
1839 ReSendQue_empty <= '1';
1841 if(InitLink = '1')then
1843 elsif(ReSend = '1')then
1844 SEQNUM <= ReSendQueOut(15 downto 8);
1845 elsif(we_ReSendQue = '1')then
1846 SEQNUM <= SEQNUM(6 downto 0) & not(SEQNUM(7) xor SEQNUM(5) xor SEQNUM(4) xor SEQNUM(3));
1848 if(reset_SyncRegs(3) = '1')then
1850 elsif(RXCHARISCOMMA = "11")then
1853 if(AMCRdy = '0' or reset_SyncRegs(3) = '1' or ReSend = '1')then
1855 ec_L1Ainfo_ra <= '0';
1856 elsif(SendTTS = '0')then
1858 when IDLE => -- send R_word (idle)
1860 ec_L1Ainfo_ra <= '0';
1861 when SendK => -- send K_word
1862 if((ReSend_l = '1' and InitLink = '1') or (ReSendQue_full = '0' and L1Ainfo_empty = '0' and InitLink = '0') or ACKNUM_empty = '0' or GotCntr = '1')then
1867 if(InitLink = '1')then
1871 elsif(GotCntr = '1')then
1875 elsif(ReSendQue_full = '0' and L1Ainfo_empty = '0')then
1877 ec_L1Ainfo_ra <= '1';
1883 TxType <= Acknowledge;
1885 when SendSEQ => -- send packet type
1886 TxState <= SendType;
1888 ACKNUM_MUX <= CntrACKNUM;
1890 ACKNUM_MUX <= ACKNUM_l;
1892 when SendType => -- send packet_seq
1893 if(L1Asent = '0')then
1896 TxState <= SendData;
1898 when SendWC => -- send packet_wc
1900 when WaitCRC => -- wait for CRC
1902 when SendData => -- send L1A info
1903 if(packet_wc = "11")then
1906 if(packet_wc = "01")then
1907 ec_L1Ainfo_ra <= '0';
1909 when others => TxState <= IDLE;
1912 if(TxState = SendK)then
1913 packet_wc <= (others => '0');
1914 elsif(TxState = SendData and SendTTS = '0')then
1915 packet_wc(1) <= packet_wc(1) xor packet_wc(0);
1916 packet_wc(0) <= not packet_wc(0);
1918 if(is_TTS = '1' or TTS_wait(7) = '1' or (InitLink = '1' and ACK = '1'))then
1923 if(SendTTS = '1')then
1924 TXDATA_i <= TTS & x"5c";
1929 when SendK => TXDATA_i <= K_word;
1930 when SendData => TXDATA_i <= L1AinfoDo;
1931 when SendSEQ => TXDATA_i <= SEQNUM & TxType;
1932 when SendType => TXDATA_i <= ACKNUM_MUX & x"0" & AMC_IDp1;
1933 when SendWC => TXDATA_i <= x"000" & '0' & L1Asent & "00";
1934 when SendCRC => TXDATA_i <= TxCRC;
1935 when others => TXDATA_i <= R_word;
1938 when IDLE | SendK | WaitCRC => TxIsK <= '1';
1940 when others => TxIsK <= '0';
1944 if(TxState = IDLE or TxState = SendK)then
1953 init_crc => Init_TxCRC,
1958 we_TxCRC <= not TxIsK;