Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Pmods/PmodAD1/main.c

raw symbols SCIP
1 /**************************************************************************//**
2 * @file main.c
3 * @brief Implementation of main program for AD7476.
4 * @author ATofan ([email protected])
5 *
6 *******************************************************************************
7 * Copyright 2011(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: $WCWREV$
42 ******************************************************************************/
43
44 /*****************************************************************************/
45 /***************************** Include Files *********************************/
46 /*****************************************************************************/
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include "platform.h"
50 #include "xil_io.h"
51 #include "xparameters.h"
52
53 /*****************************************************************************/
54 /************************ Constants Definitions ******************************/
55 /*****************************************************************************/
56 #define SAMPLE_NO 8*1024
57
58 #define DMA_BASEADDR XPAR_AXI_DMA_0_BASEADDR
59 #define CF_BASEADDR XPAR_AXI_AD7476_0_BASEADDR
60
61 /*****************************************************************************/
62 /************************ Variables Definitions ******************************/
63 /*****************************************************************************/
64 volatile u32 startAcquisition; //starts one acquisition cycle
65 volatile u32* pStartAcquisition = &startAcquisition;
66 volatile u32* point = XPAR_PS7_DDR_0_S_AXI_BASEADDR + 1024*1024 ; // pointer to data memory location
67
68 void Xil_DCacheFlush(void);
69
70 void delay_ms(u32 ms_count) {
71 u32 count;
72 for (count = 0; count < ((ms_count * 10000000) + 1); count++) {
73 asm("nop");
74 }
75 }
76 /******************************************************************************
77 * @brief Reads data from an ADC usign AXI_DMA core
78 *
79 * @param buf - Start address of the buffer where to store the read data
80 * @param size - Size in bytes of the data to read
81 * @return None
82 ******************************************************************************/
83 void ReadAdcData(u32 buf, u32 size)
84 {
85 // program DMA engine
86 Xil_Out32((DMA_BASEADDR + 0x030), 0); // Clear dma operations
87 Xil_Out32((DMA_BASEADDR + 0x030), 1); // Enable Run bit
88 Xil_Out32((DMA_BASEADDR + 0x048), buf); // Configure DMA with the destination address
89 Xil_Out32((DMA_BASEADDR + 0x058), (size * 4 )); // Number of bites to be written
90
91 // program the DMA module in the ADC core
92 Xil_Out32((CF_BASEADDR + 0x040), 0x1); // Power up the core
93 Xil_Out32((CF_BASEADDR + 0x088), 0x7); // Reset overflows
94 Xil_Out32((CF_BASEADDR + 0x080), 0x0); // DMA stop
95
96 Xil_Out32((CF_BASEADDR + 0x084), size * 4 ); // Program the number of bytes to be captured
97 Xil_Out32((CF_BASEADDR + 0x080), 0x1); // Start capturing data
98
99 // Wait for data transfer to finish
100 do {
101 delay_ms(1);
102 }
103 while ((Xil_In32(CF_BASEADDR + 0x088) & 0x1) == 1);
104 if (Xil_In32(CF_BASEADDR + 0x088) != 0x00) {
105 xil_printf("overflow occured, capture may be corrupted\n\r");
106 xil_printf ("%x\n", Xil_In32(CF_BASEADDR + 0x088) );
107 }
108 Xil_DCacheFlush();
109
110 }
111
112 /**************************************************************************//**
113 * @brief Main function implementation.
114 *
115 * @return None
116 ******************************************************************************/
117 int main()
118 {
119 init_platform();
120 int i;
121
122 xil_printf("\n-------------------------------------\n\r");
123 xil_printf("Waiting for command from the PC...\n\r");
124 xil_printf("Starting a new data acquisition...\n\r");
125
126 xil_printf("Reading data from the ADC...\n\r");
127 ReadAdcData( point , (8096) );
128
129 for (i = 0 ; i < 8096;i++)
130 {
131 xil_printf ("1 = %d\n\r",((point[i] & 0xFFFF0000) >> 16));
132 xil_printf ("2 = %d\n\r",(point[i] & 0x0000FFFF));
133 }
134
135 cleanup_platform();
136
137 return 0;
138 }