Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad-fmcadc4-ebz/ad_fmcadc4_ebz.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad_fmcadc4_ebz.c
3 * @brief Implementation of Main Function.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2015(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39
40 /******************************************************************************/
41 /***************************** Include Files **********************************/
42 /******************************************************************************/
43 #include <xparameters.h>
44 #include <xil_io.h>
45 #include "platform_drivers.h"
46 #include "ad9528.h"
47 #include "ad9680.h"
48 #include "adc_core.h"
49 #include "jesd204b_gt.h"
50 #include "jesd204b_v51.h"
51 #include <xgpiops.h>
52 #include <xspips.h>
53
54 /******************************************************************************/
55 /********************** Macros and Constants Definitions **********************/
56 /******************************************************************************/
57 #define GPIO_DEVICE_ID XPAR_PS7_GPIO_0_DEVICE_ID
58 #define GPIO_OFFSET 54 + 32
59 #define SPI_DEVICE_ID XPAR_PS7_SPI_0_DEVICE_ID
60 #define ADC_DDR_BASEADDR XPAR_DDR_MEM_BASEADDR + 0x800000
61 #define AD9680_CORE_0_BASEADDR XPAR_AXI_AD9680_CORE_0_BASEADDR
62 #define AD9680_CORE_1_BASEADDR XPAR_AXI_AD9680_CORE_1_BASEADDR
63 #define AD9680_DMA_BASEADDR XPAR_AXI_AD9680_DMA_BASEADDR
64 #define AD9680_JESD_BASEADDR XPAR_AXI_AD9680_JESD_BASEADDR
65 #define FMCADC4_GT_BASEADDR XPAR_AXI_FMCADC4_GT_BASEADDR
66 #define GPIO_AD9528_RSTN GPIO_OFFSET + 0
67 #define GPIO_AD9528_STATUS GPIO_OFFSET + 1
68 #define GPIO_AD9680_1_FDA GPIO_OFFSET + 2
69 #define GPIO_AD9680_1_FDB GPIO_OFFSET + 3
70 #define GPIO_AD9680_2_FDA GPIO_OFFSET + 4
71 #define GPIO_AD9680_2_FDB GPIO_OFFSET + 5
72
73 /******************************************************************************/
74 /************************ Variables Definitions *******************************/
75 /******************************************************************************/
76 extern uint8_t spi_decoded_cs;
77
78 struct ad9528_channel_spec ad9528_channels[] =
79 {
80 {
81 1, // channel_num
82 0, // sync_ignore_en
83 0, // output_dis
84 DRIVER_MODE_LVDS, // driver_mode
85 SOURCE_VCO, // signal_source
86 0, // divider_phase
87 2, // channel_divider
88 "FPGA", // extended_name
89 },
90
91 {
92 2, // channel_num
93 0, // sync_ignore_en
94 0, // output_dis
95 DRIVER_MODE_LVDS, // driver_mode
96 SOURCE_SYSREF_VCO, // signal_source
97 0, // divider_phase
98 1, // channel_divider
99 "ADC2-sysref", // extended_name
100 },
101
102 {
103 3, // channel_num
104 0, // sync_ignore_en
105 0, // output_dis
106 DRIVER_MODE_LVDS, // driver_mode
107 SOURCE_VCO, // signal_source
108 0, // divider_phase
109 1, // channel_divider
110 "ADC2", // extended_name
111 },
112
113 {
114 8, // channel_num
115 0, // sync_ignore_en
116 0, // output_dis
117 DRIVER_MODE_LVDS, // driver_mode
118 SOURCE_VCO, // signal_source
119 0, // divider_phase
120 1, // channel_divider
121 "ADC1", // extended_name
122 },
123
124 {
125 9, // channel_num
126 0, // sync_ignore_en
127 0, // output_dis
128 DRIVER_MODE_LVDS, // driver_mode
129 SOURCE_SYSREF_VCO, // signal_source
130 0, // divider_phase
131 1, // channel_divider
132 "ADC1-sysref", // extended_name
133 },
134
135 {
136 13, // channel_num
137 0, // sync_ignore_en
138 0, // output_dis
139 DRIVER_MODE_LVDS, // driver_mode
140 SOURCE_SYSREF_VCO, // signal_source
141 0, // divider_phase
142 1, // channel_divider
143 "FPGA-sysref", // extended_name
144 },
145 };
146
147 struct ad9528_platform_data ad9528_pdata_lpc =
148 {
149 80000000, // vcxo_freq
150 1, // spi3wire
151
152 /* REFA / REFB input configuration */
153 0, // refa_en
154 0, // refb_en
155
156 /* Differential/ Single-Ended Input Configuration */
157 1, // refa_diff_rcv_en
158 0, // refb_diff_rcv_en
159 0, // osc_in_diff_en
160
161 /*
162 * Valid if differential input disabled
163 * if false defaults to pos input
164 */
165 0, // refa_cmos_neg_inp_en
166 0, // refb_cmos_neg_inp_en
167 1, // osc_in_cmos_neg_inp_en
168
169 /* PLL1 Setting */
170 1, // refa_r_div
171 1, // refb_r_div
172 8, // pll1_feedback_div
173 1, // pll1_feedback_src_vcxo
174 10000, // pll1_charge_pump_current_nA
175 0, // pll1_bypass_en
176
177 /* Reference */
178 REF_MODE_STAY_ON_REFB, // ref_mode
179 SYSREF_SRC_INTERNAL, // sysref_src
180 20, // sysref_k_div
181
182 /* PLL2 Setting */
183 805000, // pll2_charge_pump_current_nA
184 0, // pll2_ndiv_a_cnt
185 25, // pll2_ndiv_b_cnt
186 0, // pll2_freq_doubler_en
187 2, // pll2_r1_div
188 25, // pll2_n2_div
189 4, // pll2_vco_diff_m1 /* 3..5 */
190
191 /* Loop Filter PLL2 */
192 RPOLE2_900_OHM, // rpole2
193 RZERO_3250_OHM, // rzero
194 CPOLE1_16_PF, // cpole1
195 0, // rzero_bypass_en;
196
197 /* Output Channel Configuration */
198 ARRAY_SIZE(ad9528_channels), // num_channels
199 ad9528_channels, // *channels
200 };
201
202 ad9528_init_param default_ad9528_init_param = {
203 0, // spi_chip_select
204 SPI_MODE_3, // spi_mode
205 #ifdef _XPARAMETERS_PS_H_
206 PS7_SPI, // spi_type
207 #else
208 AXI_SPI, // spi_type
209 #endif
210 SPI_DEVICE_ID, // spi_device_id;
211 };
212
213 ad9680_init_param default_ad9680_init_param = {
214 1, // spi_chip_select
215 SPI_MODE_3, // spi_mode
216 #ifdef _XPARAMETERS_PS_H_
217 PS7_SPI, // spi_type
218 #else
219 AXI_SPI, // spi_type
220 #endif
221 SPI_DEVICE_ID, // spi_device_id;
222 };
223
224 /***************************************************************************//**
225 * @brief adc4_gpio_ctl
226 *******************************************************************************/
227 void adc4_gpio_ctl(void)
228 {
229 gpio_device dev;
230
231 #ifdef _XPARAMETERS_PS_H_
232 dev.type = PS7_GPIO;
233 #else
234 dev.type = AXI_GPIO;
235 #endif
236 dev.device_id = GPIO_DEVICE_ID;
237
238 gpio_init(&dev);
239
240 gpio_set_direction(&dev, GPIO_AD9528_RSTN, GPIO_OUT);
241 gpio_set_direction(&dev, GPIO_AD9528_STATUS, GPIO_OUT);
242 gpio_set_direction(&dev, GPIO_AD9680_1_FDA, GPIO_IN);
243 gpio_set_direction(&dev, GPIO_AD9680_1_FDB, GPIO_IN);
244 gpio_set_direction(&dev, GPIO_AD9680_2_FDA, GPIO_IN);
245 gpio_set_direction(&dev, GPIO_AD9680_2_FDB, GPIO_IN);
246
247 gpio_set_value(&dev, GPIO_AD9528_STATUS, 0);
248 gpio_set_value(&dev, GPIO_AD9528_RSTN, 0);
249 mdelay(10);
250
251 gpio_set_value(&dev, GPIO_AD9528_RSTN, 1);
252 mdelay(10);
253 }
254
255 jesd204b_state jesd204b_st = {
256 1, // lanesync_enable
257 1, // scramble_enable
258 0, // sysref_always_enable
259 32, // frames_per_multiframe
260 1, // bytes_per_frame
261 1, // subclass
262 };
263
264 jesd204b_gt_link gt_link = {
265 FMCADC4_GT_BASEADDR, // gt_core_addr
266 JESD204B_GT_RX, // tx_or_rx
267 0, // first_lane
268 7, // last_lane
269 JESD204B_GT_QPLL, // qpll_or_cpll
270 JESD204B_GT_DFE, // lpm_or_dfe
271 500, // ref_clk
272 1000, // lane_rate
273 JESD204B_GT_SYSREF_INT, // sysref_int_or_ext
274 3, // sys_clk_sel
275 4, // out_clk_sel
276 0, // gth_or_gtx
277 };
278
279 /***************************************************************************//**
280 * @brief main
281 *******************************************************************************/
282 int main(void)
283 {
284 adc_core ad9680_0_core;
285 adc_core ad9680_1_core;
286 ad9528_dev *ad9528_device;
287 ad9680_dev *ad9680_0_device;
288 ad9680_dev *ad9680_1_device;
289
290 adc4_gpio_ctl();
291
292 spi_decoded_cs = 1;
293
294 #ifdef MODE_1_24G
295 ad9528_pdata_lpc.pll2_ndiv_a_cnt = 1;
296 ad9528_pdata_lpc.pll2_ndiv_b_cnt = 23;
297 ad9528_pdata_lpc.pll2_n2_div = 31;
298 ad9528_pdata_lpc.pll2_vco_diff_m1 = 3;
299 #endif
300
301 ad9528_setup(&ad9528_device, default_ad9528_init_param, ad9528_pdata_lpc);
302
303 jesd204b_gt_initialize(gt_link);
304
305 default_ad9680_init_param.spi_chip_select = 1;
306 ad9680_setup(&ad9680_0_device, default_ad9680_init_param);
307
308 default_ad9680_init_param.spi_chip_select = 2;
309 ad9680_setup(&ad9680_1_device, default_ad9680_init_param);
310
311 jesd204b_setup(AD9680_JESD_BASEADDR, jesd204b_st);
312
313 jesd204b_gt_setup(gt_link);
314 jesd204b_gt_en_sync_sysref(gt_link);
315
316 ad9680_0_core.adc_baseaddr = AD9680_CORE_0_BASEADDR;
317 ad9680_0_core.dmac_baseaddr = AD9680_DMA_BASEADDR;
318 ad9680_0_core.no_of_channels = 2;
319 ad9680_0_core.resolution = 14;
320 adc_setup(ad9680_0_core);
321
322 ad9680_1_core.adc_baseaddr = AD9680_CORE_1_BASEADDR;
323 ad9680_1_core.dmac_baseaddr = 0;
324 ad9680_1_core.no_of_channels = 2;
325 ad9680_1_core.resolution = 14;
326 adc_setup(ad9680_1_core);
327
328 ad9680_spi_write(ad9680_0_device, AD9680_REG_DEVICE_INDEX, 0x3);
329 ad9680_spi_write(ad9680_0_device, AD9680_REG_ADC_TEST_MODE, 0x05);
330 ad9680_spi_write(ad9680_0_device, AD9680_REG_OUTPUT_MODE, 0);
331 ad9680_spi_write(ad9680_1_device, AD9680_REG_DEVICE_INDEX, 0x3);
332 ad9680_spi_write(ad9680_1_device, AD9680_REG_ADC_TEST_MODE, 0x05);
333 ad9680_spi_write(ad9680_1_device, AD9680_REG_OUTPUT_MODE, 0);
334
335 adc_pn_mon(ad9680_0_core, ADC_PN23A);
336 adc_pn_mon(ad9680_1_core, ADC_PN23A);
337
338 xil_printf("Initialization done.\n\r");
339
340 ad9680_spi_write(ad9680_0_device, AD9680_REG_DEVICE_INDEX, 0x3);
341 ad9680_spi_write(ad9680_0_device, AD9680_REG_ADC_TEST_MODE, 0x0F);
342 ad9680_spi_write(ad9680_0_device, AD9680_REG_OUTPUT_MODE, 0x1);
343
344 ad9680_spi_write(ad9680_1_device, AD9680_REG_DEVICE_INDEX, 0x3);
345 ad9680_spi_write(ad9680_1_device, AD9680_REG_ADC_TEST_MODE, 0x0F);
346 ad9680_spi_write(ad9680_1_device, AD9680_REG_OUTPUT_MODE, 0x1);
347
348 adc_capture(ad9680_0_core, 32768, ADC_DDR_BASEADDR);
349
350 xil_printf("Ramp capture done.\n");
351
352 return 0;
353 }