Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/fmcomms1/Common/main.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file main.c
3 * @brief XCOMM main program implementation.
4 * @author acozma ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2011-2015(c) Analog Devices, Inc.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 * - Neither the name of Analog Devices, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 * - The use of this software may or may not infringe the patent rights
23 * of one or more patent holders. This license does not release you
24 * from the requirement that you obtain separate licenses from these
25 * patent holders to use this software.
26 * - Use of the software either in source or binary form, must be run
27 * on or directly connected to an Analog Devices Inc. component.
28 *
29 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, MERCHANTABILITY
31 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34 * INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 *******************************************************************************
41 * SVN Revision: $WCREV$
42 ******************************************************************************/
43
44 /*****************************************************************************/
45 /***************************** Include Files *********************************/
46 /*****************************************************************************/
47 #include <stdio.h>
48 #include <stdint.h>
49 #include "xil_cache.h"
50 #include "xcomm.h"
51 #include "xparameters.h"
52 #include "test.h"
53
54 extern void xil_printf(const char *ctrl1, ...);
55
56 /* Program main loop. */
57 int main()
58 {
59 int32_t ret;
60 int32_t mode = 0;
61 float retGain;
62 uint64_t retFreqRx;
63 uint64_t retFreqTx;
64 int32_t fmcSel;
65 int32_t i;
66 int32_t valArray[17];
67 XCOMM_Version boardVersion;
68 XCOMM_DefaultInit defInit = {FMC_LPC, //fmcPort
69 XILINX_ZC706, //carrierBoard
70 122880000, //adcSamplingRate
71 122880000, //dacSamplingRate
72 4500, //rxGain1000
73 2400000000ull, //rxFrequency
74 2400000000ull};//txFrequency
75
76 Xil_ICacheEnable();
77 Xil_DCacheEnable();
78
79 xil_printf("Running XCOMM Test Program\n\r");
80
81 if(defInit.carrierBoard == XILINX_ZC702)
82 {
83 fmcSel = (defInit.fmcPort == FMC_LPC ? IICSEL_B0LPC_PS7 : IICSEL_B1HPC_PS7);
84 }
85 else
86 {
87 if(defInit.carrierBoard == XILINX_ZC706)
88 {
89 fmcSel = (defInit.fmcPort == FMC_LPC ? IICSEL_B0LPC_PS7_ZC706 :
90 IICSEL_B1HPC_PS7_ZC706);
91 }
92 else
93 {
94 fmcSel = (defInit.fmcPort == FMC_LPC ? IICSEL_B0LPC_AXI : IICSEL_B1HPC_AXI);
95 }
96 }
97
98 xil_printf("\n\rInitializing XCOMM I2C...\n\r");
99 ret = XCOMM_InitI2C(&defInit);
100 if(ret < 0)
101 {
102 xil_printf("XCOMM Init I2C Failed!\n\r");
103 return 0;
104 }
105 else
106 {
107 xil_printf("XCOMM Init I2C OK!\n\r");
108 }
109
110 xil_printf("\n\rGetting XCOMM Revision...\n\r");
111 boardVersion = XCOMM_GetBoardVersion(XCOMM_ReadMode_FromHW);
112 if(boardVersion.error == -1)
113 {
114 xil_printf("\n\rGetting XCOMM Revision Failed!\n\r");
115 }
116 else
117 {
118 xil_printf("Board Version: %s\n\r", boardVersion.value);
119 }
120
121 xil_printf("\n\rInitializing XCOMM Components...\n\r");
122 ret = XCOMM_Init(&defInit);
123 if(ret < 0)
124 {
125 xil_printf("XCOMM Init Failed!\n\r");
126 return 0;
127 }
128 else
129 {
130 xil_printf("XCOMM Init OK!\n\r");
131 }
132
133 xil_printf("\n\rInitializing the Rx path...\n\r");
134 ret = XCOMM_InitRx(&defInit);
135 if(ret < 0)
136 {
137 xil_printf("XCOMM Rx Init Failed!\n\r");
138 return 0;
139 }
140 else
141 {
142 xil_printf("XCOMM Rx Init OK!\n\r");
143 }
144
145 xil_printf("\n\rInitializing the Tx path...\n\r");
146 ret = XCOMM_InitTx(&defInit);
147 if(ret < 0)
148 {
149 xil_printf("XCOMM Tx Init Failed!\n\r");
150 return 0;
151 }
152 else
153 {
154 xil_printf("XCOMM Tx Init OK!\n\r");
155 }
156
157 xil_printf("\n\rADC sampling rate [Hz]: ");
158 ret = XCOMM_GetAdcSamplingRate(XCOMM_ReadMode_FromHW);
159 xil_printf("%d \n\r", ret);
160
161 xil_printf("\n\rDAC sampling rate [Hz]: ");
162 ret = XCOMM_GetDacSamplingRate(XCOMM_ReadMode_FromHW);
163 xil_printf("%d \n\r", ret);
164
165 xil_printf("\n\rDAC available interpolation frequencies [Hz]: ");
166 XCOMM_GetDacAvailableInterpolationFreq(valArray);
167 i = 0;
168 while((valArray[i] != 0) && (i < 5))
169 {
170 xil_printf("%d ", valArray[i]);
171 i++;
172 }
173 xil_printf("\n\r");
174 XCOMM_SetDacInterpolationFreq(valArray[i - 1]);
175
176 xil_printf("\n\rDAC available center shift frequencies [Hz]: ");
177 XCOMM_GetDacAvailableCenterShiftFreq(valArray);
178 i = 0;
179 while((valArray[i] != -1) && (i < 17))
180 {
181 xil_printf("%d ", valArray[i]);
182 i++;
183 }
184 xil_printf("\n\r");
185
186 xil_printf("\n\rTesting the ADC communication... \n\r");
187 XCOMM_SetAdcTestMode(0x01, XCOMM_AdcChannel_All);
188 adc_capture(fmcSel, 1024, DDR_BASEADDR);
189
190 for (mode = 0x1; mode <= 0x7; mode++)
191 {
192 XCOMM_SetAdcTestMode(mode, XCOMM_AdcChannel_All);
193 adc_test(fmcSel, mode, 0x1);
194 }
195 xil_printf("ADC test complete.\n\r");
196
197 xil_printf("\n\rTesting the DAC communication... \n\r");
198 dac_test(fmcSel);
199 xil_printf("DAC test complete.\n\r");
200
201 xil_printf("\n\rSetting the VGA gain to: %d.%d dB\n\r", (int)defInit.rxGain1000/1000, (int)((defInit.rxGain1000 - (int)(defInit.rxGain1000/1000)*1000)));
202 retGain = (float)XCOMM_SetRxGain(defInit.rxGain1000) / 1000.0f;
203 xil_printf("Actual set VGA gain: %d.%d dB\n\r", (int)retGain, (int)((retGain - (int)retGain) * 1000));
204
205 xil_printf("\n\rSetting the Rx frequency to: %lld%06lld\n\r", defInit.rxFrequency/(uint64_t)1e6, defInit.rxFrequency%(uint64_t)1e6);
206 retFreqRx = XCOMM_SetRxFrequency(defInit.rxFrequency);
207 xil_printf("Actual set Rx frequency: %lld%06lld\n\r", retFreqRx/(uint64_t)1e6, retFreqRx%(uint64_t)1e6);
208
209 xil_printf("\n\rSetting the Tx frequency to: %lld%06lld\n\r", defInit.txFrequency/(uint64_t)1e6, defInit.txFrequency%(uint64_t)1e6);
210 retFreqTx = XCOMM_SetTxFrequency(defInit.txFrequency);
211 xil_printf("Actual set Tx frequency: %lld%06lld\n\r", retFreqTx/(uint64_t)1e6, retFreqTx%(uint64_t)1e6);
212
213 #ifndef DAC_DMA
214 xil_printf("\n\rSetting up the DDS... \n\r");
215 dds_setup(fmcSel, 1000000, 1000000);
216 xil_printf("DDS setup complete.\n\r");
217 #else
218 xil_printf("\n\rSetting up the DAC DMA... \n\r");
219 dac_dma_setup(fmcSel);
220 xil_printf("DAC DMA setup complete.\n\r");
221 #endif
222
223 xil_printf("\n\rReading data from air... \n\r");
224 XCOMM_SetAdcTestMode(XCOMM_AdcTestMode_Off, XCOMM_AdcChannel_All);
225 delay_ms(1000);
226 adc_capture(fmcSel, 16384, DDR_BASEADDR);
227 xil_printf("Read data from air complete. \n\r");
228
229 xil_printf("\n\rFinished XCOMM Test Program\n\r");
230
231 Xil_DCacheDisable();
232 Xil_ICacheDisable();
233
234 return 0;
235 }