Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/AD9250-EBZ/cf_ad9250.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file cf_ad9250.c
3 * @brief Implementation of cf_ad9250 Driver.
4 ********************************************************************************
5 * Copyright 2013(c) Analog Devices, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * - Neither the name of Analog Devices, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 * - The use of this software may or may not infringe the patent rights
21 * of one or more patent holders. This license does not release you
22 * from the requirement that you obtain separate licenses from these
23 * patent holders to use this software.
24 * - Use of the software either in source or binary form, must be run
25 * on or directly connected to an Analog Devices Inc. component.
26 *
27 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 *
38 ********************************************************************************
39 * SVN Revision: $WCREV$
40 *******************************************************************************/
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include "xil_io.h"
46 #include "cf_ad9250.h"
47 #include "AD9250.h"
48 #include "xaxidma.h"
49
50 /******************************************************************************/
51 /************************ Variables Definitions *******************************/
52 /******************************************************************************/
53 static XAxiDma *axiDma;
54
55 /******************************************************************************/
56 /************************ Private Functions Prototypes ************************/
57 /******************************************************************************/
58 void DisplayTestMode(uint32_t mode, uint32_t format);
59
60 /******************************************************************************/
61 /************************ Functions Definitions *******************************/
62 /******************************************************************************/
63
64 /***************************************************************************//**
65 * @brief Creates a delay of milliseconds.
66 *
67 * @param ms_count - Delay in milliseconds.
68 *
69 * @return None.
70 *******************************************************************************/
71 void delay_ms(uint32_t ms_count)
72 {
73 volatile uint32_t count;
74
75 for (count = 0; count < ((ms_count * CYCLES_FOR_1_MS) + 1); count++)
76 {
77 asm("nop");
78 }
79 }
80
81 /***************************************************************************//**
82 * @brief Initializes JESD FPGA core.
83 *
84 * @return None.
85 *******************************************************************************/
86 void jesd_core_setup(void)
87 {
88 Xil_Out32((JESD_BASEADDR + 0x14), 0x30); // reset
89 delay_ms(100);
90 Xil_Out32((JESD_BASEADDR + JESD_REG_LANE_CTRL),
91 JESD_LANE_CTRL_SYSREF_SEL(0) | // hardware sysref generation
92 JESD_LANE_CTRL_LANE_SYNC_EN(1) | // enable lane synchronization
93 JESD_LANE_CTRL_SCR_EN(1) | // enable scrambling
94 JESD_LANE_CTRL_SYSREF_EN(0) | // disable re-alignment at every sysref pulses
95 JESD_LANE_CTRL_ERR_DISB(0)); // enable error reporting via sync
96 Xil_Out32((JESD_BASEADDR + JESD_REG_FRAMES),
97 JESD_FRAMES_FRM_CNT(32) | // 32 frames per multi-frame
98 JESD_FRAMES_BYTE_CNT(2)); // 2 bytes (octets) per frame
99 }
100
101 /***************************************************************************//**
102 * @brief Initializes the DMA core.
103 *
104 * @return None.
105 *******************************************************************************/
106 void dma_core_setup(void)
107 {
108 XAxiDma_Config *axiDmaCfg;
109
110 /* DMA initialization */
111 axiDmaCfg = XAxiDma_LookupConfig(XPAR_AXI_DMA_0_DEVICE_ID);
112 axiDmaCfg->HasMm2S = 0;
113 axiDmaCfg->HasS2Mm = 1;
114 axiDmaCfg->HasSg = 0;
115 XAxiDma_CfgInitialize(axiDma, axiDmaCfg);
116 }
117
118 /***************************************************************************//**
119 * @brief Captures a specified number of samples from the ADC.
120 *
121 * @param size - number of bytes to read from the device
122 * @param address - capture start address
123 *
124 * @return None.
125 *******************************************************************************/
126 void adc_capture(uint32_t size, uint32_t address)
127 {
128 XAxiDma_SimpleTransfer(axiDma, address, (size * 8), XAXIDMA_DEVICE_TO_DMA);
129
130 Xil_Out32((CF_BASEADDR + CF_REG_CAPTURE_CTRL),
131 CF_CAPTURE_CTRL_CAPTURE_START(0)); // capture disable
132 Xil_Out32((CF_BASEADDR + CF_REG_ADC_STATUS),
133 CF_ADC_STATUS_UNDERFLOW |
134 CF_ADC_STATUS_OVERFLOW |
135 CF_ADC_STATUS_BUSY); // clear status
136 Xil_Out32((CF_BASEADDR + CF_REG_DATA_MONITOR),
137 CF_DATA_MONITOR_PN_ERR |
138 CF_DATA_MONITOR_PN_OUT_OF_SYNC |
139 CF_DATA_MONITOR_OVER_RNG); // clear status
140 Xil_Out32((CF_BASEADDR + CF_REG_CAPTURE_CTRL),
141 CF_CAPTURE_CTRL_CAPTURE_START(1) |
142 CF_CAPTURE_CTRL_CAPTURE_COUNT(size)); // capture enable
143 do
144 {
145 delay_ms(1);
146 }
147 while ((Xil_In32(CF_BASEADDR + CF_REG_ADC_STATUS) & CF_ADC_STATUS_BUSY));
148 if ((Xil_In32(CF_BASEADDR + CF_REG_ADC_STATUS) & CF_ADC_STATUS_OVERFLOW))
149 {
150 xil_printf("overflow occurred, capture may be corrupted\n\r");
151 }
152 #ifdef _XPARAMETERS_PS_H_
153 Xil_DCacheFlush();
154 #else
155 microblaze_flush_dcache();
156 microblaze_invalidate_dcache();
157 #endif
158 }
159
160 /***************************************************************************//**
161 * @brief Configures the AD9250 device to run in the selected test mode
162 * and checks if the read data pattern corresponds to the expected
163 * values for the set test mode.
164 *
165 * @param mode - The test mode. Range 0 ..7
166 * 0 - test mode off
167 * 1 - midscale short
168 * 2 - +FS short
169 * 3 - -FS short
170 * 4 - checkerboard output
171 * 5 - PN 23 sequence
172 * 6 - PN 9 sequence
173 * 7 - one/zero word toggle
174 * @param format - Sets the data format:
175 * 0 - offset binary
176 * 1 - twos complement
177 *
178 * @return None.
179 *******************************************************************************/
180 void adc_test(uint32_t mode, uint32_t format)
181 {
182 uint32_t i;
183 uint32_t n;
184 uint32_t error = 0;
185 uint32_t rdata_2;
186 uint32_t rdata[2];
187 uint32_t edata[2];
188
189 edata[0] = 0;
190 edata[1] = 0;
191 ad9250_output_format(format);
192 ad9250_test_mode(mode);
193 ad9250_transfer();
194 adc_capture(16, DDR_BASEADDR);
195 DisplayTestMode(mode, format);
196 if ((mode == PN_23_SEQUENCE) || (mode == PN_9_SEQUENCE))
197 {
198 if (format == TWOS_COMPLEMENT)
199 {
200 xil_printf(" Test skipped\r\n");
201 return;
202 }
203 Xil_Out32((CF_BASEADDR + CF_REG_PN_TYPE),
204 ((mode == PN_23_SEQUENCE) ? CF_PN_TYPE_BIT(1) : CF_PN_TYPE_BIT(0)));
205 delay_ms(10);
206 Xil_Out32((CF_BASEADDR + CF_REG_DATA_MONITOR),
207 CF_DATA_MONITOR_PN_ERR |
208 CF_DATA_MONITOR_PN_OUT_OF_SYNC |
209 CF_DATA_MONITOR_OVER_RNG); // write ones to clear bits
210 delay_ms(100);
211 if ((Xil_In32(CF_BASEADDR + CF_REG_DATA_MONITOR) &
212 (CF_DATA_MONITOR_PN_ERR |
213 CF_DATA_MONITOR_PN_OUT_OF_SYNC |
214 CF_DATA_MONITOR_OVER_RNG)) != 0)
215 {
216 xil_printf(" ERROR: PN status(%04x).\n\r",
217 Xil_In32(CF_BASEADDR + CF_REG_DATA_MONITOR));
218 }
219 else
220 {
221 xil_printf(" Test passed\r\n");
222 }
223 return;
224 }
225 for (n = 0; n < 32; n++)
226 {
227 rdata_2 = Xil_In32(DDR_BASEADDR + (n * 4));
228 rdata[0] = (rdata_2 >> 0) & 0xffff;
229 rdata[1] = (rdata_2 >> 16) & 0xffff;
230 for (i = 0; i < 2; i++)
231 {
232 if ((mode == MIDSCALE) && (format == OFFSET_BINARY))
233 {
234 edata[i] = 0x2000;
235 }
236 if ((mode == POS_FULLSCALE) && (format == OFFSET_BINARY))
237 {
238 edata[i] = 0x3fff;
239 }
240 if ((mode == NEG_FULLSCALE) && (format == OFFSET_BINARY))
241 {
242 edata[i] = 0x0000;
243 }
244 if ((mode == MIDSCALE) && (format == TWOS_COMPLEMENT))
245 {
246 edata[i] = 0x0000;
247 }
248 if ((mode == POS_FULLSCALE) && (format == TWOS_COMPLEMENT))
249 {
250 edata[i] = 0x1fff;
251 }
252 if ((mode == NEG_FULLSCALE) && (format == TWOS_COMPLEMENT))
253 {
254 edata[i] = 0x2000;
255 }
256 if (((mode == CHECKERBOARD) || (mode == ONE_ZERO_TOGGLE)) && (n == 0))
257 {
258 edata[i] = (rdata[i] & 0xffff);
259 }
260 if ((mode == CHECKERBOARD) && (n > 0))
261 {
262 edata[i] = (edata[i] == 0x2aaa) ? 0x1555 : 0x2aaa;
263 }
264 if ((mode == ONE_ZERO_TOGGLE) && (n > 0))
265 {
266 edata[i] = (edata[i] == 0x3fff) ? 0x0000 : 0x3fff;
267 }
268 if (rdata[i] != edata[i])
269 {
270 xil_printf(" ERROR[%2d]: ch(%d), rcv(%08x), exp(%08x)\n\r", n, i, rdata[i], edata[i]);
271 error = 1;
272 }
273 }
274 }
275 if(error == 0)
276 {
277 xil_printf(" Test passed\r\n");
278 }
279 }
280
281 void DisplayTestMode(uint32_t mode, uint32_t format)
282 {
283 char *sMode;
284 char *sFormat;
285
286 switch(format)
287 {
288 case OFFSET_BINARY:
289 sFormat = "OFFSET BINARY";
290 break;
291 case TWOS_COMPLEMENT:
292 sFormat = "TWOS_COMPLEMENT";
293 break;
294 default:
295 sFormat = "";
296 break;
297 }
298 switch(mode)
299 {
300 case TEST_DISABLE:
301 sMode = "TEST_DISABLE BINARY";
302 break;
303 case MIDSCALE:
304 sMode = "MIDSCALE";
305 break;
306 case POS_FULLSCALE:
307 sMode = "POS_FULLSCALE";
308 break;
309 case NEG_FULLSCALE:
310 sMode = "NEG_FULLSCALE BINARY";
311 break;
312 case CHECKERBOARD:
313 sMode = "CHECKERBOARD";
314 break;
315 case PN_23_SEQUENCE:
316 sMode = "PN_23_SEQUENCE";
317 break;
318 case PN_9_SEQUENCE:
319 sMode = "PN_9_SEQUENCE";
320 break;
321 case ONE_ZERO_TOGGLE:
322 sMode = "ONE_ZERO_TOGGLE";
323 break;
324 default:
325 sMode = "";
326 break;
327 }
328 xil_printf("ADC Test: mode - %s\r\n format - %s\n\r", sMode, sFormat);
329 }