Debian Codegraph @

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

raw symbols SCIP
1 /**************************************************************************//**
2 * @file test.c
3 * @brief Test functions implementations.
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 <stdint.h>
48 #include <xparameters.h>
49 #include <xil_io.h>
50 #include <xil_cache.h>
51 #include "timer.h"
52 #include "test.h"
53 #include "dac_core.h"
54
55 /*****************************************************************************/
56 /***************************** External Functions ****************************/
57 /*****************************************************************************/
58 extern int32_t ad9122_write(uint8_t registerAddress, uint8_t registerValue);
59 extern int32_t ad9122_read(uint8_t registerAddress);
60 extern void xil_printf(const char *ctrl1, ...);
61
62 /*****************************************************************************/
63 /************************ Constants Definitions ******************************/
64 /*****************************************************************************/
65 const uint16_t sine_lut_q[32] = {
66 32768, 34366, 35902, 37318, 38560, 39578, 40335, 40802,
67 40959, 40802, 40335, 39578, 38560, 37318, 35902, 34366,
68 32768, 31169, 29633, 28217, 26975, 25957, 25200, 24733,
69 24576, 24733, 25200, 25957, 26975, 28217, 29633, 31169,
70 };
71
72 const uint16_t sine_lut_i[32] = {
73 24576, 24733, 25200, 25957, 26975, 28217, 29633, 31169,
74 32768, 34366, 35902, 37318, 38560, 39578, 40335, 40802,
75 40959, 40802, 40335, 39578, 38560, 37318, 35902, 34366,
76 32768, 31169, 29633, 28217, 26975, 25957, 25200, 24733,
77 };
78
79 static uint32_t dac_base_addr;
80
81 /**************************************************************************//**
82 * @brief Delays the program execution with the specified number of ms.
83 *
84 * @param ns_count Number of ms with which the program must be delayed.
85 * @return None.
86 ******************************************************************************/
87 void delay_ms(uint32_t ms_count)
88 {
89 #ifdef _XPARAMETERS_PS_H_
90 volatile uint32_t i;
91 for(i = 0; i < ms_count*1000; i++);
92 #else
93 #ifdef XPAR_AXI_TIMER_0_BASEADDR
94 TIMER0_WAIT(XPAR_AXI_TIMER_0_BASEADDR, ms_count*1000000);
95 #else
96 TIMER0_WAIT(XPAR_AXI_TIMER_BASEADDR, ms_count*1000000);
97 #endif
98 #endif
99 }
100
101 /***************************************************************************//**
102 * @brief dac_read
103 *******************************************************************************/
104 void dac_read(uint32_t regAddr, uint32_t *data)
105 {
106 *data = Xil_In32(dac_base_addr + 0x4000 + regAddr);
107 }
108
109 /***************************************************************************//**
110 * @brief dac_write
111 *******************************************************************************/
112 void dac_write(uint32_t regAddr, uint32_t data)
113 {
114 Xil_Out32(dac_base_addr + 0x4000 + regAddr, data);
115 }
116
117 /***************************************************************************//**
118 * @brief do_div
119 *******************************************************************************/
120 #define do_div(n,base) ({ \
121 uint64_t __res; \
122 __res = ((uint64_t) (n)) % (uint64_t) (base); \
123 n = ((uint64_t) (n)) / (uint64_t) (base); \
124 __res;})
125
126 /***************************************************************************//**
127 * @brief dds_set_frequency
128 *******************************************************************************/
129 void dds_set_frequency(uint32_t chan, uint32_t freq)
130 {
131 uint32_t pcore_version;
132 uint64_t val64;
133 uint32_t ctrl_reg, reg;
134 uint32_t dac_clk;
135 uint32_t val;
136
137 dac_read(ADI_REG_VERSION, &pcore_version);
138 dac_read(ADI_REG_CLK_FREQ, &val);
139 dac_clk = val;
140 dac_read(ADI_REG_CLK_RATIO, &val);
141 dac_clk *= val * 100000000 / 65536;
142
143 dac_read(ADI_REG_CNTRL_1, &ctrl_reg);
144 dac_write(ADI_REG_CNTRL_1, 0);
145 dac_read(ADI_REG_CHAN_CNTRL_2_IIOCHAN(chan), &reg);
146 reg &= ~ADI_DDS_INCR(~0);
147 val64 = (u64) freq * 0xFFFFULL;
148 do_div(val64, dac_clk);
149 reg |= ADI_DDS_INCR(val64) | 1;
150 dac_write(ADI_REG_CHAN_CNTRL_2_IIOCHAN(chan), reg);
151 if (PCORE_VERSION_MAJOR(pcore_version) > 7)
152 {
153 dac_write(ADI_REG_CNTRL_1, 0x1);
154 }
155 else
156 {
157 dac_write(ADI_REG_CNTRL_1, ctrl_reg);
158 }
159 }
160
161 /***************************************************************************//**
162 * @brief dds_set_phase
163 *******************************************************************************/
164 void dds_set_phase(uint32_t chan, uint32_t phase)
165 {
166 uint32_t pcore_version;
167 uint64_t val64;
168 uint32_t ctrl_reg, reg;
169
170 dac_read(ADI_REG_VERSION, &pcore_version);
171 dac_read(ADI_REG_CNTRL_1, &ctrl_reg);
172 dac_write(ADI_REG_CNTRL_1, 0);
173 dac_read(ADI_REG_CHAN_CNTRL_2_IIOCHAN(chan), &reg);
174 reg &= ~ADI_DDS_INIT(~0);
175 val64 = (u64) phase * 0x10000ULL + (360000 / 2);
176 do_div(val64, 360000);
177 reg |= ADI_DDS_INIT(val64);
178 dac_write(ADI_REG_CHAN_CNTRL_2_IIOCHAN(chan), reg);
179 if (PCORE_VERSION_MAJOR(pcore_version) > 7)
180 {
181 dac_write(ADI_REG_CNTRL_1, 0x1);
182 }
183 else
184 {
185 dac_write(ADI_REG_CNTRL_1, ctrl_reg);
186 }
187 }
188
189 /***************************************************************************//**
190 * @brief dds_set_scale
191 *******************************************************************************/
192 void dds_set_scale(uint32_t chan, double scale)
193 {
194 uint32_t pcore_version;
195 uint32_t ctrl_reg;
196 uint32_t scale_reg;
197 uint32_t sign_part;
198 uint32_t int_part;
199 uint32_t fract_part;
200
201 dac_read(ADI_REG_VERSION, &pcore_version);
202 if (PCORE_VERSION_MAJOR(pcore_version) > 6)
203 {
204 if(scale >= 1.0)
205 {
206 sign_part = 0;
207 int_part = 1;
208 fract_part = 0;
209 goto set_scale_reg;
210 }
211 if(scale <= -1.0)
212 {
213 sign_part = 1;
214 int_part = 1;
215 fract_part = 0;
216 goto set_scale_reg;
217 }
218 if(scale < 0)
219 {
220 sign_part = 1;
221 int_part = 0;
222 scale *= -1;
223 goto set_scale_reg;
224 }
225 sign_part = 0;
226 int_part = 0;
227 fract_part = (uint32_t)(scale * 0x4000);
228 set_scale_reg:
229 scale_reg = (sign_part << 15) | (int_part << 14) | fract_part;
230 }
231 else
232 {
233 if(scale >= 1.0)
234 {
235 scale_reg = 0;
236 scale = 1.0;
237 }
238 if(scale <= 0.0)
239 {
240 scale_reg = 0;
241 scale = 0.0;
242 }
243 fract_part = (uint32_t)(scale * 1000000);
244 scale_reg = 500000 / fract_part;
245 }
246 dac_read(ADI_REG_CNTRL_1, &ctrl_reg);
247 dac_write(ADI_REG_CNTRL_1, 0);
248 dac_write(ADI_REG_CHAN_CNTRL_1_IIOCHAN(chan), ADI_DDS_SCALE(scale_reg));
249 if (PCORE_VERSION_MAJOR(pcore_version) > 7)
250 {
251 dac_write(ADI_REG_CNTRL_1, 0x1);
252 }
253 else
254 {
255 dac_write(ADI_REG_CNTRL_1, ctrl_reg);
256 }
257 }
258
259 /**************************************************************************//**
260 * @brief Initializes the DDS core.
261 *
262 * @return None.
263 ******************************************************************************/
264 void dds_setup(uint32_t sel, uint32_t f1, uint32_t f2)
265 {
266 uint32_t hdl_version;
267
268 dac_base_addr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ?
269 CFAD9122_1_BASEADDR : CFAD9122_0_BASEADDR;
270
271 dac_read(ADI_REG_VERSION, &hdl_version);
272
273 if (PCORE_VERSION_MAJOR(hdl_version) > 7)
274 {
275 dac_write(ADI_REG_CHAN_CNTRL_7(0), 0);
276 dac_write(ADI_REG_CHAN_CNTRL_7(1), 0);
277 dac_write(ADI_REG_CNTRL_1, 0x0);
278 dac_write(ADI_REG_CNTRL_1, 0x1);
279 }
280 else
281 {
282 dac_write(ADI_REG_CNTRL_2, ADI_DATA_FORMAT | ADI_DATA_SEL(DATA_SEL_DDS));
283 dac_write(ADI_REG_CNTRL_1, 0x0);
284 dac_write(ADI_REG_CNTRL_1, 0x1);
285 }
286
287 dds_set_frequency(0, f1);
288 dds_set_phase(0, 90000);
289 dds_set_scale(0, 0.125);
290 dds_set_frequency(1, f1);
291 dds_set_phase(1, 90000);
292 dds_set_scale(1, 0.125);
293 dds_set_frequency(2, f2);
294 dds_set_phase(2, 0);
295 dds_set_scale(2, 0.125);
296 dds_set_frequency(3, f2);
297 dds_set_phase(3, 0);
298 dds_set_scale(3, 0.125);
299 }
300
301 /**************************************************************************//**
302 * @brief Initializes the DAC DMA.
303 *
304 * @return None.
305 ******************************************************************************/
306 void dac_dma_setup(uint32_t sel)
307 {
308 uint32_t baddr;
309 uint32_t index;
310 uint32_t tx_count;
311 uint32_t data_i;
312 uint32_t data_q;
313 uint32_t dac_clk;
314 uint32_t val;
315 uint32_t sine_freq;
316 uint32_t hdl_version;
317
318 dac_base_addr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ?
319 CFAD9122_1_BASEADDR : CFAD9122_0_BASEADDR;
320
321 dac_read(ADI_REG_VERSION, &hdl_version);
322
323 tx_count = sizeof(sine_lut_i) / sizeof(uint16_t);
324 for(index = 0; index < tx_count; index ++)
325 {
326 data_i = (sine_lut_i[index] << 16);
327 data_q = (sine_lut_q[index] << 0);
328 Xil_Out32(DDRDAC_BASEADDR + index * 4, data_i | data_q);
329 }
330 #ifdef _XPARAMETERS_PS_H_
331 Xil_DCacheFlush();
332 #else
333 microblaze_flush_dcache();
334 microblaze_invalidate_dcache();
335 #endif
336
337 baddr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ? DMA9122_1_BASEADDR : DMA9122_0_BASEADDR;
338
339 Xil_Out32(baddr + AXI_DMAC_REG_CTRL, AXI_DMAC_CTRL_ENABLE);
340 Xil_Out32(baddr + AXI_DMAC_REG_SRC_ADDRESS, DDRDAC_BASEADDR);
341 Xil_Out32(baddr + AXI_DMAC_REG_SRC_STRIDE, 0);
342 Xil_Out32(baddr + AXI_DMAC_REG_X_LENGTH, (tx_count * 4) - 1);
343 Xil_Out32(baddr + AXI_DMAC_REG_Y_LENGTH, 0x0);
344 Xil_Out32(baddr + AXI_DMAC_REG_START_TRANSFER, 0x1);
345
346 dac_read(ADI_REG_CLK_FREQ, &val);
347 dac_clk = val;
348 dac_read(ADI_REG_CLK_RATIO, &val);
349 dac_clk *= val * 100000000 / 65536;
350 sine_freq = dac_clk / (tx_count * 2);
351 xil_printf("dac_dma: Sine frequency is %d Hz.\n\r", sine_freq);
352
353 if (PCORE_VERSION_MAJOR(hdl_version) > 7)
354 {
355 dac_write(ADI_REG_CHAN_CNTRL_7(0), 2);
356 dac_write(ADI_REG_CHAN_CNTRL_7(1), 2);
357 dac_write(ADI_REG_CNTRL_1, 0x0);
358 dac_write(ADI_REG_CNTRL_1, 0x1);
359 }
360 else
361 {
362 dac_write(ADI_REG_CNTRL_2, ADI_DATA_FORMAT | ADI_DATA_SEL(DATA_SEL_DMA));
363 dac_write(ADI_REG_CNTRL_1, 0x0);
364 dac_write(ADI_REG_CNTRL_1, 0x1);
365 }
366 }
367
368 /**************************************************************************//**
369 * @brief Puts the DAC in SED mode and verifies the correctness of the samples
370 *
371 * @return None.
372 ******************************************************************************/
373 void dac_sed(uint32_t sel, uint32_t s0, uint32_t s1)
374 {
375 uint32_t baddr;
376 uint32_t rdata;
377 uint32_t hdl_version;
378
379 baddr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ? CFAD9122_1_BASEADDR : CFAD9122_0_BASEADDR;
380
381 hdl_version = Xil_In32(baddr + 0x4000);
382
383 ad9122_write(0x68, ((s0>> 0) & 0xff));
384 ad9122_write(0x69, ((s0>> 8) & 0xff));
385 ad9122_write(0x6a, ((s1>> 0) & 0xff));
386 ad9122_write(0x6b, ((s1>> 8) & 0xff));
387 ad9122_write(0x6c, ((s0>>16) & 0xff));
388 ad9122_write(0x6d, ((s0>>24) & 0xff));
389 ad9122_write(0x6e, ((s1>>16) & 0xff));
390 ad9122_write(0x6f, ((s1>>24) & 0xff));
391 ad9122_write(0x67, 0x00);
392 ad9122_write(0x67, 0x80);
393 Xil_Out32((baddr + 0x4410), s0); // pattern
394 Xil_Out32((baddr + 0x4450), s1); // pattern
395 if (PCORE_VERSION_MAJOR(hdl_version) > 7)
396 {
397 Xil_Out32((baddr + 0x4418), 0x1); // sed sel
398 Xil_Out32((baddr + 0x4458), 0x1); // sed sel
399 Xil_Out32((baddr + 0x4044), 0x1); // sync
400 }
401 else
402 {
403 Xil_Out32((baddr + 0x4048), 0x1); // format, sel
404 Xil_Out32((baddr + 0x4044), 0x1); // enable
405 }
406 delay_ms(10);
407 ad9122_write(0x67, 0xa3);
408 ad9122_write(0x07, 0x1c);
409 delay_ms(100);
410
411 xil_printf("dac_sed: s0(0x%08x), s1(0x%08x)\n\r", s0, s1);
412 rdata = ad9122_read(0x67);
413 if ((rdata & 0x20) == 0x20)
414 {
415 xil_printf("ERROR: Addr(0x67) Data(0x%02x)!\n\r", rdata);
416 }
417 rdata = ad9122_read(0x07);
418 if ((rdata & 0x04) == 0x04)
419 {
420 xil_printf("ERROR: Addr(0x07) Data(0x%02x)!\n\r", rdata);
421 }
422 rdata = ad9122_read(0x70);
423 if (rdata != 0x00)
424 {
425 xil_printf("ERROR: Addr(0x70) Data(0x%02x)!\n\r", rdata);
426 }
427 rdata = ad9122_read(0x71);
428 if (rdata != 0x00)
429 {
430 xil_printf("ERROR: Addr(0x71) Data(0x%02x)!\n\r", rdata);
431 }
432 rdata = ad9122_read(0x72);
433 if (rdata != 0x00)
434 {
435 xil_printf("ERROR: Addr(0x72) Data(0x%02x)!\n\r", rdata);
436 }
437 rdata = ad9122_read(0x73);
438 if (rdata != 0x00)
439 {
440 xil_printf("ERROR: Addr(0x73) Data(0x%02x)!\n\r", rdata);
441 }
442
443 return;
444 }
445
446 /**************************************************************************//**
447 * @brief Tests the communication with the DAC
448 *
449 * @return None.
450 ******************************************************************************/
451 void dac_test(uint32_t sel)
452 {
453 u32 rdata;
454 u32 dac_clk_int;
455 u32 dac_clk_frac;
456 float dac_clk;
457 uint32_t baddr;
458
459 baddr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ? CFAD9122_1_BASEADDR : CFAD9122_0_BASEADDR;
460 Xil_Out32((baddr + 0x4040), 0x3); // reset
461 delay_ms(10);
462 if (Xil_In32(baddr + 0x405c) == 0x0)
463 {
464 xil_printf("dac_setup: status NOT set!!\n\r");
465 }
466 rdata = Xil_In32(baddr + 0x4054);
467 dac_clk = (float) rdata;
468 rdata = Xil_In32(baddr + 0x4058);
469 dac_clk = dac_clk * (float) rdata * (float) 100.0;
470 dac_clk = dac_clk / (float) 65536.0;
471 dac_clk_int = (u32) dac_clk;
472 dac_clk_frac = (dac_clk - (float) dac_clk_int) * 1000;
473 xil_printf("dac_setup: dac_clock(%d.%3dMHz)\n\r", dac_clk_int, dac_clk_frac);
474
475 ad9122_write(0x16, 0x01);
476 ad9122_read(0x16);
477 dac_sed(sel, 0x0000aaaa, 0x00000000);
478 dac_sed(sel, 0x00005555, 0x00000000);
479 dac_sed(sel, 0xaaaa0000, 0x00000000);
480 dac_sed(sel, 0x55550000, 0x00000000);
481 dac_sed(sel, 0x00000000, 0x0000aaaa);
482 dac_sed(sel, 0x00000000, 0x00005555);
483 dac_sed(sel, 0x00000000, 0xaaaa0000);
484 dac_sed(sel, 0x00000000, 0x55550000);
485 dac_sed(sel, 0x00000000, 0x00000000);
486 dac_sed(sel, 0xaaaaaaaa, 0x55555555);
487 dac_sed(sel, 0x55555555, 0xaaaaaaaa);
488
489 return;
490 }
491
492 /**************************************************************************//**
493 * @brief Captures data from the ADC
494 *
495 * @return None.
496 ******************************************************************************/
497 void adc_capture(uint32_t sel, uint32_t size, uint32_t start_address)
498 {
499 uint32_t baddr;
500 uint32_t reg_val;
501 uint32_t transfer_id;
502
503 baddr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ? DMA9643_1_BASEADDR : DMA9643_0_BASEADDR;
504
505 Xil_Out32(baddr + AXI_DMAC_REG_CTRL, 0x0);
506 Xil_Out32(baddr + AXI_DMAC_REG_CTRL, AXI_DMAC_CTRL_ENABLE);
507
508 Xil_Out32(baddr + AXI_DMAC_REG_IRQ_MASK, 0x0);
509
510 transfer_id = Xil_In32(baddr + AXI_DMAC_REG_TRANSFER_ID);
511 reg_val = Xil_In32(baddr + AXI_DMAC_REG_IRQ_PENDING);
512 Xil_Out32(baddr + AXI_DMAC_REG_IRQ_PENDING, reg_val);
513
514 Xil_Out32(baddr + AXI_DMAC_REG_DEST_ADDRESS, start_address);
515 Xil_Out32(baddr + AXI_DMAC_REG_DEST_STRIDE, 0x0);
516 Xil_Out32(baddr + AXI_DMAC_REG_X_LENGTH, (size * 8) - 1);
517 Xil_Out32(baddr + AXI_DMAC_REG_Y_LENGTH, 0x0);
518
519 Xil_Out32(baddr + AXI_DMAC_REG_START_TRANSFER, 0x1);
520 /* Wait until the new transfer is queued. */
521 do {
522 reg_val = Xil_In32(baddr + AXI_DMAC_REG_START_TRANSFER);
523 }
524 while(reg_val == 1);
525
526 /* Wait until the current transfer is completed. */
527 do {
528 reg_val = Xil_In32(baddr + AXI_DMAC_REG_IRQ_PENDING);
529 }
530 while(reg_val != (AXI_DMAC_IRQ_SOT | AXI_DMAC_IRQ_EOT));
531 Xil_Out32(baddr + AXI_DMAC_REG_IRQ_PENDING, reg_val);
532
533 /* Wait until the transfer with the ID transfer_id is completed. */
534 do {
535 reg_val = Xil_In32(baddr + AXI_DMAC_REG_TRANSFER_DONE);
536 }
537 while((reg_val & (1 << transfer_id)) != (1 << transfer_id));
538 #ifdef _XPARAMETERS_PS_H_
539 Xil_DCacheFlush();
540 #else
541 microblaze_flush_dcache();
542 microblaze_invalidate_dcache();
543 #endif
544 }
545
546 /**************************************************************************//**
547 * @brief Tests the communication with the ADC
548 *
549 * @return None.
550 ******************************************************************************/
551 void adc_test(uint32_t sel, uint32_t mode, uint32_t format)
552 {
553 uint32_t n;
554 uint32_t rdata;
555 uint32_t adata;
556 uint32_t bdata;
557 uint32_t edata;
558 uint32_t baddr;
559 uint32_t adc_clk_int;
560 uint32_t adc_clk_frac;
561 float adc_clk;
562 uint32_t pcore_version;
563
564 baddr = ((sel == IICSEL_B1HPC_AXI)||(sel == IICSEL_B1HPC_PS7)) ? CFAD9643_1_BASEADDR : CFAD9643_0_BASEADDR;
565
566 pcore_version = Xil_In32(baddr + 0x0000);
567
568 Xil_Out32((baddr + 0x040), 0x3);
569 delay_ms(10);
570 if (Xil_In32(baddr + 0x05c) == 0x0)
571 {
572 xil_printf("adc_test: status NOT set!!\n\r");
573 }
574
575 if (PCORE_VERSION_MAJOR(pcore_version) > 8) {
576 if ((Xil_In32(baddr + 0x800) & 0x200) == 0x1)
577 {
578 xil_printf("adc_test: delay NOT locked!!\n\r");
579 }
580 } else {
581 if ((Xil_In32(baddr + 0x064) & 0x200) == 0x0)
582 {
583 xil_printf("adc_test: delay NOT locked!!\n\r");
584 }
585 }
586
587 rdata = Xil_In32(baddr + 0x054);
588 adc_clk = (float) rdata;
589 rdata = Xil_In32(baddr + 0x058);
590 adc_clk = adc_clk * (float) rdata * (float) 100.0;
591 adc_clk = adc_clk / (float) 65536.0;
592 adc_clk_int = (u32) adc_clk;
593 adc_clk_frac = (adc_clk - (float) adc_clk_int) * 1000;
594 xil_printf("adc_test: adc_clock(%d.%3dMHz)\n\r", adc_clk_int, adc_clk_frac);
595
596 Xil_Out32((baddr + 0x400), 0x1); // signextn, fmt & ch enable
597 Xil_Out32((baddr + 0x440), 0x1); // signextn, fmt & ch enable
598
599 adc_capture(sel, 16, DDR_BASEADDR);
600 delay_ms(10);
601
602 xil_printf("adc_test: mode(%2d), format(%2d)\n\r", mode, format);
603
604 /* Alternating Checkerboard */
605 if (mode == 0x4)
606 {
607 for (n = 0; n < 32; n++)
608 {
609 rdata = Xil_In32(DDR_BASEADDR+(n*4));
610 if (n == 0)
611 {
612 adata = ((rdata & 0xffff) == 0x2aaa) ? 0x2aaa : 0x1555;
613 bdata = (((rdata>>16) & 0xffff) == 0x2aaa) ? 0x2aaa : 0x1555;
614 }
615 else
616 {
617 adata = (adata == 0x2aaa) ? 0x1555 : 0x2aaa;
618 bdata = (bdata == 0x2aaa) ? 0x1555 : 0x2aaa;
619 }
620 edata = (bdata<<16) | adata;
621 if (rdata != edata)
622 {
623 xil_printf(" ERROR[%2d]: rcv(%08x), exp(%08x)\n\r", n, rdata, edata);
624 }
625 }
626 goto end;
627 }
628
629 /* PnLongSeq or PnShortSeq */
630 if ((mode == 0x5) || (mode == 0x6))
631 {
632 if (format == 0x1)
633 goto end;
634 Xil_Out32((baddr + 0x400), ((mode == 0x5) ? 0x2 : 0x0));
635 Xil_Out32((baddr + 0x440), ((mode == 0x5) ? 0x2 : 0x0));
636 delay_ms(10);
637 Xil_Out32((baddr + 0x404), 0xff);
638 Xil_Out32((baddr + 0x444), 0xff);
639 delay_ms(100);
640 if (Xil_In32(baddr + 0x404) != 0)
641 {
642 xil_printf(" ERROR: PN status(%02x).\n\r", Xil_In32(baddr + 0x404));
643 }
644 if (Xil_In32(baddr + 0x444) != 0)
645 {
646 xil_printf(" ERROR: PN status(%02x).\n\r", Xil_In32(baddr + 0x444));
647 }
648 goto end;
649 }
650
651 /* One Zero Toggle */
652 if (mode == 0x7)
653 {
654 for (n = 0; n < 32; n++)
655 {
656 rdata = Xil_In32(DDR_BASEADDR+(n*4));
657 if (n == 0)
658 {
659 adata = ((rdata & 0xffff) == 0x3fff) ? 0x3fff : 0x0000;
660 bdata = (((rdata>>16) & 0xffff) == 0x3fff) ? 0x3fff : 0x0000;
661 }
662 else
663 {
664 adata = (adata == 0x3fff) ? 0x0000 : 0x3fff;
665 bdata = (bdata == 0x3fff) ? 0x0000 : 0x3fff;
666 }
667 edata = (bdata<<16) | adata;
668 if (rdata != edata)
669 {
670 xil_printf(" ERROR[%2d]: rcv(%08x), exp(%08x)\n\r", n, rdata, edata);
671 }
672 }
673 goto end;
674 }
675
676 /* Ramp */
677 if (mode == 0xf)
678 {
679 for (n = 0; n < 16; n++)
680 {
681 rdata = Xil_In32(DDR_BASEADDR+(n*8));
682 if (n == 0)
683 {
684 adata = rdata & 0xffff;
685 bdata = (rdata>>16) & 0xffff;
686 }
687 else
688 {
689 adata = (adata+1) & 0x3fff;
690 bdata = (bdata+1) & 0x3fff;
691 }
692 edata = (bdata<<16) | adata;
693 if (rdata != edata)
694 {
695 xil_printf(" ERROR[%2d]: rcv(%08x), exp(%08x)\n\r", n, rdata, edata);
696 }
697 }
698 goto end;
699 }
700
701 /* MidscaleShort, PositiveFs, NegativeFs */
702 edata = 0xffffffff;
703 if ((mode == 0x1) && (format == 0))
704 edata = 0x20002000;
705 if ((mode == 0x2) && (format == 0))
706 edata = 0x3fff3fff;
707 if ((mode == 0x3) && (format == 0))
708 edata = 0x00000000;
709 if ((mode == 0x1) && (format == 1))
710 edata = 0x00000000;
711 if ((mode == 0x2) && (format == 1))
712 edata = 0x1fff1fff;
713 if ((mode == 0x3) && (format == 1))
714 edata = 0x20002000;
715 for (n = 0; n < 32; n++)
716 {
717 rdata = Xil_In32(DDR_BASEADDR+(n*4));
718 if (rdata != edata)
719 {
720 xil_printf(" ERROR[%2d]: rcv(%08x), exp(%08x)\n\r", n, rdata, edata);
721 }
722 }
723 end:
724 Xil_Out32((baddr + 0x400), 0x31);
725 Xil_Out32((baddr + 0x440), 0x31);
726 }