1 ----------------------------------------------------------------------------------
5 -- Create Date: 09:
16:
59 11/24/2012
7 -- Module Name: EMAC_GXPCS - Behavioral
16 -- Revision 0.
01 -
File Created
17 -- Additional Comments:
19 ----------------------------------------------------------------------------------
21 use IEEE.STD_LOGIC_1164.
ALL;
22 use IEEE.STD_LOGIC_ARITH.
ALL;
23 use IEEE.STD_LOGIC_UNSIGNED.
ALL;
24 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;
38 clk2x : IN ;
-- 2xSFP_REFCLK 312.5MHz norminal
41 TX_high : IN ;
-- in clk2x domain, TX_high = clk
46 GTX_TXD : out (31 downto 0) := (others => '0');
47 GTX_TXHEADER : out (1 downto 0) := (others => '0');
48 GTX_TX_PAUSE : IN ;
-- sequence counter = "011111"
49 GTX_RXD : in (31 downto 0);
51 GTX_RXHEADER : in (1 downto 0);
52 GTX_RXHEADERVLD : in ;
54 GTX_RXGEARBOXSLIP_OUT : out := '0';
55 EmacPhyTxC : in (3 downto 0);
56 EmacPhyTxD : in (31 downto 0);
57 PhyEmacRxC : out (3 downto 0) := (others => '0');
58 PhyEmacRxD : out (31 downto 0) := (others => '0')
65 RXHEADER_IN :
IN (
2 downto 0);
66 RXHEADERVALID_IN :
IN ;
70 RXGEARBOXSLIP_OUT :
OUT
79 UNSCRAMBLED_DATA_IN :
IN ((TX_DATA_WIDTH
-1)
downto 0);
83 SCRAMBLED_DATA_OUT :
OUT ((TX_DATA_WIDTH
-1)
downto 0)
92 SCRAMBLED_DATA_IN :
IN ((RX_DATA_WIDTH
-1)
downto 0);
96 UNSCRAMBLED_DATA_OUT :
OUT ((RX_DATA_WIDTH
-1)
downto 0)
99 constant EBLOCK : (63 downto 0) := x"1e1e1e1e1e1e1e1e";
100 constant LBLOCK : (63 downto 0) := x"0100000001000055";
101 constant R_FAULT : (31 downto 0) := x"0200009c";
102 constant LBLOCK_R : (71 downto 0) := x"0100009c10100009c1";
103 constant EBLOCK_R : (71 downto 0) := x"fefefefeffefefefef";
104 type array37x32 is array(0 to 36) of (31 downto 0);
105 constant RxIdle : array37x32 := (x"ffff0000",x"ffff0000",x"ffff0000",x"ffff0000",
106 x"ffff0000",x"ffff0000",x"ffff0000",x"00000000",x"00000000",x"00000000",x"00000000",x"00000000",
107 x"ffff0000",x"ffff0000",x"ffff0000",x"00000000",x"00000000",x"00000000",x"00000000",x"00000000",
108 x"ffff0000",x"ffff0000",x"ffff0000",x"00000000",x"00000000",x"00000000",x"00000000",x"00000000",
109 x"ffff0000",x"ffff0000",x"ffff0000",x"00000000",x"00000000",x"00000000",x"00000000",x"00000000",
111 type state is (TX_INIT, TX_C, TX_D, TX_T, TX_E);
112 signal T_state : state := TX_INIT;
113 signal EmacPhyTxC_q : (3 downto 0) := (others => '0');
114 signal EmacPhyTxD_q : (31 downto 0) := (others => '0');
115 signal TxC : (7 downto 0) := (others => '0');
116 signal TxD : (63 downto 0) := (others => '0');
117 signal TxD_q : (63 downto 0) := (others => '0');
118 signal c_coded : (55 downto 0) := (others => '0');
119 signal tx_coded : (65 downto 0) := (others => '0');
120 signal T_TYPE_C : := '0';
121 signal T_TYPE_D : := '0';
122 signal T_TYPE_S : := '0';
123 signal T_TYPE_T : := '0';
124 signal T_IS_D : := '0';
125 signal T_IS_O : (1 downto 0) := (others => '0');
126 signal T_IS_S : (1 downto 0) := (others => '0');
127 signal T_IS_C : (7 downto 0) := (others => '0');
128 signal T_IS_E : (7 downto 0) := (others => '0');
129 signal T_IS_T : (7 downto 0) := (others => '0');
130 signal GTX_TX_PAUSE_q : := '0';
131 signal TX_FIFO_DI : (33 downto 0) := (others => '0');
132 signal TX_FIFO_DO : (33 downto 0) := (others => '0');
133 signal TX_FIFO_wa : (3 downto 0) := (others => '0');
134 signal TX_FIFO_ra : (3 downto 0) := (others => '0');
135 signal GTX_RXHEADER_IN : (2 downto 0) := (others => '0');
136 signal BLOCK_LOCK : := '0';
137 signal BLOCK_SYNC_SM_RESET : := '0';
138 signal BLOCK_NOT_LOCK : := '0';
139 signal GTX_RXHEADERVLD_dl : (1 downto 0) := (others => '0');
140 signal GTX_RXHEADER_dl0 : (1 downto 0) := (others => '0');
141 signal TX_UNSCRAMBLED_DATA : (65 downto 0) := (others => '0');
142 signal TX_UNSCRAMBLED_DATA_MUX : (33 downto 0) := (others => '0');
143 signal RX_UNSCRAMBLED_DATA : (63 downto 0) := (others => '0');
144 signal RX_UNSCRAMBLED_DATA_OUT : (31 downto 0) := (others => '0');
145 signal RXHEADER : (1 downto 0) := (others => '0');
146 type Rstate is (RX_INIT, RX_C, RX_D, RX_T, RX_E);
147 signal R_state : Rstate := RX_INIT;
148 signal RxC : (7 downto 0) := (others => '0');
149 signal RxD : (63 downto 0) := (others => '0');
150 signal c_raw : (63 downto 0) := (others => '0');
151 signal rx_raw : (71 downto 0) := (others => '0');
152 signal rx_raw_ps2 : (71 downto 0) := (others => '0');
153 signal rx_raw_ps3 : (71 downto 0) := (others => '0');
154 signal rx_raw_mux : (35 downto 0) := (others => '0');
155 signal R_TYPE_C : := '0';
156 signal R_TYPE_D : := '0';
157 signal R_TYPE_S : := '0';
158 signal R_TYPE_T : := '0';
159 signal NEXT_TYPE_C : := '0';
160 signal NEXT_TYPE_D : := '0';
161 signal NEXT_TYPE_S : := '0';
162 signal NEXT_TYPE_T : := '0';
163 signal R_IS_D : := '0';
164 signal R_IS_T : := '0';
165 signal Legal_O : (1 downto 0) := (others => '0');
166 signal R_IS_O : (1 downto 0) := (others => '0');
167 signal R_IS_S : (1 downto 0) := (others => '0');
168 signal R_IS_C : (7 downto 0) := (others => '0');
169 signal R_IS_E : (7 downto 0) := (others => '0');
170 signal RX_FIFO_DI : (36 downto 0) := (others => '0');
171 signal RX_FIFO_DO : (36 downto 0) := (others => '0');
172 signal RX_FIFO_WA : (3 downto 0) := (others => '0');
173 signal RX_FIFO_RA : (3 downto 0) := (others => '0');
174 signal RX_FIFO_RA_G : (3 downto 0) := (others => '0');
175 signal RX_FIFO_RA_P : (3 downto 0) := (others => '0');
176 signal RX_FIFO_WA_RA_D : (3 downto 0) := (others => '0');
177 signal RX_FIFO_RA_G0SyncRegs : (2 downto 0) := (others => '0');
178 signal RX_FIFO_RA_G1SyncRegs : (2 downto 0) := (others => '0');
179 signal RX_FIFO_RA_G2SyncRegs : (2 downto 0) := (others => '0');
180 signal RX_FIFO_RA_G3SyncRegs : (2 downto 0) := (others => '0');
181 signal RX_FIFO_WE : := '0';
182 signal GTX_RXDVLD_q : := '0';
183 signal skip_RX_FIFO_WE : := '0';
184 signal ec_RX_FIFO_RAn : := '0';
185 signal insert_IDLE : := '0';
186 signal delete_IDLE : := '0';
187 signal insert_IDLE_l : := '0';
188 signal delete_IDLE_l : := '0';
189 signal R_IS_RF : (6 downto 0) := (others => '0');
190 signal R_IS_LF : (6 downto 0) := (others => '0');
191 signal R_IS_IDLE : (5 downto 0) := (others => '0');
192 signal en_DI : := '0';
193 signal en_II : := '0';
194 signal T4567 : := '0';
196 signal inh_cntr : (3 downto 0) := (others => '0');
197 signal reset_RXSyncRegs : (2 downto 0) := (others => '0');
198 signal RXGOOD_cntr : (4 downto 0) := (others => '0');
199 signal RXRESETDONE_SyncRegs : (3 downto 0) := (others => '0');
203 if(clk2x'event and clk2x = '1')then
204 if(TX_high = '0')then
205 EmacPhyTxC_q <= EmacPhyTxC;
206 EmacPhyTxD_q <= EmacPhyTxD;
208 TxC <= EmacPhyTxC & EmacPhyTxC_q;
209 TxD <= EmacPhyTxD & EmacPhyTxD_q;
211 if(TX_high = '1')then
212 TX_UNSCRAMBLED_DATA_MUX <= '1' & TX_UNSCRAMBLED_DATA(64) & TX_UNSCRAMBLED_DATA(31 downto 0);
214 TX_UNSCRAMBLED_DATA_MUX <= '0' & TX_UNSCRAMBLED_DATA(64 downto 32);
216 TX_FIFO_DI(33 downto 32) <= TX_UNSCRAMBLED_DATA_MUX(33 downto 32);
221 if(clk'event and clk = '1')then
222 if(TxC(3 downto 0) = x"1" and TxD(31 downto 0) = R_FAULT)then
227 if(TxC(7 downto 4) = x"1" and TxD(63 downto 32) = R_FAULT)then
232 if(TxC = x"01" and TxD(7 downto 0) = x"fb")then
237 if(TxC(7 downto 4) = x"1" and TxD(39 downto 32) = x"fb")then
243 if(TxC(i) = '1' and TxD(i*8+7 downto i*8) = x"07")then
248 if(TxC(i) = '1' and TxD(i*8+7 downto i*8) = x"fe")then
250 c_coded(I*7+6 downto i*7) <= "0011110";
253 c_coded(I*7+6 downto i*7) <= "0000000";
256 if(TxC(0) = '1' and TxD(7 downto 0) = x"fd")then
261 if(TxC(1 downto 0) = "10" and TxD(15 downto 8) = x"fd")then
266 if(TxC(2 downto 0) = "100" and TxD(23 downto 16) = x"fd")then
271 if(TxC(3 downto 0) = "1000" and TxD(31 downto 24) = x"fd")then
276 if(TxC(4 downto 0) = "10000" and TxD(39 downto 32) = x"fd")then
281 if(TxC(5 downto 0) = "100000" and TxD(47 downto 40) = x"fd")then
286 if(TxC(6 downto 0) = "1000000" and TxD(55 downto 48) = x"fd")then
291 if(TxC(7 downto 0) = "10000000" and TxD(63 downto 56) = x"fd")then
296 T_IS_D <= not or_reduce(TxC);
297 if(and_reduce(T_IS_C) = '1' or (T_IS_O(0) = '1' and T_IS_C(7 downto 4) = not T_IS_E(7 downto 4)) or (T_IS_O(1) = '1' and T_IS_C(3 downto 0) = not T_IS_E(3 downto 0)) or T_IS_O = "11")then
302 if(T_IS_S(0) = '1' or (T_IS_S(1) = '1' and (T_IS_C(3 downto 0) = not T_IS_E(3 downto 0) or T_IS_O(0) = '1')))then
309 if(T_IS_T(0) = '1' and T_IS_C(7 downto 1) = not T_IS_E(7 downto 1))then
312 if(T_IS_T(1) = '1' and T_IS_C(7 downto 2) = not T_IS_E(7 downto 2))then
315 if(T_IS_T(2) = '1' and T_IS_C(7 downto 3) = not T_IS_E(7 downto 3))then
318 if(T_IS_T(3) = '1' and T_IS_C(7 downto 4) = not T_IS_E(7 downto 4))then
321 if(T_IS_T(4) = '1' and T_IS_C(7 downto 5) = not T_IS_E(7 downto 5))then
324 if(T_IS_T(5) = '1' and T_IS_C(7 downto 6) = not T_IS_E(7 downto 6))then
327 if(T_IS_T(6) = '1' and T_IS_C(7) = not T_IS_E(7))then
330 if(T_IS_T(7) = '1')then
334 if(T_IS_C = x"ff")then
335 tx_coded(63 downto 0) <= x"000000000000001e";
337 if(T_IS_O(1) = '1' and T_IS_C(3 downto 0) = not T_IS_E(3 downto 0))then
338 tx_coded(63 downto 0) <= TxD_q(63 downto 40) & x"0" & c_coded(27 downto 0) & x"2d";
340 if(T_IS_S(1) = '1' and T_IS_C(3 downto 0) = not T_IS_E(3 downto 0))then
341 tx_coded(63 downto 0) <= TxD_q(63 downto 40) & x"0" & c_coded(27 downto 0) & x"33";
343 if(T_IS_O(0) = '1' and T_IS_C(7 downto 4) = not T_IS_E(7 downto 4))then
344 tx_coded(63 downto 0) <= c_coded(55 downto 28) & x"0" & TxD_q(31 downto 8) & x"4b";
346 if(T_IS_O = "11")then
347 tx_coded(63 downto 0) <= TxD_q(63 downto 40) & x"00" & TxD_q(31 downto 8) & x"55";
349 if(T_IS_S(1) = '1' and T_IS_O(0) = '1')then
350 tx_coded(63 downto 0) <= TxD_q(63 downto 40) & TxD_q(31 downto 0) & x"66";
352 if(T_IS_S(0) = '1')then
353 tx_coded(63 downto 0) <= TxD_q(63 downto 8) & x"78";
355 if(T_IS_T(0) = '1')then
356 tx_coded(63 downto 0) <= c_coded(55 downto 7) & "0000000" & x"87";
358 if(T_IS_T(1) = '1')then
359 tx_coded(63 downto 0) <= c_coded(55 downto 14) & "000000" & TxD_q(7 downto 0) & x"99";
361 if(T_IS_T(2) = '1')then
362 tx_coded(63 downto 0) <= c_coded(55 downto 21) & "00000" & TxD_q(15 downto 0) & x"aa";
364 if(T_IS_T(3) = '1')then
365 tx_coded(63 downto 0) <= c_coded(55 downto 28) & "0000" & TxD_q(23 downto 0) & x"b4";
367 if(T_IS_T(4) = '1')then
368 tx_coded(63 downto 0) <= c_coded(55 downto 35) & "000" & TxD_q(31 downto 0) & x"cc";
370 if(T_IS_T(5) = '1')then
371 tx_coded(63 downto 0) <= c_coded(55 downto 42) & "00" & TxD_q(39 downto 0) & x"d2";
373 if(T_IS_T(6) = '1')then
374 tx_coded(63 downto 0) <= c_coded(55 downto 49) & '0' & TxD_q(47 downto 0) & x"e1";
376 if(T_IS_T(7) = '1')then
377 tx_coded(63 downto 0) <= TxD_q(55 downto 0) & x"ff";
380 tx_coded(63 downto 0) <= TxD_q;
383 tx_coded(65 downto 64) <= "01";
385 tx_coded(65 downto 64) <= "10";
389 TX_UNSCRAMBLED_DATA <= "10" & LBLOCK;
393 TX_UNSCRAMBLED_DATA <= tx_coded;
394 if(T_TYPE_C = '1')then
396 elsif(T_TYPE_S = '1')then
400 TX_UNSCRAMBLED_DATA <= "10" & EBLOCK;
403 TX_UNSCRAMBLED_DATA <= tx_coded;
404 if(T_TYPE_S = '1')then
406 elsif(T_TYPE_C = '0')then
408 TX_UNSCRAMBLED_DATA <= "10" & EBLOCK;
411 TX_UNSCRAMBLED_DATA <= tx_coded;
412 if(T_TYPE_T = '1')then
414 elsif(T_TYPE_D = '0')then
416 TX_UNSCRAMBLED_DATA <= "10" & EBLOCK;
419 TX_UNSCRAMBLED_DATA <= tx_coded;
420 if(T_TYPE_C = '1')then
422 elsif(T_TYPE_S = '1')then
426 TX_UNSCRAMBLED_DATA <= "10" & EBLOCK;
429 TX_UNSCRAMBLED_DATA <= tx_coded;
430 if(T_TYPE_C = '1')then
432 elsif(T_TYPE_D = '1')then
434 elsif(T_TYPE_T = '1')then
437 TX_UNSCRAMBLED_DATA <= "10" & EBLOCK;
443 process(clk2x,reset_TXSync)
445 if(reset_TXSync = '1')then
447 elsif(clk2x'event and clk2x = '1')then
448 TX_FIFO_WA <= TX_FIFO_WA + 1;
451 g_TX_FIFO: for i in 0 to 33 generate
454 DPO => TX_FIFO_DO
(i
),
-- Read-only 1-bit data output
455 SPO =>
open,
-- R/W 1-bit data output
456 A0 => TX_FIFO_WA
(0),
-- R/W address[0] input
457 A1 => TX_FIFO_WA
(1),
-- R/W address[1] input
458 A2 => TX_FIFO_WA
(2),
-- R/W address[2] input
459 A3 => TX_FIFO_WA
(3),
-- R/W address[3] input
460 A4 => '0',
-- R/W address[4] input
461 D => TX_FIFO_DI
(i
),
-- Write 1-bit data input
462 DPRA0 => TX_FIFO_RA
(0),
-- Read-only address[0] input
463 DPRA1 => TX_FIFO_RA
(1),
-- Read-only address[1] input
464 DPRA2 => TX_FIFO_RA
(2),
-- Read-only address[2] input
465 DPRA3 => TX_FIFO_RA
(3),
-- Read-only address[3] input
466 DPRA4 => '0',
-- Read-only address[4] input
467 WCLK => clk2x,
-- Write clock input
468 WE => '1'
-- Write enable input
473 if(TXUSRCLK'event and TXUSRCLK = '1')then
474 if(reset_TXSync = '1')then
475 TX_FIFO_RA <= (others => '0');
476 elsif(GTX_TX_PAUSE = '0' or (TX_FIFO_DO(33) = '1' and GTX_TX_PAUSE_q = '0'))then
477 TX_FIFO_RA <= TX_FIFO_RA + 1;
480 GTX_TXHEADER <= "00";
482 GTX_TXHEADER <= not TX_FIFO_DO(32) & TX_FIFO_DO(32);
484 GTX_TX_PAUSE_q <= GTX_TX_PAUSE;
486 GTX_TXD <= (others => '0');
488 GTX_TXD <= TX_FIFO_DO(31 downto 0);
492 process(RXUSRCLK,RXRESETDONE)
494 if(RXRESETDONE = '0')then
495 RXRESETDONE_SyncRegs <= (others => '0');
496 elsif(RXUSRCLK'event and RXUSRCLK = '1')then
497 RXRESETDONE_SyncRegs <= RXRESETDONE_SyncRegs(2 downto 0) & '1';
501 BLOCKSYNC_OUT => BLOCK_LOCK,
502 RXGEARBOXSLIP_OUT => GTX_RXGEARBOXSLIP_OUT ,
503 RXHEADER_IN => GTX_RXHEADER_IN ,
504 RXHEADERVALID_IN => GTX_RXHEADERVLD,
505 USER_CLK => RXUSRCLK,
506 SYSTEM_RESET => BLOCK_SYNC_SM_RESET
508 BLOCK_SYNC_SM_RESET <= not RXRESETDONE_SyncRegs(3);
509 GTX_RXHEADER_IN <= '0' & GTX_RXHEADER;
510 BLOCK_NOT_LOCK <= not BLOCK_LOCK;
512 UNSCRAMBLED_DATA_IN => TX_UNSCRAMBLED_DATA_MUX
(31 downto 0),
513 SCRAMBLED_DATA_OUT => TX_FIFO_DI
(31 downto 0),
514 DATA_VALID_IN => '1',
516 SYSTEM_RESET => RESET_TXSync
520 SCRAMBLED_DATA_IN => GTX_RXD,
521 UNSCRAMBLED_DATA_OUT => RX_UNSCRAMBLED_DATA_OUT ,
522 DATA_VALID_IN => GTX_RXDVLD,
523 USER_CLK => RXUSRCLK,
524 SYSTEM_RESET => BLOCK_NOT_LOCK
528 if(RXUSRCLK'event and RXUSRCLK = '1')then
529 GTX_RXHEADERVLD_dl <= GTX_RXHEADERVLD_dl(0) & GTX_RXHEADERVLD;
530 if(GTX_RXHEADERVLD = '1')then
531 GTX_RXHEADER_dl0 <= GTX_RXHEADER;
533 if(GTX_RXHEADERVLD_dl(0) = '1')then
534 RX_UNSCRAMBLED_DATA(31 downto 0) <= RX_UNSCRAMBLED_DATA_OUT;
536 if(GTX_RXHEADERVLD_dl(1) = '1')then
537 RX_UNSCRAMBLED_DATA(63 downto 32) <= RX_UNSCRAMBLED_DATA_OUT;
539 if(GTX_RXHEADERVLD_dl(0) = '1')then
540 if(reset_RXSyncRegs(2) = '1' or R_state = RX_E)then
542 elsif(RXGOOD_cntr(4) = '1')then
545 if(reset_RXSyncRegs(2) = '1' or R_state = RX_E)then
546 RXGOOD_cntr <= (others => '0');
547 elsif(RXGOOD_cntr(4) = '0')then
548 RXGOOD_cntr <= RXGOOD_cntr + 1;
551 RXHEADER <= GTX_RXHEADER_dl0;
552 case RX_UNSCRAMBLED_DATA(3 downto 0) is
553 when x"1" => RxC <= x"c0";
554 when x"2" => RxC <= x"e0";
555 when x"3" | x"d" => RxC <= x"1f";
556 when x"4" => RxC <= x"f8";
557 when x"5" | x"6" => RxC <= x"11";
558 when x"7" | x"e" => RxC <= x"ff";
559 when x"8" => RxC <= x"01";
560 when x"9" => RxC <= x"fe";
561 when x"a" => RxC <= x"fc";
562 when x"b" => RxC <= x"f1";
563 when x"c" => RxC <= x"f0";
564 when x"f" => RxC <= x"80";
565 when others => RxC <= x"00";
567 RxD <= RX_UNSCRAMBLED_DATA;
569 if(RX_UNSCRAMBLED_DATA(i*7+14 downto i*7+8) = "0000000")then
574 if(RX_UNSCRAMBLED_DATA(i*7+14 downto i*7+8) = "0011110")then
576 c_raw(I*8+7 downto i*8) <= x"fe";
579 c_raw(I*8+7 downto i*8) <= x"07";
582 if(RX_UNSCRAMBLED_DATA(35 downto 8) = x"0010000" or RX_UNSCRAMBLED_DATA(35 downto 8) = x"0020000")then
587 if(RX_UNSCRAMBLED_DATA(63 downto 36) = x"0100000" or RX_UNSCRAMBLED_DATA(63 downto 36) = x"0200000")then
592 if(RX_UNSCRAMBLED_DATA(7 downto 4) = x"4" or RX_UNSCRAMBLED_DATA(7 downto 4) = x"5" or RX_UNSCRAMBLED_DATA(7 downto 4) = x"6")then
597 if(RX_UNSCRAMBLED_DATA(7 downto 4) = x"2" or RX_UNSCRAMBLED_DATA(7 downto 4) = x"5")then
602 if(RX_UNSCRAMBLED_DATA(7 downto 4) = x"7")then
607 if(RX_UNSCRAMBLED_DATA(7 downto 4) = x"3" or RX_UNSCRAMBLED_DATA(7 downto 4) = x"6")then
612 if(RXHEADER = "01")then
617 if(RX_UNSCRAMBLED_DATA(7) = '1')then
618 case RX_UNSCRAMBLED_DATA(6 downto 4) is
619 when "000" => R_IS_T <= not or_reduce(RX_UNSCRAMBLED_DATA(14 downto 8));
620 when "001" => R_IS_T <= not or_reduce(RX_UNSCRAMBLED_DATA(21 downto 16));
621 when "010" => R_IS_T <= not or_reduce(RX_UNSCRAMBLED_DATA(28 downto 24));
622 when "011" => R_IS_T <= not or_reduce(RX_UNSCRAMBLED_DATA(35 downto 32));
623 when "100" => R_IS_T <= not or_reduce(RX_UNSCRAMBLED_DATA(42 downto 40));
624 when "101" => R_IS_T <= not or_reduce(RX_UNSCRAMBLED_DATA(49 downto 48));
625 when "110" => R_IS_T <= not RX_UNSCRAMBLED_DATA(56);
626 when others => R_IS_T <= '1';
637 rx_raw_ps2 <= x"00" & RxD;
638 R_IS_IDLE(1 downto 0) <= "00";
639 R_IS_RF(1 downto 0) <= "00";
640 R_IS_LF(1 downto 0) <= "00";
642 R_IS_IDLE(0) <= and_reduce(RxC(3 downto 0)) and and_reduce(R_IS_C(3 downto 0)) and (not NEXT_TYPE_T or not T4567) and not R_IS_T;
643 R_IS_IDLE(1) <= and_reduce(RxC(7 downto 4)) and and_reduce(R_IS_C(7 downto 4)) and not R_IS_T;
644 R_IS_RF(0) <= R_IS_O(0) and Legal_O(0) and not RxD(24);
645 R_IS_RF(1) <= R_IS_O(1) and Legal_O(1) and not RxD(56);
646 R_IS_LF(0) <= R_IS_O(0) and Legal_O(0) and RxD(24);
647 R_IS_LF(1) <= R_IS_O(1) and Legal_O(1) and RxD(56);
649 rx_raw_ps2(71 downto 64) <= RxC;
650 if(RxC = x"ff" and R_IS_C = x"ff" and R_IS_T = '0')then
652 rx_raw_ps2(63 downto 0) <= c_raw;
653 elsif(Legal_O(0) = '1' and R_IS_O(0) = '1' and R_IS_C(7 downto 4) = not R_IS_E(7 downto 4) and RxC(7 downto 4) = x"f")then
655 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 32) & RxD(31 downto 8) & x"9c";
656 elsif(Legal_O(1) = '1' and R_IS_O(1) = '1' and R_IS_C(3 downto 0) = not R_IS_E(3 downto 0) and RxC(3 downto 0) = x"f")then
658 rx_raw_ps2(63 downto 0) <= RxD(63 downto 40) & x"9c" & c_raw(31 downto 0);
659 elsif(Legal_O = "11" and R_IS_O = "11")then
661 rx_raw_ps2(63 downto 0) <= RxD(63 downto 40) & x"9c" & RxD(31 downto 8) & x"9c";
665 if(R_IS_S(0) = '1')then
667 rx_raw_ps2(63 downto 0) <= RxD(63 downto 8) & x"fb";
668 elsif(R_IS_S(1) = '1' and R_IS_C(3 downto 0) = not R_IS_E(3 downto 0) and RxC(3 downto 0) = x"f")then
670 rx_raw_ps2(63 downto 0) <= RxD(63 downto 40) & x"fb" & c_raw(31 downto 0);
671 elsif(R_IS_S(1) = '1' and Legal_O(1) = '1' and R_IS_O(1) = '1')then
673 rx_raw_ps2(63 downto 0) <= RxD(63 downto 40) & x"fb" & RxD(31 downto 8) & x"9c";
678 case RxD(6 downto 4) is
680 if(R_IS_C(7 downto 1) = not R_IS_E(7 downto 1))then
685 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 8) & x"fd";
687 if(R_IS_C(7 downto 2) = not R_IS_E(7 downto 2))then
692 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 16) & x"fd" & RxD(15 downto 8);
694 if(R_IS_C(7 downto 3) = not R_IS_E(7 downto 3))then
699 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 24) & x"fd" & RxD(23 downto 8);
701 if(R_IS_C(7 downto 4) = not R_IS_E(7 downto 4))then
706 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 32) & x"fd" & RxD(31 downto 8);
708 if(R_IS_C(7 downto 5) = not R_IS_E(7 downto 5))then
713 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 40) & x"fd" & RxD(39 downto 8);
715 if(R_IS_C(7 downto 6) = not R_IS_E(7 downto 6))then
720 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 48) & x"fd" & RxD(47 downto 8);
722 if(R_IS_C(7) = not R_IS_E(7))then
727 rx_raw_ps2(63 downto 0) <= c_raw(63 downto 56) & x"fd" & RxD(55 downto 8);
730 rx_raw_ps2(63 downto 0) <= x"fd" & RxD(63 downto 8);
738 R_TYPE_C <= NEXT_TYPE_C;
739 R_TYPE_D <= NEXT_TYPE_D;
740 R_TYPE_S <= NEXT_TYPE_S;
741 R_TYPE_T <= NEXT_TYPE_T;
742 rx_raw_ps3 <= rx_raw_ps2(63 downto 32) & rx_raw_ps2(71 downto 68) & rx_raw_ps2(31 downto 0) & rx_raw_ps2(67 downto 64);
743 R_IS_IDLE(3 downto 2) <= R_IS_IDLE(1 downto 0);
744 R_IS_RF(3 downto 2) <= R_IS_RF(1 downto 0);
745 R_IS_LF(3 downto 2) <= R_IS_LF(1 downto 0);
748 if(reset = '1' or BLOCK_LOCK = '0')then
751 R_IS_LF(5 downto 4) <= "11";
752 R_IS_RF(5 downto 4) <= "00";
753 R_IS_IDLE(5 downto 4) <= "00";
754 elsif(GTX_RXHEADERVLD_dl(0) = '1')then
757 rx_raw <= rx_raw_ps3;
758 R_IS_LF(5 downto 4) <= "11";
759 R_IS_RF(5 downto 4) <= "00";
760 R_IS_IDLE(5 downto 4) <= "00";
761 if(R_TYPE_C = '1')then
763 elsif(R_TYPE_S = '1')then
770 R_IS_LF(5 downto 4) <= R_IS_LF(3 downto 2);
771 R_IS_RF(5 downto 4) <= R_IS_RF(3 downto 2);
772 R_IS_IDLE(5 downto 4) <= R_IS_IDLE(3 downto 2);
773 rx_raw <= rx_raw_ps3;
774 if(R_TYPE_S = '1')then
776 elsif(R_TYPE_C = '0')then
781 R_IS_LF(5 downto 4) <= R_IS_LF(3 downto 2);
782 R_IS_RF(5 downto 4) <= R_IS_RF(3 downto 2);
783 R_IS_IDLE(5 downto 4) <= R_IS_IDLE(3 downto 2);
784 rx_raw <= rx_raw_ps3;
785 if(R_TYPE_T = '1' and (NEXT_TYPE_C = '1' or NEXT_TYPE_S = '1'))then
787 elsif(R_TYPE_D = '0')then
792 R_IS_LF(5 downto 4) <= R_IS_LF(3 downto 2);
793 R_IS_RF(5 downto 4) <= R_IS_RF(3 downto 2);
794 R_IS_IDLE(5 downto 4) <= R_IS_IDLE(3 downto 2);
795 rx_raw <= rx_raw_ps3;
796 if(R_TYPE_S = '1')then
802 rx_raw <= rx_raw_ps3;
803 R_IS_LF(5 downto 4) <= "00";
804 R_IS_RF(5 downto 4) <= "00";
805 R_IS_IDLE(5 downto 4) <= "00";
806 if(R_TYPE_C = '1')then
808 elsif(R_TYPE_D = '1')then
810 elsif(R_TYPE_T = '1' and (NEXT_TYPE_C = '1' or NEXT_TYPE_S = '1'))then
819 process(RXUSRCLK,reset)
822 reset_RXSyncRegs <= (others => '1');
824 elsif(RXUSRCLK'event and RXUSRCLK = '1')then
825 reset_RXSyncRegs <= reset_RXSyncRegs(1 downto 0) & '0';
826 if(BLOCK_LOCK = '0')then
828 elsif((GTX_RXHEADERVLD_dl(0) = '0' and and_reduce(rx_raw(3 downto 0)) = '0') or (GTX_RXHEADERVLD_dl(0) = '1' and and_reduce(rx_raw(39 downto 36)) = '0'))then
830 elsif((GTX_RXHEADERVLD_dl(0) = '0' and or_reduce(rx_raw(3 downto 0)) = '1') or (GTX_RXHEADERVLD_dl(0) = '1' and or_reduce(rx_raw(39 downto 36)) = '1'))then
837 if(RXUSRCLK'event and RXUSRCLK = '1')then
838 GTX_RXDVLD_q <= GTX_RXDVLD;
839 RX_FIFO_WE <= GTX_RXHEADERVLD_dl(1) or GTX_RXHEADERVLD_dl(0);
840 if(GTX_RXHEADERVLD_dl(0) = '0')then
841 rx_raw_mux <= rx_raw(35 downto 0);
842 R_IS_LF(6) <= R_IS_LF(4);
843 R_IS_RF(6) <= R_IS_RF(4);
844 if(R_IS_IDLE(4) = '1' or (R_IS_RF(6) = '1' and R_IS_RF(4) = '1') or (R_IS_LF(6) = '1' and R_IS_LF(4) = '1'))then
850 rx_raw_mux <= rx_raw(71 downto 36);
851 R_IS_LF(6) <= R_IS_LF(5);
852 R_IS_RF(6) <= R_IS_RF(5);
853 if(R_IS_IDLE(5) = '1' or (R_IS_RF(6) = '1' and R_IS_RF(5) = '1') or (R_IS_LF(6) = '1' and R_IS_LF(5) = '1'))then
859 RX_FIFO_DI(36) <= en_II and insert_IDLE_l and not(RX_FIFO_DI(36) and RX_FIFO_WE);
860 RX_FIFO_DI(35 downto 0) <= rx_raw_mux;
861 skip_RX_FIFO_WE <= not (RX_FIFO_WE and skip_RX_FIFO_WE) and en_DI and delete_IDLE_l;
862 if(inh = '1' or (RX_FIFO_WE = '1' and skip_RX_FIFO_WE = '1'))then
863 delete_IDLE_l <= '0';
864 elsif(GTX_RXDVLD_q = '1' and GTX_RXDVLD = '0')then
865 delete_IDLE_l <= delete_IDLE;
867 if(inh = '1' or (RX_FIFO_WE = '1' and RX_FIFO_DI(36) = '1'))then
868 insert_IDLE_l <= '0';
869 elsif(GTX_RXDVLD_q = '1' and GTX_RXDVLD = '0')then
870 insert_IDLE_l <= insert_IDLE;
874 process(RXUSRCLK,reset)
878 RX_FIFO_RA_G0SyncRegs <= (others => '0');
879 RX_FIFO_RA_G1SyncRegs <= (others => '0');
880 RX_FIFO_RA_G2SyncRegs <= (others => '0');
881 RX_FIFO_RA_G3SyncRegs <= (others => '0');
882 RX_FIFO_RA_P <= (others => '0');
883 RX_FIFO_WA_RA_D <= (others => '0');
885 elsif(RXUSRCLK'event and RXUSRCLK = '1')then
886 if(RX_FIFO_WE = '1' and skip_RX_FIFO_WE = '0')then
887 RX_FIFO_WA <= RX_FIFO_WA + 1;
889 RX_FIFO_RA_G0SyncRegs <= RX_FIFO_RA_G0SyncRegs(1 downto 0) & RX_FIFO_RA_G(0);
890 RX_FIFO_RA_G1SyncRegs <= RX_FIFO_RA_G1SyncRegs(1 downto 0) & RX_FIFO_RA_G(1);
891 RX_FIFO_RA_G2SyncRegs <= RX_FIFO_RA_G2SyncRegs(1 downto 0) & RX_FIFO_RA_G(2);
892 RX_FIFO_RA_G3SyncRegs <= RX_FIFO_RA_G3SyncRegs(1 downto 0) & RX_FIFO_RA_G(3);
893 RX_FIFO_RA_P(3) <= RX_FIFO_RA_G3SyncRegs(2);
894 RX_FIFO_RA_P(2) <= RX_FIFO_RA_G3SyncRegs(2) xor RX_FIFO_RA_G2SyncRegs(2);
895 RX_FIFO_RA_P(1) <= RX_FIFO_RA_G3SyncRegs(2) xor RX_FIFO_RA_G2SyncRegs(2) xor RX_FIFO_RA_G1SyncRegs(2);
896 RX_FIFO_RA_P(0) <= RX_FIFO_RA_G3SyncRegs(2) xor RX_FIFO_RA_G2SyncRegs(2) xor RX_FIFO_RA_G1SyncRegs(2) xor RX_FIFO_RA_G0SyncRegs(2);
897 RX_FIFO_WA_RA_D <= RX_FIFO_WA - RX_FIFO_RA_P;
898 if(RX_FIFO_WE = '1' and (skip_RX_FIFO_WE = '1' or RX_FIFO_DI(36) = '1'))then
900 elsif(inh_cntr(3) = '1')then
904 inh_cntr <= (others => '0');
905 elsif(GTX_RXHEADERVLD_dl(0) = '1')then
906 inh_cntr <= inh_cntr + 1;
910 i_delete_IDLE : ROM32X1
914 O => delete_IDLE,
-- ROM output
915 A0 => RX_FIFO_WA_RA_D
(0),
-- ROM address[0]
916 A1 => RX_FIFO_WA_RA_D
(1),
-- ROM address[1]
917 A2 => RX_FIFO_WA_RA_D
(2),
-- ROM address[2]
918 A3 => RX_FIFO_WA_RA_D
(3),
-- ROM address[3]
919 A4 => '0'
-- ROM address[4]
921 i_insert_IDLE : ROM32X1
925 O => insert_IDLE,
-- ROM output
926 A0 => RX_FIFO_WA_RA_D
(0),
-- ROM address[0]
927 A1 => RX_FIFO_WA_RA_D
(1),
-- ROM address[1]
928 A2 => RX_FIFO_WA_RA_D
(2),
-- ROM address[2]
929 A3 => RX_FIFO_WA_RA_D
(3),
-- ROM address[3]
930 A4 => '0'
-- ROM address[4]
932 g_RX_FIFO: for i in 0 to 36 generate
935 INIT => RxIdle
(i
)) -- Initial contents of RAM
937 DPO => RX_FIFO_DO
(i
),
-- Read-only 1-bit data output
938 SPO =>
open,
-- R/W 1-bit data output
939 A0 => RX_FIFO_WA
(0),
-- R/W address[0] input
940 A1 => RX_FIFO_WA
(1),
-- R/W address[1] input
941 A2 => RX_FIFO_WA
(2),
-- R/W address[2] input
942 A3 => RX_FIFO_WA
(3),
-- R/W address[3] input
943 A4 => '0',
-- R/W address[4] input
944 D => RX_FIFO_DI
(i
),
-- Write 1-bit data input
945 DPRA0 => RX_FIFO_RA
(0),
-- Read-only address[0] input
946 DPRA1 => RX_FIFO_RA
(1),
-- Read-only address[1] input
947 DPRA2 => RX_FIFO_RA
(2),
-- Read-only address[2] input
948 DPRA3 => RX_FIFO_RA
(3),
-- Read-only address[3] input
949 DPRA4 => ec_RX_FIFO_RAn,
-- Read-only address[4] input
950 WCLK => RXUSRCLK,
-- Write clock input
951 WE => RX_FIFO_WE
-- Write enable input
954 -- add or remove idle(Ordered set) will be decided at the RX_FIFO write side
957 if(clk2x'event and clk2x = '1')then
958 ec_RX_FIFO_RAn <= RX_FIFO_DO(36);
960 RX_FIFO_RA <= (others => '0');
961 RX_FIFO_RA_G <= (others => '0');
963 if(ec_RX_FIFO_RAn = '0')then
964 RX_FIFO_RA <= RX_FIFO_RA +1;
966 RX_FIFO_RA_G(3) <= RX_FIFO_RA(3);
967 RX_FIFO_RA_G(2) <= RX_FIFO_RA(3) xor RX_FIFO_RA(2);
968 RX_FIFO_RA_G(1) <= RX_FIFO_RA(2) xor RX_FIFO_RA(1);
969 RX_FIFO_RA_G(0) <= RX_FIFO_RA(1) xor RX_FIFO_RA(0);
971 PhyEmacRxC <= RX_FIFO_DO(3 downto 0);
972 PhyEmacRxD <= RX_FIFO_DO(35 downto 4);