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