Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad6676-ebz/ad6676_ebz.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad6676_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 "ad6676.h"
47 #include "adc_core.h"
48 #include "adxcvr_core.h"
49
50 /******************************************************************************/
51 /********************** Macros and Constants Definitions **********************/
52 /******************************************************************************/
53 #ifdef _XPARAMETERS_PS_H_
54 #define SPI_DEVICE_ID XPAR_PS7_SPI_0_DEVICE_ID
55 #define GPIO_DEVICE_ID XPAR_PS7_GPIO_0_DEVICE_ID
56 #define GPIO_OFFSET 54 + 32
57 #define ADC_DDR_BASEADDR XPAR_PS7_DDR_0_S_AXI_BASEADDR + 0x800000
58 #else
59 #define SPI_DEVICE_ID XPAR_SPI_0_DEVICE_ID
60 #define GPIO_DEVICE_ID XPAR_GPIO_0_DEVICE_ID
61 #define GPIO_OFFSET 32
62 #define ADC_DDR_BASEADDR XPAR_AXI_DDR_CNTRL_BASEADDR + 0x800000
63 #endif
64 #define AD6676_CORE_BASEADDR XPAR_AXI_AD6676_CORE_BASEADDR
65 #define AD6676_DMA_BASEADDR XPAR_AXI_AD6676_DMA_BASEADDR
66 #define AD6676_JESD_BASEADDR XPAR_AXI_AD6676_JESD_BASEADDR
67 #define AD6676_ADXCVR_BASEADDR XPAR_AXI_AD6676_XCVR_BASEADDR
68 #define GPIO_ADC_OEN GPIO_OFFSET + 9
69 #define GPIO_ADC_SELA GPIO_OFFSET + 8
70 #define GPIO_ADC_SELB GPIO_OFFSET + 7
71 #define GPIO_ADC_S0 GPIO_OFFSET + 6
72 #define GPIO_ADC_S1 GPIO_OFFSET + 5
73 #define GPIO_ADC_RESETB GPIO_OFFSET + 4
74 #define GPIO_ADC_AGC1 GPIO_OFFSET + 3
75 #define GPIO_ADC_AGC2 GPIO_OFFSET + 2
76 #define GPIO_ADC_AGC3 GPIO_OFFSET + 1
77 #define GPIO_ADC_AGC4 GPIO_OFFSET + 0
78
79 #define GPIO_JESD204_SYSREF GPIO_OFFSET + 16
80
81 /******************************************************************************/
82 /************************ Variables Definitions *******************************/
83 /******************************************************************************/
84 ad6676_init_param default_init_param = {
85 /* GPIO */
86 #ifdef _XPARAMETERS_PS_H_
87 PS7_GPIO, // gpio_type;
88 #else
89 AXI_GPIO, // gpio_type
90 #endif
91 GPIO_DEVICE_ID, // gpio_device_id
92 GPIO_ADC_OEN, // gpio_adc_oen
93 GPIO_ADC_SELA, // gpio_adc_sela
94 GPIO_ADC_SELB, // gpio_adc_selb
95 GPIO_ADC_S0, // gpio_adc_s0
96 GPIO_ADC_S1, // gpio_adc_s1
97 GPIO_ADC_RESETB, // gpio_adc_resetb
98 GPIO_ADC_AGC1, // gpio_adc_agc1
99 GPIO_ADC_AGC2, // gpio_adc_agc2
100 GPIO_ADC_AGC3, // gpio_adc_agc3
101 GPIO_ADC_AGC4, // gpio_adc_agc4
102 /* SPI */
103 0, // spi_chip_select
104 SPI_MODE_0, // spi_mode
105 #ifdef _XPARAMETERS_PS_H_
106 PS7_SPI, // spi_type
107 #else
108 AXI_SPI, // spi_type
109 #endif
110 SPI_DEVICE_ID, // spi_device_id
111 /* Device Settings */
112 200000000UL, // reference_clk_rate
113 0, // spi_3_wire
114 3200000000UL, // adc_frequency_hz
115 250000000UL, // intermediate_frequency_hz
116 MIN_FIF, // intermediate_frequency_min_hz
117 MAX_FIF, // intermediate_frequency_max_hz
118 75000000UL, // bandwidth_hz
119 5, // bandwidth_margin_low_mhz
120 5, // bandwidth_margin_high_mhz
121 0, // bandwidth_margin_if_mhz
122 16, // decimation
123 19, // external_inductance_l_nh
124 64, // idac1_fullscale_adjust
125 0, // use_external_clk_enable
126 1, // adc_frequency_fixed_enable
127 1, // jesd_scrambling_enable
128 1, // jesd_use_lvds_syncb_enable
129 0, // jesd_powerdown_sysref_enable
130 2, // jesd_l_lanes
131 16, // jesd_f_frames_per_multiframe
132 1, // shuffler_control
133 5, // shuffler_thresh
134 };
135
136 /***************************************************************************//**
137 * @brief main
138 *******************************************************************************/
139 int main(void)
140 {
141 adc_core ad6676_core;
142 ad6676_dev *ad6676_device;
143 jesd204_core ad6676_jesd204;
144 adxcvr_core ad6676_xcvr;
145
146 ad6676_jesd204.base_addr = AD6676_JESD_BASEADDR;
147 ad6676_jesd204.rx_tx_n = 1;
148 ad6676_jesd204.octets_per_frame = 1;
149 ad6676_jesd204.frames_per_multiframe = 32;
150 ad6676_jesd204.subclass_mode = 1;
151 ad6676_jesd204.sysref_type = INTERN;
152 ad6676_jesd204.gpio_device.device_id = default_init_param.gpio_device_id;
153 ad6676_jesd204.gpio_device.type = default_init_param.gpio_type;
154 ad6676_jesd204.gpio_sysref = GPIO_JESD204_SYSREF;
155
156 ad6676_xcvr.base_addr = AD6676_ADXCVR_BASEADDR;
157 ad6676_xcvr.tx_enable = 0;
158 ad6676_xcvr.gth_enable = 0;
159 ad6676_xcvr.lpm_enable = 0;
160 ad6676_xcvr.out_clk_sel = 4;
161 ad6676_xcvr.sys_clk_sel = 0;
162 ad6676_xcvr.init_set_rate_enable = 0;
163 ad6676_xcvr.lane_rate_khz = 4000000;
164 ad6676_xcvr.ref_rate_khz = 200000;
165
166 // set up the device
167 ad6676_setup(&ad6676_device, default_init_param);
168
169 ad6676_core.adc_baseaddr = AD6676_CORE_BASEADDR;
170 ad6676_core.dmac_baseaddr = AD6676_DMA_BASEADDR;
171 ad6676_core.no_of_channels = 2;
172 ad6676_core.resolution = 16;
173
174 // set up the JESD link and bring up the core
175 jesd204_init(ad6676_jesd204);
176 adxcvr_init(ad6676_xcvr);
177 jesd204_gen_sysref(ad6676_jesd204);
178 adc_setup(ad6676_core);
179
180 // check JESD link status
181 jesd204_read_status(ad6676_jesd204);
182
183 /* Enable Ramp Test Mode */
184 ad6676_spi_write(ad6676_device, AD6676_TEST_GEN, TESTGENMODE_RAMP);
185
186 xil_printf("Start capturing data...\n\r");
187
188 adc_capture(ad6676_core, 16384 * 2, ADC_DDR_BASEADDR);
189
190 xil_printf("Done.\n\r");
191
192 return 0;
193 }