3 use IEEE.STD_LOGIC_1164.
ALL;
4 use ieee.std_logic_unsigned.
all;
10 use UNISIM.VComponents.
all;
13 Port ( sys_reset : in ;
-- active high reset of all logic but GTX
17 LinkWe : in (2 downto 0);
18 LinkCtrl : in (2 downto 0);
19 LinkData : in array3x64;
21 LinkDown : out (2 downto 0);
22 LinkFull : out (2 downto 0);
24 -- ack_cnt : out (2 downto 0); --
1 ck pulse (txusrclk) indicating a received acknowledge
25 -- pckt_cnt : out (2 downto 0); --
1 ck pulse (txusrclk) indicating a transmit packet
26 -- retransmit_cnt : out (2 downto 0); --
1 ck pulse (txusrclk) indicating a retransmit packet
27 -- event_cnt : out (2 downto 0); --
1 ck pulse (sys_clk) indicating a sent event
28 sync_loss : out (2 downto 0);
-- goes to '1' (rxusrclk) when SERDES is out of synch
29 status_ce : in (2 downto 0);
-- not implemented yet
30 status_addr : in (15 downto 0);
-- not implemented yet
31 status_port : out array3x64;
-- first 32 bits are hard-wired
33 txusrclk_o : out ;
-- reconstructed tx clock, to be used to clock sending circuitry
34 rxusrclk_o : out ;
-- reconstructed rx clock, to be used to clock receiving circuitry
36 gtx_reset : in ;
-- full reset of GTX only
37 gtx_refclk : in ;
-- iob for refclk neg
38 sfp_rxn : in (2 downto 0);
-- sfp iobs
39 sfp_rxp : in (2 downto 0);
40 sfp_txn : out (2 downto 0);
41 sfp_txp : out (2 downto 0)
49 signal gtx_txfsmresetdone : (2 downto 0);
50 signal gtx_rxfsmresetdone : (2 downto 0);
51 signal gtx_data_valid: (2 downto 0);
52 signal sys_reset_bar : ;
53 signal txusrclk, txusrclk2 : ;
54 --signal txdll_locked, rxdll_locked, dll_reset, rxdll_reset, txdll_reset, txplllkdet, rxplllkdet: ;
55 --signal txclkfromserdes, rxclkfromserdes, rxclkfromserdes_bufg : ;
56 signal serdes_in_sync : (2 downto 0);
57 signal txdata, rxdata : array3x32;
58 signal rxcharisk, txcharisk, rxchariscomma, gtx_rxnotintable : array3x4;
59 --signal rxlossofsync : (1 downto 0);
60 --signal rxbufstatus : (2 downto 0);
61 signal rxbyteisaligned, rxenrealign, rxbyterealign, rxcommadet : (2 downto 0);
62 --signal gtxrefclk, drp_clk : ;
63 signal gtx_cpllfbclklost, gtx_cplllock, gtx_cpllrefclklost : ;
64 signal gtx_rxresetdone, gtx_txresetdone : (2 downto 0);
65 signal gtx_qpllrefclklost : ;
66 signal gtx_qplllock : ;
68 signal gtx_rxbyteisaligned_is_stable : (2 downto 0);
69 signal gtx_rxcdrlock : (2 downto 0);
70 signal stable_count : array3x16 ;
71 signal data_valid_cnt : array3x9 ;
72 signal serdes_status : array3x32 := (others => (others => '0'));
80 LINKData :
IN (
63 downto 0);
81 src_ID :
IN (
15 downto 0);
82 inject_err :
IN (
17 downto 0);
84 Addr :
IN (
15 downto 0);
88 SD_Data_i :
IN (
31 downto 0);
89 SD_Kb_i :
IN (
3 downto 0);
90 status_data :
OUT (
63 downto 0);
93 SD_Data_o :
OUT (
31 downto 0);
94 SD_Kb_o :
OUT (
3 downto 0);
95 Serdes_status :
in (
31 downto 0)
107 sfp_pd :
IN array3x2;
111 data_valid :
IN (
2 downto 0);
112 sfp_rxp :
IN (
2 downto 0);
113 sfp_rxn :
IN (
2 downto 0);
114 rxmcommaalignen :
IN (
2 downto 0);
115 rxpcommaalignen :
IN (
2 downto 0);
116 txcharisk :
IN array3x4;
117 txdata :
IN array3x32;
118 txfsmresetdone :
OUT (
2 downto 0);
119 rxfsmresetdone :
OUT (
2 downto 0);
120 rxcdrlock :
OUT (
2 downto 0);
121 rxnotintable :
OUT array3x4;
122 rxbyteisaligned :
OUT (
2 downto 0);
123 rxbyterealign :
OUT (
2 downto 0);
124 rxcommadet :
OUT (
2 downto 0);
125 rxchariscomma :
OUT array3x4;
126 rxcharisk :
OUT array3x4;
127 rxresetdone :
OUT (
2 downto 0);
128 txresetdone :
OUT (
2 downto 0);
129 rxdata :
OUT array3x32;
130 sfp_txp :
OUT (
2 downto 0);
131 sfp_txn :
OUT (
2 downto 0)
136 txusrclk2 <= txusrclk;
137 g_SLINK_opt : for i in 0 to 2 generate
142 reset => sys_reset_bar,
-- needs an active low reset
146 -- DATA interface from FED
149 LINKWe =>
not LinkWe
(i
),
150 LINKCtrl => LinkCtrl
(i
),
151 LINKData => LinkData
(i
),
153 inject_err =>
(others =>'0'
),
156 status_data => status_port
(i
),
157 LINKDown => LinkDown
(i
),
158 LINK_LFF => LinkFull
(i
),
162 clock => txusrclk2,
-- clk tx from SERDES
163 serdes_init => serdes_in_sync
(i
),
-- status that comes back from GTX
164 SD_Data_o => TXDATA
(i
),
-- data sent to serdes (32 )
165 SD_Kb_o => TXCHARISK
(i
),
-- control K associated to SD_Data_o (4 bits)
166 clock_r => txusrclk2,
-- reconstructed clock from SERDES
167 SD_Data_i => RXDATA
(i
),
-- return data from SERDES 32
168 SD_Kb_i => RXCHARISK
(i
),
-- return control K associated to SD_Data_i (4 bits)
169 serdes_status => serdes_status
(i
)
170 -- Status for user logic (to be removed later)
172 -- ack_cnt => ack_cnt(i), -- pulse indicating a received acknoledge
173 -- pckt_cnt => pckt_cnt(i), -- pulse indicating a transmit packet
174 -- retransmit => retransmit_cnt(i), -- pulse indicating a retransmit packet
175 -- cnt_evt => event_cnt(i) -- pulse indicating a sent event
179 refclk => gtx_refclk,
182 txusrclk_out => txusrclk,
183 qplllock => gtx_qplllock,
184 gtx_reset => gtx_reset,
185 data_valid => gtx_data_valid,
188 txfsmresetdone => gtx_txfsmresetdone,
189 rxfsmresetdone => gtx_rxfsmresetdone,
190 rxcdrlock => gtx_rxcdrlock,
191 rxnotintable => gtx_rxnotintable,
192 rxmcommaalignen => rxenrealign,
193 rxpcommaalignen => rxenrealign,
194 rxbyteisaligned => rxbyteisaligned,
195 rxbyterealign => rxbyterealign,
196 rxcommadet => rxcommadet,
197 rxchariscomma => rxchariscomma,
198 rxcharisk => rxcharisk,
199 rxresetdone => gtx_rxresetdone,
200 txresetdone => gtx_txresetdone,
201 txcharisk => txcharisk,
209 txusrclk_o <= txusrclk;
210 rxusrclk_o <= txusrclk;
211 sys_reset_bar <= not(sys_reset);
217 if txusrclk='1' and txusrclk'event then
219 if rxbyteisaligned(i)='0' then
220 stable_count(i) <= (others => '0');
221 gtx_rxbyteisaligned_is_stable(i) <='0';
223 stable_count(i) <= stable_count(i) + 1;
224 if stable_count(i) = x"ffff" then
225 gtx_rxbyteisaligned_is_stable(i) <= '1';
229 if(gtx_rxnotintable(i) /= x"0")then
230 gtx_data_valid(i) <= '0';
231 data_valid_cnt(i) <= (others => '0');
233 if(data_valid_cnt(i)(8) = '1')then
234 gtx_data_valid(i) <= '1';
236 data_valid_cnt(i) <= data_valid_cnt(i) + 1;
240 serdes_in_sync <= gtx_rxfsmresetdone and gtx_txfsmresetdone and gtx_rxbyteisaligned_is_stable;
241 sync_loss <= not(serdes_in_sync);
242 rxenrealign <= not(rxbyteisaligned);
247 --serdes_in_sync <= gtx_rxfsmresetdone and gtx_txfsmresetdone and gtx_rxcdrlock_is_stable;
249 --sync_loss <= not(serdes_in_sync);
251 --rxenrealign <= not(rxbyteisaligned);
252 g_status : for i in 0 to 2 generate
253 serdes_status(i)(0) <= gtx_qplllock;
254 serdes_status(i)(1) <= gtx_qpllrefclklost;
255 serdes_status(i)(2) <= gtx_txresetdone(i);
256 serdes_status(i)(3) <= gtx_rxresetdone(i);
258 serdes_status(i)(4) <= gtx_rxcdrlock(i);
259 serdes_status(i)(5) <= rxbyteisaligned(i);
260 serdes_status(i)(6) <= rxbyterealign(i);
261 serdes_status(i)(7) <= rxcommadet(i);
263 serdes_status(i)(11 downto 8) <= rxchariscomma(i);
264 serdes_status(i)(15 downto 12) <= rxcharisk(i);
266 serdes_status(i)(16) <= gtx_cpllfbclklost;
267 serdes_status(i)(17) <= gtx_cplllock;
268 serdes_status(i)(18) <= gtx_cpllrefclklost;
269 serdes_status(i)(31 downto 19) <= (others => '0');
271 gtx_cpllfbclklost <= '0';
273 gtx_cpllrefclklost <= '0';
274 gtx_qpllrefclklost <= '0';