AMC13
Firmwares for the different applications of the AMC13 uTCA board made at Boston University
 All Classes Variables
DaqLSCXG.vhd
1 
2 library IEEE;
3 use IEEE.STD_LOGIC_1164.ALL;
4 use ieee.std_logic_unsigned.all;
5 use work.amc13_pack.all;
6 use work.mydefs.all;
7 
8 
9 library UNISIM;
10 use UNISIM.VComponents.all;
11 
12 entity DaqLSCXG is
13  Port ( sys_reset : in STD_LOGIC; -- active high reset of all logic but GTX
14  sys_clk : in STD_LOGIC;
15  sfp_pd : in array3x2;
16  DRP_clk : in STD_LOGIC;
17  LinkWe : in STD_LOGIC_VECTOR (2 downto 0);
18  LinkCtrl : in STD_LOGIC_VECTOR (2 downto 0);
19  LinkData : in array3x64;
20  srcID : in array3x16;
21  LinkDown : out STD_LOGIC_VECTOR (2 downto 0);
22  LinkFull : out STD_LOGIC_VECTOR (2 downto 0);
23  --
24 -- ack_cnt : out STD_LOGIC_VECTOR (2 downto 0); -- 1 ck pulse (txusrclk) indicating a received acknowledge
25 -- pckt_cnt : out STD_LOGIC_VECTOR (2 downto 0); -- 1 ck pulse (txusrclk) indicating a transmit packet
26 -- retransmit_cnt : out STD_LOGIC_VECTOR (2 downto 0); -- 1 ck pulse (txusrclk) indicating a retransmit packet
27 -- event_cnt : out STD_LOGIC_VECTOR (2 downto 0); -- 1 ck pulse (sys_clk) indicating a sent event
28  sync_loss : out STD_LOGIC_VECTOR (2 downto 0); -- goes to '1' (rxusrclk) when SERDES is out of synch
29  status_ce : in std_logic_VECTOR (2 downto 0); -- not implemented yet
30  status_addr : in STD_LOGIC_VECTOR (15 downto 0); -- not implemented yet
31  status_port : out array3x64; -- first 32 bits are hard-wired
32  --
33  txusrclk_o : out STD_LOGIC; -- reconstructed tx clock, to be used to clock sending circuitry
34  rxusrclk_o : out STD_LOGIC; -- reconstructed rx clock, to be used to clock receiving circuitry
35  --
36  gtx_reset : in std_logic; -- full reset of GTX only
37  gtx_refclk : in std_logic; -- iob for refclk neg
38  sfp_rxn : in std_logic_VECTOR (2 downto 0); -- sfp iobs
39  sfp_rxp : in std_logic_VECTOR (2 downto 0);
40  sfp_txn : out std_logic_VECTOR (2 downto 0);
41  sfp_txp : out std_logic_VECTOR (2 downto 0)
42  );
43 end DaqLSCXG;
44 
45 architecture Behavioral of DaqLSCXG is
46 
47 -- Local signals
48 
49 signal gtx_txfsmresetdone : std_logic_vector(2 downto 0);
50 signal gtx_rxfsmresetdone : std_logic_vector(2 downto 0);
51 signal gtx_data_valid: std_logic_vector(2 downto 0);
52 signal sys_reset_bar : std_logic;
53 signal txusrclk, txusrclk2 : std_logic;
54 --signal txdll_locked, rxdll_locked, dll_reset, rxdll_reset, txdll_reset, txplllkdet, rxplllkdet: std_logic;
55 --signal txclkfromserdes, rxclkfromserdes, rxclkfromserdes_bufg : std_logic;
56 signal serdes_in_sync : std_logic_vector(2 downto 0);
57 signal txdata, rxdata : array3x32;
58 signal rxcharisk, txcharisk, rxchariscomma, gtx_rxnotintable : array3x4;
59 --signal rxlossofsync : std_logic_vector(1 downto 0);
60 --signal rxbufstatus : std_logic_vector(2 downto 0);
61 signal rxbyteisaligned, rxenrealign, rxbyterealign, rxcommadet : std_logic_vector(2 downto 0);
62 --signal gtxrefclk, drp_clk : std_logic;
63 signal gtx_cpllfbclklost, gtx_cplllock, gtx_cpllrefclklost : std_logic;
64 signal gtx_rxresetdone, gtx_txresetdone : std_logic_vector(2 downto 0);
65 signal gtx_qpllrefclklost : std_logic;
66 signal gtx_qplllock : std_logic;
67 
68 signal gtx_rxbyteisaligned_is_stable : std_logic_vector(2 downto 0);
69 signal gtx_rxcdrlock : std_logic_vector(2 downto 0);
70 signal stable_count : array3x16 ;
71 signal data_valid_cnt : array3x9 ;
72 signal serdes_status : array3x32 := (others => (others => '0'));
73 
74 COMPONENT SLINK_opt
75  PORT(
76  reset : IN std_logic;
77  SYS_CLK : IN std_logic;
78  LINKWe : IN std_logic;
79  LINKCtrl : IN std_logic;
80  LINKData : IN std_logic_vector(63 downto 0);
81  src_ID : IN std_logic_vector(15 downto 0);
82  inject_err : IN std_logic_vector(17 downto 0);
83  read_CE : IN std_logic;
84  Addr : IN std_logic_vector(15 downto 0);
85  clock : IN std_logic;
86  serdes_init : IN std_logic;
87  clock_r : IN std_logic;
88  SD_Data_i : IN std_logic_vector(31 downto 0);
89  SD_Kb_i : IN std_logic_vector(3 downto 0);
90  status_data : OUT std_logic_vector(63 downto 0);
91  LINKDown : OUT std_logic;
92  LINK_LFF : OUT std_logic;
93  SD_Data_o : OUT std_logic_vector(31 downto 0);
94  SD_Kb_o : OUT std_logic_vector(3 downto 0);
95  Serdes_status : in std_logic_vector(31 downto 0)
96 -- ack_cnt : OUT std_logic;
97 -- pckt_cnt : OUT std_logic;
98 -- retransmit : OUT std_logic;
99 -- cnt_evt : OUT std_logic
100  );
101 END COMPONENT;
102 
103 COMPONENT serdes5_wrapper
104  PORT(
105  refclk : IN std_logic;
106  DRPclk : IN std_logic;
107  sfp_pd : IN array3x2;
108  txusrclk_out : OUT std_logic;
109  qplllock : OUT std_logic;
110  gtx_reset : IN std_logic;
111  data_valid : IN std_logic_vector(2 downto 0);
112  sfp_rxp : IN std_logic_vector(2 downto 0);
113  sfp_rxn : IN std_logic_vector(2 downto 0);
114  rxmcommaalignen : IN std_logic_vector(2 downto 0);
115  rxpcommaalignen : IN std_logic_vector(2 downto 0);
116  txcharisk : IN array3x4;
117  txdata : IN array3x32;
118  txfsmresetdone : OUT std_logic_vector(2 downto 0);
119  rxfsmresetdone : OUT std_logic_vector(2 downto 0);
120  rxcdrlock : OUT std_logic_vector(2 downto 0);
121  rxnotintable : OUT array3x4;
122  rxbyteisaligned : OUT std_logic_vector(2 downto 0);
123  rxbyterealign : OUT std_logic_vector(2 downto 0);
124  rxcommadet : OUT std_logic_vector(2 downto 0);
125  rxchariscomma : OUT array3x4;
126  rxcharisk : OUT array3x4;
127  rxresetdone : OUT std_logic_vector(2 downto 0);
128  txresetdone : OUT std_logic_vector(2 downto 0);
129  rxdata : OUT array3x32;
130  sfp_txp : OUT std_logic_vector(2 downto 0);
131  sfp_txn : OUT std_logic_vector(2 downto 0)
132  );
133 END COMPONENT;
134 
135 begin
136 txusrclk2 <= txusrclk;
137 g_SLINK_opt : for i in 0 to 2 generate
138  Inst_SLINK_opt: SLINK_opt
139  PORT MAP(
140 
141 -- FROM FED logic
142  reset => sys_reset_bar, -- needs an active low reset
143  SYS_CLK => sys_clk,
144 
145 
146 -- DATA interface from FED
147 
148 
149  LINKWe => not LinkWe (i),
150  LINKCtrl => LinkCtrl(i),
151  LINKData => LinkData(i),
152  src_ID => srcID(i),
153  inject_err => (others =>'0'),
154  read_CE => '0',
155  Addr => status_addr,
156  status_data => status_port(i),
157  LINKDown => LinkDown(i),
158  LINK_LFF => LinkFull(i),
159 
160 -- SERDES interface
161 
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 bit)
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 bit
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)
171 
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
176 );
177 end generate;
178 i_serdes5_wrapper: serdes5_wrapper PORT MAP(
179  refclk => gtx_refclk,
180  DRPclk => DRP_clk,
181  sfp_pd => sfp_pd ,
182  txusrclk_out => txusrclk,
183  qplllock => gtx_qplllock,
184  gtx_reset => gtx_reset,
185  data_valid => gtx_data_valid,
186  sfp_rxp => sfp_rxp,
187  sfp_rxn => sfp_rxn,
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,
202  txdata => txdata,
203  rxdata => rxdata,
204  sfp_txp => sfp_txp,
205  sfp_txn => sfp_txn
206  );
207 
208 
209 txusrclk_o <= txusrclk;
210 rxusrclk_o <= txusrclk;
211 sys_reset_bar <= not(sys_reset);
212 
213 
214 
215 process (txusrclk)
216 begin
217  if txusrclk='1' and txusrclk'event then
218  for i in 0 to 2 loop
219  if rxbyteisaligned(i)='0' then
220  stable_count(i) <= (others => '0');
221  gtx_rxbyteisaligned_is_stable(i) <='0';
222  else
223  stable_count(i) <= stable_count(i) + 1;
224  if stable_count(i) = x"ffff" then
225  gtx_rxbyteisaligned_is_stable(i) <= '1';
226  end if;
227  end if;
228 
229  if(gtx_rxnotintable(i) /= x"0")then
230  gtx_data_valid(i) <= '0';
231  data_valid_cnt(i) <= (others => '0');
232  else
233  if(data_valid_cnt(i)(8) = '1')then
234  gtx_data_valid(i) <= '1';
235  else
236  data_valid_cnt(i) <= data_valid_cnt(i) + 1;
237  end if;
238  end if;
239  end loop;
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);
243  end if;
244 end process;
245 
246 
247 --serdes_in_sync <= gtx_rxfsmresetdone and gtx_txfsmresetdone and gtx_rxcdrlock_is_stable;
248 --
249 --sync_loss <= not(serdes_in_sync);
250 --
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);
257 
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);
262 
263  serdes_status(i)(11 downto 8) <= rxchariscomma(i);
264  serdes_status(i)(15 downto 12) <= rxcharisk(i);
265 
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');
270 end generate;
271 gtx_cpllfbclklost <= '0';
272 gtx_cplllock <= '1';
273 gtx_cpllrefclklost <= '0';
274 gtx_qpllrefclklost <= '0';
275 
276 
277 
278 end Behavioral;
279