1 ------------------------------------------------------------------------ 3 -- b2tt_decode.vhd -- TT-link decoder for Belle2link frontend 5 -- Mikihiko Nakao, KEK IPNS 7 -- 20120325 first version 8 -- 20120528 fixes based on c-model 9 -- 20120603 restructured 10 -- 20131002 many changes, b2tt_iddr separated out 11 -- 20131012 unifying with v6 code 12 -- 20131101 no more std_logic_arith 13 -- 20131126 tagerr fix (debug with c-model) 14 -- 20140102 ini.value of detag:buf_cnttrg / detrig:cnt_trig to -1 15 -- 20141128 address setting 18 -- 20150207 no tagerr if masked 19 -- 20150319 clraddr, runreset, longer stareset 20 -- 20150526 tagset/tagin (tested with ft3f) 21 -- 20150528 divclk1 fix (divclk2 was forgotten) 22 -- 20150614 clkfreq to 24-bit, running, longer frame3/frame9 23 -- (but reverted back to 20150319) 24 -- 20150718 fix revert of 20150319 25 -- 20150722 cnt_trig is one clock delayed to relax timing constraint 26 -- 20160315 trgmask when masked in the upstream 27 -- 20160407 trgmask undefined initial value fix 28 -- 20160627 no more sig_triginc 29 -- 20160831 regsel (cmd 8) 30 -- 20170713 regsel at cmd 7, usrreg, rstmask 31 -- 20170724 semreset at RST bit 32 33 -- eout bit 9 is first transmitted, bit 0 is last transmitted 34 -- ein bit 9 is first received, bit 0 is last received 37 -- bit2 2-bit input at every clock 38 -- bit10 10-bit input before 8b10b 39 -- octet/isk 8-bit decoded data and flag for K-character 40 -- packet 16-octet container starting with a comma 41 -- payload 77-bit data inserted in a packet 42 -- frame 16-packet container synchronized to beam revolution 46 -- 0 to 4 incremented every clock to make an octet to 8b10b 47 -- 5 octet boundary is not found or found at wrong place 48 -- When a comma is found at a wrong place, "newcomma" is 49 -- asserted. When another comma is found when cntbit2 is 5, 50 -- cntbit2 cycle immediately goes into 0 to 4 cycle. 52 -- 0 to 15 incremented every 5 clocks to make a packet (16 octet) 53 -- 16 packet boundary is found with alternative comma 54 -- 17 packet boundary is not found or found at wrong place 55 -- When a packet boundary is found at a wrong place, 56 -- "newframe" is asserted. When another comma is found 57 -- when cntbit2 is 5, cntbit2 cycle immediately goes into 61 -- 0 to 15 incremented every 16 octet to make a frame 62 -- 16 reset because of incorrect octet/packet 63 -- 17 to 255 link yet to be established, incremented until round 66 ------------------------------------------------------------------------ 68 ------------------------------------------------------------------------ 70 ------------------------------------------------------------------------ 72 use ieee.std_logic_1164.
all;
73 use ieee.std_logic_unsigned.
all;
74 use ieee.numeric_std.
all;
81 bit2 : in (1 downto 0);
82 prev8 : in (7 downto 0);
83 cntbit2 : in (2 downto 0);
87 ------------------------------------------------------------------------ 89 signal sig_bit10 : (9 downto 0) := "0000000000";
90 signal sig_comma : := '0';
93 sig_bit10 <= prev8 & bit2 when ckup = '1' else (others => '0');
95 -- comma detection (before clock cycle) 97 sig_bit10 = K28_5P or sig_bit10 = K28_5N or 98 sig_bit10 = K28_1P or sig_bit10 = K28_1N else '0';
100 -- misaligned comma detection (before clock cycle) 102 newcomma <= '1' when sig_comma = '1' and 103 cntbit2 /= 0 and cntbit2 /= 5 else '0';
107 ------------------------------------------------------------------------ 109 ------------------------------------------------------------------------ 111 use ieee.std_logic_1164.
all;
112 use ieee.std_logic_unsigned.
all;
113 use ieee.numeric_std.
all;
124 bit2 : in (1 downto 0);
125 bit10 : out (9 downto 0);
126 cntbit2 : out (2 downto 0);
-- 0 to 4 129 ------------------------------------------------------------------------ 132 signal buf_slip10 : (9 downto 0) := "0000000000";
133 signal buf_slip : := '0';
134 signal buf_bit10 : (9 downto 0) := "0000000000";
136 signal cnt_bit2 : (2 downto 0) := "101";
139 proc:
process (clock)
141 if clock'event and clock = '1' then 143 -- search for a shifted comma charactor for bit slip 145 buf_slip10 = K28_5P or buf_slip10 = K28_5N or 146 buf_slip10 = K28_1P or buf_slip10 = K28_1N then 147 buf_slip10 <= (others => '0');
151 buf_slip10 <= buf_slip10(7 downto 0) & buf_slip & bit2(1);
156 -- decode counter to align octet boundary (==5 when not aligned) 157 if ckup = '0' or nocomma = '1' or newcomma = '1' then 158 cnt_bit2 <= "101";
-- 5 159 --elsif newcomma = '1' then 160 -- cnt_bit2 <= "101"; -- 5 161 elsif comma = '1' then 162 cnt_bit2 <= "001";
-- 1 163 elsif cnt_bit2 = 4 then 164 cnt_bit2 <= "000";
-- 0 165 elsif cnt_bit2 /= 5 then 166 cnt_bit2 <= cnt_bit2 + 1;
171 buf_bit10 <= buf_bit10(7 downto 0) & bit2;
173 buf_bit10 <= (others => '0');
183 ------------------------------------------------------------------------ 185 ------------------------------------------------------------------------ 187 use ieee.std_logic_1164.
all;
188 use ieee.std_logic_unsigned.
all;
189 use ieee.numeric_std.
all;
196 cntbit2 : in (2 downto 0);
197 bit2 : in (1 downto 0);
198 bit10 : in (9 downto 0);
199 octet : out (7 downto 0);
-- out/async 200 isk : out );
-- out/async 202 ------------------------------------------------------------------------ 205 signal sig_10b : (9 downto 0) := "0000000000";
206 signal sig_en : := '0';
207 signal sig_isk : := '0';
208 signal buf_isk : := '0';
209 signal sig_8b : (7 downto 0) := x"00";
210 signal buf_8b : (7 downto 0) := x"00";
212 signal open_err : (4 downto 0) := (others => '0');
213 signal open_rdp : := '0';
217 sig_10b <= bit10(7 downto 0) & bit2;
218 sig_en <= '1' when cntbit2 = 4 else '0';
220 -- almost async (except for rdp) 222 port map ( reset => '0',
228 err => open_err,
-- out 229 rdp => open_rdp
);
-- out 232 octet <= sig_8b when cntbit2 = 0 or cntbit2 = 5 else buf_8b;
233 isk <= sig_isk when cntbit2 = 0 or cntbit2 = 5 else buf_isk;
235 proc:
process (clock)
237 if clock'event and clock = '1' then 238 if cntbit2 = 0 or cntbit2 = 5 then 246 ------------------------------------------------------------------------ 248 ------------------------------------------------------------------------ 250 use ieee.std_logic_1164.
all;
251 use ieee.std_logic_unsigned.
all;
252 use ieee.numeric_std.
all;
262 cntbit2 : in (2 downto 0);
263 octet : in (7 downto 0);
266 tagin : in (31 downto 0);
267 jtag : out (2 downto 0);
268 jtagdbg : out (9 downto 0);
270 trgtyp : out (3 downto 0);
271 trgtag : out (31 downto 0);
274 ------------------------------------------------------------------------ 276 signal sta_en : := '0';
277 signal sig_trgoctet : := '0';
278 signal sig_trgout : := '0';
279 signal sig_trgtim : (2 downto 0) := "111";
280 signal buf_trgtim : (2 downto 0) := "111";
281 signal cnt_trginterval : (4 downto 0) := "11000";
-- 24 282 signal cnt_trig : (31 downto 0) := (others => '1');
283 signal cnt_delta : (7 downto 0) := (others => '0');
284 --signal sig_triginc : std_logic := '0'; 286 signal seq_tck : (3 downto 0) := "0000";
287 signal sig_tck : := '0';
288 signal sig_tms : := '0';
289 signal sig_tdi : := '0';
293 sta_en <= ttup and (not mask);
294 sig_trgtim <= octet(6 downto 4);
295 sig_trgoctet <= octet(7) and (not isk) when cntbit2 = 1 else '0';
296 sig_tck <= (sta_en and isk) when octet(7 downto 4) = "1111" and 297 octet(1 downto 0) /= 0 and 300 sig_tms <= sig_tck and octet(3) and octet(2) and (octet(1) xor octet(0));
301 sig_tdi <= sig_tck and octet(3) and octet(1) and (octet(2) xor octet(0));
304 jtagdbg(8 downto 4) <= cnt_trginterval;
305 jtagdbg(3) <= seq_tck(3);
306 jtagdbg(2) <= sig_tck;
307 jtagdbg(1) <= sig_tms;
308 jtagdbg(0) <= sig_tdi;
310 proc:
process (clock)
312 if clock'event and clock = '1' then 313 if (sig_trgout = '1' or sig_tck = '1') and cnt_trginterval + 1 >= 24 then 314 cnt_trginterval <= "00001";
315 elsif cnt_trginterval < 23 then 316 cnt_trginterval <= cnt_trginterval + 1;
319 -- search for trigger octet 320 -- sig_trgout: time-recovered trigger signal 321 -- buf_trgtim: for delayed trigger generation 322 -- trgshort: trigger comes in a too short interval (held until reset) 325 if sta_en = '0' or runreset = '1' then 327 elsif (sig_trgoctet = '1' or sig_tck = '1') and 328 cnt_trginterval + sig_trgtim < 24 then 333 jtag(2) <= seq_tck(3);
334 seq_tck(3 downto 1) <= seq_tck(2 downto 0);
335 if sig_tck = '1' then 336 jtag(1 downto 0) <= sig_tms & sig_tdi;
338 if sig_tck = '1' and cnt_trginterval + 1 >= 24 then 340 elsif cnt_trginterval >= 16 then 345 if sta_en = '0' or runreset = '1' then 347 elsif sig_trgoctet = '1' and sig_trgtim = 1 then 348 if cnt_trginterval + 1 >= 24 then 353 elsif cntbit2 = buf_trgtim then 359 -- cnt_trig / cnt_delta (without sig_triginc) 360 if sta_en = '0' or runreset = '1' then 361 cnt_trig <= (others => '1');
362 cnt_delta <= (others => '0');
363 elsif tagset = '1' then 364 -- tagset is issued twice when mask is released, 365 -- to properly include cnt_delta 366 cnt_trig <= tagin + (x"000000" & cnt_delta);
367 elsif sig_trgoctet = '1' and sig_trgtim = 1 then 368 if cnt_trginterval + 1 >= 24 then 369 cnt_trig <= cnt_trig + 1;
370 cnt_delta <= cnt_delta + 1;
372 elsif cntbit2 = buf_trgtim then 373 cnt_trig <= cnt_trig + 1;
374 cnt_delta <= cnt_delta + 1;
378 if sta_en = '0' or runreset = '1' then 380 elsif cntbit2 = 1 and sig_trgoctet = '1' then 381 trgtyp <= octet(3 downto 0);
385 if sta_en = '0' or runreset = '1' then 387 elsif sig_trgoctet = '1' then 388 if sig_trgtim <= 1 or sig_trgtim > 5 then 389 buf_trgtim <= "111";
-- 1: immediate trgout, 0,6,7: invalid 390 elsif sig_trgtim = 5 then 391 buf_trgtim <= "000";
-- 5: wrap-around to 0 393 buf_trgtim <= sig_trgtim;
-- 2,3,4: as it is 395 elsif cntbit2 = 0 then 403 trgout <= sig_trgout;
407 ------------------------------------------------------------------------ 409 ------------------------------------------------------------------------ 411 use ieee.std_logic_1164.
all;
412 use ieee.std_logic_unsigned.
all;
413 use ieee.numeric_std.
all;
420 cntbit2 : in (2 downto 0);
421 octet : in (7 downto 0);
429 cntlinkrst : out (7 downto 0);
430 payload : out (76 downto 0);
431 cntoctet : out (4 downto 0);
432 cntdato : out (3 downto 0);
433 rxerr : out (5 downto 0);
434 crcdbg : out (8 downto 0) );
436 ------------------------------------------------------------------------ 438 signal cnt_octet : (4 downto 0) := "00000";
439 signal sta_octet : := '0';
440 signal seq_octet : := '0';
441 signal cnt_invalid : (11 downto 0) := x"000";
442 signal cnt_incdelay : (7 downto 0) := x"00";
444 signal sig_datoctet : := '0';
445 signal cnt_datoctet : (3 downto 0) := (others => '0');
446 signal buf_payload : (76 downto 0) := (others => '0');
448 signal sig_rxerr : (5 downto 0) := (others => '0');
450 signal sta_crc8 : (7 downto 0) := x"00";
451 signal sta_crc8ok : := '0';
453 -- from crc8.vhd and comlib.vhd of 454 -- http://opencores.org/project,w11 455 -- 0x4d (x8 + x6 + x3 + x2 + 1) [ shr 1 makes 0xa6 ] 456 subtype byte_t is (7 downto 0);
458 ( crc:
in byte_t; data:
in byte_t )
return byte_t is 459 variable t : byte_t := (others => '0');
460 variable n : byte_t := (others => '0');
463 n(0) := t(5) xor t(4) xor t(2) xor t(0);
464 n(1) := t(6) xor t(5) xor t(3) xor t(1);
465 n(2) := t(7) xor t(6) xor t(5) xor t(0);
466 n(3) := t(7) xor t(6) xor t(5) xor t(4) xor t(2) xor t(1) xor t(0);
467 n(4) := t(7) xor t(6) xor t(5) xor t(3) xor t(2) xor t(1);
468 n(5) := t(7) xor t(6) xor t(4) xor t(3) xor t(2);
469 n(6) := t(7) xor t(3) xor t(2) xor t(0);
470 n(7) := t(4) xor t(3) xor t(1);
472 end function crc8_update;
476 sig_datoctet <= (not octet(7)) and (not isk);
478 proc:
process (clock)
480 if clock'event and clock = '1' then 482 seq_octet <= sta_octet;
483 if seq_octet = '1' and sta_octet = '0' then 489 -- check invalid packet 490 -- - cnt_invalid: number of invalid octet 491 -- - sig_indelay: signal to increment delay 492 if cnt_invalid(cnt_invalid'left) = '1' then 493 cnt_invalid <= (others => '0');
494 incdelay <= '1';
-- out 495 cnt_incdelay <= cnt_incdelay + 1;
497 if sta_octet = '0' then 498 cnt_invalid <= cnt_invalid + 1;
500 incdelay <= '0';
-- out 503 -- search for a packet boundary 504 -- - cnt_octet: to align octet to packet boundary 505 -- - sta_octet: octet is aligned to packet boundary 507 if sta_octet = '1' then 511 cnt_octet <= "11111";
514 elsif cntbit2 = 1 then 515 -- and all the octets are checked only at cntbit2 = 1 (2?) 517 if cnt_octet = 15 or cnt_octet = 31 then 518 sta_crc8 <= crc8_update(x"00", octet);
520 elsif cnt_octet = 14 and octet(7) = '0' and isk = '0' and 521 sta_crc8(6 downto 0) /= octet(6 downto 0) then 524 sta_crc8 <= crc8_update(sta_crc8, octet);
527 if isk = '1' and octet = K28_1 then 528 -- valid comma if cnt_octet = 15 529 if cnt_octet = 15 or cnt_octet = 31 then 531 cnt_octet <= "00000";
534 cnt_octet <= "10000";
537 elsif isk = '1' and octet = K28_5 then 538 -- valid alternative comma if cnt_octet = 16 539 if cnt_octet = 16 then 541 cnt_octet <= "00001";
545 cnt_octet <= "10001";
548 elsif (cnt_datoctet = 0 or cnt_datoctet = 11) and 549 isk = '1' and octet = K28_3 then 551 cnt_octet <= cnt_octet + 1;
553 ((not octet(7 downto 4)) /= 0 or octet(1 downto 0) = 0) then 555 -- invalid K symbol (none of comma, acomma, idle, jtag) 557 -- valid jtag symbols are (tms,tdi) 558 -- 00 => K23.7 1111 0111 559 -- 01 => K27.7 1111 1011 560 -- 10 => K29.7 1111 1101 561 -- 11 => K30.7 1111 1110 564 cnt_octet <= "11111";
566 elsif octet(7) = '0' and (cnt_octet = 14 or cnt_octet = 30) then 567 -- valid data or crc8 568 cnt_octet <= cnt_octet + 1;
569 elsif cnt_datoctet = 11 and octet(7) = '0' then 570 -- invalid (too long) data payload 572 cnt_octet <= "11111";
574 elsif cnt_octet = 15 and octet(7) = '1' then 575 -- valid trigger octet at the beginning of packet 576 cnt_octet <= "10000";
577 elsif cnt_octet < 15 then 578 -- valid data or trigger octet 579 cnt_octet <= cnt_octet + 1;
581 -- invalid data payload 583 cnt_octet <= "00000";
587 sig_rxerr <= (others => '0');
590 -- payload reconstruction 592 buf_payload <= (others => '0');
593 cnt_datoctet <= (others => '0');
594 elsif cntbit2 = 2 then 595 if cnt_octet = 0 or cnt_octet(4) = '1' then 596 buf_payload <= (others => '0');
597 cnt_datoctet <= (others => '0');
598 elsif cnt_octet = 15 and 599 cnt_datoctet = 0 and sig_datoctet = '1' then 600 -- do not increment cnt_datoctet for crc8 octet 601 elsif cnt_datoctet < 11 and sig_datoctet = '1' then 602 buf_payload <= buf_payload(7*10-1 downto 0) & octet(6 downto 0);
603 cnt_datoctet <= cnt_datoctet + 1;
607 -- sig_payload and sig_idle 608 if cntbit2 = 3 and cnt_octet = 15 then 609 if cnt_datoctet = 11 then 610 sigpayload <= '1';
-- out 611 payload <= buf_payload;
613 if cnt_datoctet = 0 then 614 sigidle <= '1';
-- out 617 sigpayload <= '0';
-- out 618 sigidle <= '0';
-- out 625 cntoctet <= cnt_octet;
626 cntdato <= cnt_datoctet;
628 staoctet <= sta_octet;
629 stacrc8ok <= sta_crc8ok;
630 cntlinkrst <= cnt_incdelay;
631 crcdbg <= sta_crc8ok & sta_crc8;
634 ------------------------------------------------------------------------ 636 ------------------------------------------------------------------------ 638 use ieee.std_logic_1164.
all;
639 use ieee.std_logic_unsigned.
all;
640 use ieee.numeric_std.
all;
648 CLKDIV1 : range 0 to 72;
649 CLKDIV2 : range 0 to 72;
650 DEFADDR : (19 downto 0) := x"00000";
651 SIM_SPEEDUP : := '0' );
654 staiddr : in (1 downto 0);
658 payload : in (76 downto 0);
659 regsel :
out (
4 downto 0);
660 usrreg : out (7 downto 0);
663 myaddr : out (19 downto 0);
667 divclk1 : out (1 downto 0);
668 divclk2 : out (1 downto 0);
669 cntpacket : out (7 downto 0);
670 utime : out (31 downto 0);
671 ctime : out (26 downto 0);
672 clkfreq : out (23 downto 0);
673 frameloc : out (10 downto 0);
675 errreset : out ;
-- only inside b2tt 676 bsyreset : out ;
-- only inside b2tt 677 semreset : out ;
-- only inside b2tt 687 dismask : out ;
-- only for FTSW, not for FEE 690 --timerr0 : out std_logic_vector (26 downto 0); 691 --timerr1 : out std_logic_vector (26 downto 0); 692 --timerr2 : out std_logic_vector (31 downto 0); 693 --timerr3 : out std_logic_vector (31 downto 0); 694 sigerr : out (2 downto 0) );
697 ------------------------------------------------------------------------ 699 signal sta_ttup : := '0';
700 signal cnt_packet : (7 downto 0) := (others => '0');
701 signal buf_bcast : := '0';
702 signal buf_ttpkt : (11 downto 0) := (others => '0');
703 signal buf_bdata : (63 downto 0) := (others => '0');
704 signal buf_adata : (43 downto 0) := (others => '0');
705 signal buf_addr : (19 downto 0) := (others => '0');
706 signal sig_frame : := '0';
707 signal sig_frame3 : := '0';
708 signal sig_frame9 : := '0';
709 signal sta_dismask : := '0';
710 signal buf_utime : (31 downto 0) := (others => '0');
711 signal buf_ctime : (26 downto 0) := (others => '0');
712 signal buf_clkfreq : (23 downto 0) := x"952980";
713 signal cnt_utime : (31 downto 0) := (others => '0');
714 signal cnt_ctime : (26 downto 0) := (others => '0');
715 signal cnt_timer : (3 downto 0) := "0000";
716 signal cnt_frameloc : (10 downto 0) := "10100000000";
717 signal sig_runreset : := '0';
718 signal sig_errreset : := '0';
719 signal sta_running : := '0';
720 signal cnt_divseq1 : (6 downto 0) := (others => '0');
721 signal cnt_divseq2 : (6 downto 0) := (others => '0');
722 signal buf_myaddr : (19 downto 0) := DEFADDR;
723 signal buf_cmd : (7 downto 0) := (others => '0');
724 signal reg_clkfreq : (26 downto 0) := "111" & x"95297f";
725 signal seq_runreset : := '0';
726 signal sig_payload : := '0';
727 signal sta_trgmask : := '0';
728 signal buf_trgmask : := '0';
729 signal sta_rstmask : := '0';
730 signal buf_rstmask : := '0';
731 signal sta_notagerr : := '0';
732 signal buf_notagerr : := '0';
733 signal sta_badver : := '0';
735 -- code below means CNTLIMIT := x"1f" when SIM_SPEEDUP = '1' else x"ff"; 736 constant CNTLIMIT : (7 downto 0) := 737 (not SIM_SPEEDUP) & (not SIM_SPEEDUP) & (not SIM_SPEEDUP) & "11111";
739 --signal buf_timerr : std_logic := '0'; 742 buf_bcast <= payload(76);
743 buf_ttpkt <= payload(75 downto 64);
744 buf_bdata <= payload(63 downto 0);
745 buf_adata <= payload(43 downto 0);
746 buf_addr <= payload(63 downto 44);
747 buf_cmd <= payload(43 downto 36);
748 reg_clkfreq <= ("
111" & buf_clkfreq) -
1;
749 sig_payload <= sigpayload and sta_ttup;
751 proc:
process (clock)
753 if clock'event and clock = '1' then 755 -- check valid payload 756 if staoctet = '0' or staiddr /= 3 then 757 cnt_packet <= "00010000";
760 elsif sigidle = '1' and cnt_packet /= CNTLIMIT then 761 cnt_packet <= cnt_packet + 1;
762 elsif sigpayload = '1' then 763 if buf_bcast = '1' and buf_ttpkt = TTPKT_SYNC then 764 if cnt_packet = 15 or cnt_packet = CNTLIMIT then 765 cnt_packet <= (others => '0');
768 elsif cnt_packet(3 downto 0) = 15 then 769 cnt_packet <= cnt_packet + 1;
773 cnt_packet <= "00010000";
777 elsif cnt_packet /= CNTLIMIT then 778 cnt_packet <= cnt_packet + 1;
783 if sig_payload = '1' and buf_ttpkt = TTPKT_RST and 784 buf_adata(38) = '1' and (buf_myaddr = 0 or buf_addr = 0) then 785 buf_myaddr <= buf_addr;
787 elsif sig_payload = '1' and buf_ttpkt = TTPKT_RST and 788 buf_adata(35) = '1' then 789 buf_myaddr <= (others => '0');
796 if sig_payload = '1' and buf_ttpkt = TTPKT_FREQ then 797 -- version in buf_adata(33 downto 24) of TTPKT_FREQ 798 if buf_adata(33 downto 24) = PROTOCOL or 799 buf_adata(33 downto 24) = COMPAT then 804 buf_clkfreq <= buf_adata(23 downto 0);
807 -- feereset, gtpreset 808 if sig_payload = '1' and buf_ttpkt = TTPKT_RST and 809 (buf_bcast = '1' or buf_addr = buf_myaddr) then 810 feereset <= buf_adata(43);
811 b2lreset <= buf_adata(42);
812 gtpreset <= buf_adata(41);
813 incdelay <= buf_adata(40);
814 caldelay <= buf_adata(39);
815 sig_errreset <= buf_adata(36);
816 sta_running <= buf_adata(34);
817 bsyreset <= buf_adata(33);
818 semreset <= buf_adata(32);
830 -- entagerr (don't care bcast or myaddr) 831 if sig_payload = '1' and buf_ttpkt = TTPKT_RST then 832 entagerr <= buf_adata(37) and (not sta_notagerr);
834 seq_runreset <= sig_runreset;
836 -- sig_runreset, sig_frame, sig_frame3, sig_frame9 837 if sig_payload = '1' and buf_bcast = '1' and buf_ttpkt = TTPKT_SYNC and 838 (cnt_packet = 15 or cnt_packet = CNTLIMIT) then 839 sig_runreset <= buf_bdata(63);
841 sig_frame3 <= buf_bdata(62);
842 sig_frame9 <= buf_bdata(61);
843 sta_dismask <= buf_bdata(59);
846 -- runreset, frame3, frame9 are not a single clock pulse 847 --sig_runreset <= '0'; 853 if (sig_payload = '1' and buf_bcast = '1' and buf_ttpkt = TTPKT_SYNC and 854 buf_bdata(61) = '1' and cnt_packet(3 downto 0) = 15) or 856 cnt_divseq1 <= (to_unsigned(CLKDIV1 - 1, 7));
859 elsif CLKDIV1 = 1 then 865 if cnt_divseq1 <= (CLKDIV1 + 0) / 2 then 868 if cnt_divseq1 <= (CLKDIV1 + 1) / 2 then 872 cnt_divseq1 <= cnt_divseq1 - 1;
876 if (sig_payload = '1' and buf_bcast = '1' and buf_ttpkt = TTPKT_SYNC and 877 buf_bdata(61) = '1' and cnt_packet(3 downto 0) = 15) or 879 cnt_divseq2 <= (to_unsigned(CLKDIV2 - 1, 7));
882 elsif CLKDIV2 = 1 then 888 if cnt_divseq2 <= (CLKDIV2 + 0) / 2 then 891 if cnt_divseq2 <= (CLKDIV2 + 1) / 2 then 895 cnt_divseq2 <= cnt_divseq2 - 1;
898 -- buf_utime, buf_ctime, cnt_timer 899 if sig_payload = '1' and buf_bcast = '1' and buf_ttpkt = TTPKT_SYNC and 900 (cnt_packet = 15 or cnt_packet = CNTLIMIT) then 901 buf_utime <= buf_bdata(58 downto 27);
902 buf_ctime <= buf_bdata(26 downto 0);
904 elsif cnt_timer /= 0 then 905 cnt_timer <= cnt_timer - 1;
908 -- cnt_utime, cnt_ctime 909 if cnt_timer = 2 then 910 cnt_utime <= buf_utime;
911 cnt_ctime <= buf_ctime;
912 elsif buf_utime /= 0 then 913 if cnt_ctime = reg_clkfreq then 914 cnt_utime <= cnt_utime + 1;
915 cnt_ctime <= (others => '0');
917 cnt_ctime <= cnt_ctime + 1;
922 if sig_runreset = '1' or sig_errreset = '1' then 925 elsif cnt_timer = 1 and 926 (cnt_utime /= buf_utime or cnt_ctime /= buf_ctime) then 929 --if buf_timerr = '0' then 930 -- timerr0 <= cnt_ctime; 931 -- timerr1 <= buf_ctime; 932 -- timerr2 <= cnt_utime; 933 -- timerr3 <= buf_utime; 938 if cnt_timer = 2 then 939 cnt_frameloc <= (others => '0');
940 elsif cnt_frameloc /= 1280 then 941 cnt_frameloc <= cnt_frameloc + 1;
945 -- use TTPKT_RST at cnt_packet = 3, which is circulated all the time 946 -- on the other hand, TTPKT_CMD at cnt_packet = 4 is circulated only 947 -- when there is a command. 949 -- 20170709 trgmask bit is moved from bit 0 to bit 20, and will not be 950 -- set in broadcast mode (clear only in broadcast mode) 951 if sigidle = '1' and cnt_packet = 3 then -- TTPKT_RST is masked 953 elsif sig_payload = '1' and buf_ttpkt = TTPKT_CMD then 954 if ((buf_bcast = '1' and payload(20) = '0') or buf_addr = buf_myaddr) and 956 sta_trgmask <= payload(20);
957 buf_trgmask <= payload(20);
958 sta_rstmask <= payload(21);
959 buf_rstmask <= payload(21);
960 sta_notagerr <= payload(22);
961 buf_notagerr <= payload(22);
963 sta_trgmask <= buf_trgmask;
964 sta_rstmask <= buf_rstmask;
965 sta_notagerr <= buf_notagerr;
970 if sig_runreset = '1' or sig_errreset = '1' then 971 regsel <= (
others => '0');
972 elsif sig_payload = '1' and buf_ttpkt = TTPKT_CMD and 973 (buf_bcast = '1' or buf_addr = buf_myaddr) and buf_cmd = x"07" then 974 regsel <= payload(
4 downto 0);
975 if payload(4 downto 0) = 1 then 976 usrreg <= payload(15 downto 8);
985 trgmask <= sta_trgmask;
986 rstmask <= sta_rstmask;
987 cntpacket <= cnt_packet;
988 clkfreq <= buf_clkfreq;
991 frameloc <= cnt_frameloc;
992 runreset <= sig_runreset and not sta_rstmask;
993 errreset <= sig_errreset and not sta_rstmask;
995 frame3 <= sig_frame3;
996 frame9 <= sig_frame9;
997 dismask <= (sta_running or sta_dismask) and sta_ttup;
998 running <= sta_running and sta_ttup;
999 myaddr <= buf_myaddr;
1000 badver <= sta_badver and sta_ttup;
1003 ------------------------------------------------------------------------ 1005 ------------------------------------------------------------------------ 1007 use ieee.std_logic_1164.
all;
1008 use ieee.std_logic_unsigned.
all;
1009 use ieee.numeric_std.
all;
1017 frameloc : in (10 downto 0);
1022 trgtag : in (31 downto 0);
1024 payload : in (76 downto 0);
1025 exprun : out (31 downto 0);
1027 tagin : out (31 downto 0);
1032 signal sig_bcast : := '0';
1033 signal buf_ttpkt : (11 downto 0) := (others => '0');
1034 signal buf_bdata : (63 downto 0) := (others => '0');
1035 signal buf_cnttrig : (31 downto 0) := (others => '1');
1036 signal buf_exprun : (31 downto 0) := x"87654321";
--dbg 1037 signal seq_mask : (1 downto 0) := "00";
1038 signal seq_tagerr : := '0';
1039 signal sta_tagerr : := '0';
1043 sig_bcast <= payload(76) and ttup and sigpayload;
1044 buf_ttpkt <= payload(75 downto 64);
1045 buf_bdata <= payload(63 downto 0);
1048 proc:
process (clock)
1050 if clock'event and clock = '1' then 1053 if runreset = '1' then 1054 buf_cnttrig <= (others => '1');
1055 elsif frameloc = 1278 then 1056 -- (1279 => 1278 at 0.46 => 0.48 to fix tagerr) 1057 buf_cnttrig <= trgtag;
1061 if frameloc = 1278 and seq_mask /= 0 and mask = '0' then 1068 -- [buf_data: (8-bit expno) (12-bit runno) (12-bit subno) (32-bit tag)] 1069 if runreset = '1' then 1070 buf_exprun <= (others => '0');
1073 elsif sig_bcast = '1' and buf_ttpkt = TTPKT_TTAG then 1074 buf_exprun <= buf_bdata(63 downto 32);
1075 seq_mask <= seq_mask(0) & mask;
1076 tagin <= buf_bdata(31 downto 0);
1077 if buf_bdata(31 downto 0) /= buf_cnttrig and seq_mask = 0 then 1078 ---sta_tagerr <= entagerr and (not mask); 1079 seq_tagerr <= entagerr and (not mask);
1081 -- tagerr is issued if entagerr is not cleared within one turn, 1082 -- i.e., at next TTPKT_RST 1083 sta_tagerr <= entagerr and (not mask) and seq_tagerr;
1090 exprun <= buf_exprun;
1091 tagerr <= sta_tagerr;
1095 ------------------------------------------------------------------------ 1097 ------------------------------------------------------------------------ 1099 use ieee.std_logic_1164.
all;
1100 use ieee.std_logic_unsigned.
all;
1101 use ieee.numeric_std.
all;
1110 DEFADDR : (19 downto 0) := x"00000";
1111 CLKDIV1 : range 0 to 72;
1112 CLKDIV2 : range 0 to 72;
1113 SIM_SPEEDUP : := '0' );
1116 clock : in ;
-- 127 MHz 1117 invclock : in ;
-- 127 MHz inverted 1118 dblclock : in ;
-- 254 MHz 1119 dblclockb : in ;
-- 254 MHz inverted 1120 ckup : in ;
-- clock is locked 1121 trgp : in ;
-- directly from RJ-45 or SFP 1125 utime : out (31 downto 0);
-- unit: second 1126 ctime : out (26 downto 0);
-- unit: clock 1127 clkfreq : out (23 downto 0);
-- unit: clock 1129 --timerr0 : out std_logic_vector (26 downto 0); 1130 --timerr1 : out std_logic_vector (26 downto 0); 1131 --timerr2 : out std_logic_vector (31 downto 0); 1132 --timerr3 : out std_logic_vector (31 downto 0); 1134 -- exp- / run-number, my address 1135 exprun : out (31 downto 0);
1138 myaddr : out (19 downto 0);
1141 runreset : out ;
-- one clock long 1142 errreset : out ;
-- one clock long 1143 bsyreset : out ;
-- one clock long 1144 feereset : out ;
-- one clock long 1145 b2lreset : out ;
-- one clock long 1146 gtpreset : out ;
-- one clock long 1147 semreset : out ;
-- one clock long 1148 rstmask : out ;
-- for runreset and errreset 1150 -- disable mask while running, jtag and ttaddr -p 1154 jtag : out (2 downto 0);
1155 jtagdbg : out (9 downto 0);
1158 trgout : out ;
-- one clock long 1159 trgtyp : out (3 downto 0);
-- available at trgout 1160 trgtag : out (31 downto 0);
-- available at trgout 1161 tagerr : out ;
-- error, held until runreset 1162 trgshort : out ;
-- error, held until runreset 1167 staoctet : out ;
-- H: valid K-symbols found for 80 clocks 1168 ttup : out ;
-- H: valid packet found for 256*1280 clocks 1169 cntlinkrst : out (7 downto 0);
-- number of link reset 1172 -- revolution signal and reduced clock output 1176 frameloc : out (10 downto 0);
1177 divclk1 : out (1 downto 0);
1178 divclk2 : out (1 downto 0);
1180 -- data out (may be or may not be useful) 1181 octet : out (7 downto 0);
1183 payload : out (76 downto 0);
1186 cntbit2 : out (2 downto 0);
1187 cntoctet : out (4 downto 0);
1188 cntdato : out (3 downto 0);
1189 cntpacket : out (7 downto 0);
1192 regsel :
out (
4 downto 0);
1193 usrreg : out (7 downto 0);
1195 -- debug input to investigate link condition 1201 -- debug output to investigate link condition 1202 bit2 : out (1 downto 0);
1203 bit10 : out (9 downto 0);
1204 cntdelay : out (6 downto 0);
1205 cntwidth : out (5 downto 0);
1206 staiddr : out (1 downto 0);
1207 starxerr : out (8 downto 0);
1209 iddrdbg : out (9 downto 0);
1210 crcdbg : out (8 downto 0) );
1213 ------------------------------------------------------------------------ 1215 -- cnt_bit2: (3-bit) 0..4 if in sync, 5 if out of sync 1216 -- cnt_octet: (5-bit) 0..16 to count any octet in a packet (=16 alt.comma) 1217 -- cnt_packet: (8-bit) 0..15 to count packet in a revo frame (>15 not sync) 1218 -- cnt_frameloc: (11-bit) 0..1279 to locate position in a frame 1219 signal cnt_bit2 : (2 downto 0) := "101";
1220 signal cnt_packet : (7 downto 0) := "00010000";
1221 signal cnt_frameloc : (10 downto 0) := "10100000000";
1223 signal buf_octet : (7 downto 0) := x"00";
1224 signal buf_isk : := '0';
1225 signal sig_comma : := '0';
1226 signal sta_ttup : := '0';
1227 signal sta_octet : := '0';
1228 signal sig_nocomma : := '0';
1230 signal sig_bit2 : (1 downto 0) := "00";
1231 signal sig_bit10 : (9 downto 0) := (others => '0');
1232 signal sig_slip : := '0';
1234 signal sig_incdelay : := '0';
1235 signal sig_inccmd : := '0';
1236 signal sig_calcmd : := '0';
-- spartan6 only 1237 signal sig_caldelay : := '0';
-- spartan6 only 1239 signal sig_newcomma : := '0';
1241 signal sig_payload : := '0';
1242 signal sig_idle : := '0';
1243 signal buf_payload : (76 downto 0) := (others => '0');
1245 signal sig_trig : := '0';
1246 signal sta_trgtag : (31 downto 0) := (others => '0');
1247 signal sig_utime : (31 downto 0) := (others => '0');
1248 signal sig_ctime : (26 downto 0) := (others => '0');
1250 signal sig_runreset : := '0';
1251 signal sig_errreset : := '0';
1253 signal sta_entagerr : := '0';
1255 signal sta_trgmask : := '0';
1256 signal sta_rstmask : := '0';
1257 signal sig_tagset : := '0';
1258 signal buf_tagin : (31 downto 0) := (others => '0');
1260 signal cnt_octet : (4 downto 0) := (others => '0');
1261 signal cnt_datoctet : (3 downto 0) := (others => '0');
1262 signal sig_ocerr : (5 downto 0) := (others => '0');
1263 signal sig_paerr : (2 downto 0) := (others => '0');
1265 signal sta_iddr : (1 downto 0) := "00";
1266 signal sta_crc8ok : := '0';
1270 sig_caldelay <= caldelay or sig_calcmd;
1273 generic map ( FLIPIN => FLIPTRG,
1274 SIM_SPEEDUP => SIM_SPEEDUP
) 1275 port map ( clock => clock,
1276 invclock => invclock,
1277 dblclock => dblclock,
1278 dblclockb => dblclockb,
1281 staoctet => sta_octet,
1282 stacrc8ok => sta_crc8ok,
1284 incdelay => incdelay,
1285 clrdelay => clrdelay,
1286 caldelay => sig_caldelay,
-- spartan6 only 1287 staiddr => sta_iddr,
-- out 1288 bit2 => sig_bit2,
-- out 1289 cntdelay => cntdelay,
-- out 1290 cntwidth => cntwidth,
-- out 1291 iddrdbg => iddrdbg
);
-- out 1294 port map ( ckup => ckup,
1296 prev8 => sig_bit10
(7 downto 0),
1297 cntbit2 => cnt_bit2,
1298 comma => sig_comma,
-- out/async for debit2 1299 newcomma => sig_newcomma
);
-- out/async for debit2 1302 port map ( clock => clock,
1304 nocomma => sig_nocomma,
1305 newcomma => sig_newcomma,
1308 bit10 => sig_bit10,
-- out 1309 cntbit2 => cnt_bit2,
-- out 1310 sigslip => sig_slip
);
-- out 1313 port map ( clock => clock,
1314 cntbit2 => cnt_bit2,
1315 bit2 => sig_bit2,
-- to skip one clock wait for 10b 1317 octet => buf_octet,
-- out/async for detrig/deoctet 1318 isk => buf_isk
);
-- out/async for detrig/deoctet 1321 port map ( clock => clock,
1323 mask => sta_trgmask,
1324 runreset => sig_runreset,
1325 cntbit2 => cnt_bit2,
1328 tagset => sig_tagset,
1330 jtag => jtag,
-- out 1331 jtagdbg => jtagdbg,
-- out 1332 trgout => sig_trig,
-- out 1333 trgtyp => trgtyp,
-- out 1334 trgtag => sta_trgtag,
-- out 1335 trgshort => trgshort
);
-- out 1338 port map ( clock => clock,
1339 cntbit2 => cnt_bit2,
1342 nocomma => sig_nocomma,
-- out 1343 staoctet => sta_octet,
-- out 1344 stacrc8ok => sta_crc8ok,
-- out 1345 sigpayload => sig_payload,
-- out 1346 sigidle => sig_idle,
-- out 1347 incdelay => sig_incdelay,
-- out 1348 cntlinkrst => cntlinkrst,
-- out 1349 payload => buf_payload,
-- out 1350 cntoctet => cnt_octet,
-- out 1351 cntdato => cnt_datoctet,
-- out 1352 rxerr => sig_ocerr,
-- out 1353 crcdbg => crcdbg
);
-- out 1356 generic map ( PROTOCOL => PROTOCOL,
1361 SIM_SPEEDUP => SIM_SPEEDUP
) 1362 port map ( clock => clock,
1363 staiddr => sta_iddr,
1364 staoctet => sta_octet,
1365 sigpayload => sig_payload,
1366 sigidle => sig_idle,
1367 payload => buf_payload,
1368 regsel => regsel,
-- out 4 downto 0 1369 usrreg => usrreg,
-- out 7 downto 0 1370 badver => badver,
-- out 1371 clraddr => clraddr,
-- out 1372 myaddr => myaddr,
-- out 1373 frame => frame,
-- out 1374 frame3 => frame3,
-- out 1375 frame9 => frame9,
-- out 1376 divclk1 => divclk1,
-- out 1377 divclk2 => divclk2,
-- out 1378 cntpacket => cnt_packet,
-- out 1379 clkfreq => clkfreq,
-- out 1380 utime => sig_utime,
-- out 1381 ctime => sig_ctime,
-- out 1382 frameloc => cnt_frameloc,
-- out 1383 runreset => sig_runreset,
-- out 1384 errreset => sig_errreset,
-- out 1385 bsyreset => bsyreset,
-- out 1386 feereset => feereset,
-- out 1387 b2lreset => b2lreset,
-- out 1388 gtpreset => gtpreset,
-- out 1389 semreset => semreset,
-- out 1390 incdelay => sig_inccmd,
-- out 1391 caldelay => sig_calcmd,
-- out 1392 entagerr => sta_entagerr,
-- out 1393 running => running,
-- out 1394 trgmask => sta_trgmask,
-- out 1395 rstmask => sta_rstmask,
-- out 1396 dismask => dismask,
-- out 1397 ttup => sta_ttup,
-- out 1398 timerr => timerr,
-- out 1399 --timerr0 => timerr0, -- out 1400 --timerr1 => timerr1, -- out 1401 --timerr2 => timerr2, -- out 1402 --timerr3 => timerr3, -- out 1403 sigerr => sig_paerr
);
-- out 1406 port map ( clock => clock,
1407 frameloc => cnt_frameloc,
1409 entagerr => sta_entagerr,
1410 mask => sta_trgmask,
1411 runreset => sig_runreset,
1412 trgtag => sta_trgtag,
1413 sigpayload => sig_payload,
1414 payload => buf_payload,
1415 exprun => exprun,
-- out 1416 tagset => sig_tagset,
-- out 1417 tagin => buf_tagin,
-- out 1418 tagerr => tagerr
);
-- out 1426 -- staoctet='1' when a valid comma is found 1427 -- ttup='1' when >255 continuously valid packets are found 1428 staoctet <= sta_octet;
1430 runreset <= sig_runreset;
1431 errreset <= sig_errreset;
1432 staiddr <= sta_iddr;
1433 starxerr <= sig_paerr & sig_ocerr;
1435 cntbit2 <= cnt_bit2;
1436 cntoctet <= cnt_octet;
1437 cntdato <= cnt_datoctet;
1438 cntpacket <= cnt_packet;
1442 payload <= buf_payload;
1443 sigpayload <= sig_payload;
1444 sigidle <= sig_idle;
1447 trgtag <= sta_trgtag;
1450 frameloc <= cnt_frameloc;
1451 trgmask <= sta_trgmask;
1452 rstmask <= sta_rstmask;
1453 entagerr <= sta_entagerr;
1457 -- - emacs outline mode setup 1458 -- Local Variables: *** 1459 -- mode:outline-minor *** 1460 -- outline-regexp:"-- -+" ***