Debian Codegraph @

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

raw symbols SCIP
1 /**************************************************************************//**
2 * @file main.c
3 * @brief Implementation of main program for AD7091R.
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: 468
42 ******************************************************************************/
43
44 /*****************************************************************************/
45 /***************************** Include Files *********************************/
46 /*****************************************************************************/
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include "xil_io.h"
50 #include "xparameters.h"
51
52 /*****************************************************************************/
53 /************************ Constants Definitions ******************************/
54 /*****************************************************************************/
55 #define SAMPLE_NO 8*1024
56
57 #define DMA_BASEADDR XPAR_AXIDMA_0_BASEADDR
58 #define CF_BASEADDR XPAR_AXI_AD7091R_0_BASEADDR
59
60 /*****************************************************************************/
61 /************************ Variables Definitions ******************************/
62 /*****************************************************************************/
63 volatile u32 startAcquisition; //starts one acquisition cycle
64 volatile u32* pStartAcquisition = &startAcquisition; //pointer to the startAcquisition variable
65 volatile u32* point = XPAR_PS7_DDR_0_S_AXI_BASEADDR + 1024*1024 ; // pointer to data memory location
66
67 void Xil_DCacheFlush(void);
68
69 void delay_ms(u32 ms_count) {
70 u32 count;
71 for (count = 0; count < ((ms_count * 10000000) + 1); count++) {
72 asm("nop");
73 }
74 }
75 /******************************************************************************
76 * @brief Reads data from an ADC usign AXI_DMA core
77 *
78 * @param buf - Start address of the buffer where to store the read data
79 * @param size - Size in bytes of the data to read
80 * @return None
81 ******************************************************************************/
82 void ReadAdcData(u32 buf, u32 size)
83 {
84 // program DMA engine
85 Xil_Out32((DMA_BASEADDR + 0x030), 0); // Clear dma operations
86 Xil_Out32((DMA_BASEADDR + 0x030), 1); // Enable Run bit
87 Xil_Out32((DMA_BASEADDR + 0x048), buf); // Configure DMA with the destination address
88 Xil_Out32((DMA_BASEADDR + 0x058), (size * 4 )); // Number of bites to be written
89
90 // program the DMA module in the ADC core
91 Xil_Out32((CF_BASEADDR + 0x040), 0x1); // Power up the core
92 Xil_Out32((CF_BASEADDR + 0x088), 0x7); // Reset overflows
93 Xil_Out32((CF_BASEADDR + 0x080), 0x0); // DMA stop
94
95 Xil_Out32((CF_BASEADDR + 0x084), size * 4 ); // Program the number of bytes to be captured
96 Xil_Out32((CF_BASEADDR + 0x080), 0x1); // Start capturing data
97
98 // Wait for data transfer to finish
99 do {
100 delay_ms(1);
101 }
102 while ((Xil_In32(CF_BASEADDR + 0x088) & 0x1) == 1);
103 if (Xil_In32(CF_BASEADDR + 0x088) != 0x00) {
104 xil_printf("overflow occured, capture may be corrupted\n\r");
105 xil_printf ("%x\n", Xil_In32(CF_BASEADDR + 0x088) );
106 }
107 Xil_DCacheFlush();
108
109 }
110
111 void printVin(u32 data);
112
113 /**************************************************************************//**
114 * @brief Main function implementation.
115 *
116 * @return None
117 ******************************************************************************/
118 int main()
119 {
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
128 ReadAdcData( point , (8096) );
129
130 for (i = 0 ; i < 8096;i++)
131 {
132 printVin(point[i]);
133 }
134
135 return 0;
136 }
137
138 void printVin(u32 data)
139 {
140 int rxData = 0;
141 float value = 0;
142 int whole = 0;
143 int thousands = 0;
144
145 rxData = data & 0xFFF;
146
147 // converting data for display
148 value = ((float)rxData/4096)*2.5;
149 whole = value;
150 thousands = ((value - whole)*1000);
151
152 if(thousands > 99)
153 {
154 xil_printf("Vin = %d.%3d %c\n\r",whole, thousands,'V');
155 }
156 else if(thousands > 9)
157 {
158 xil_printf("Vin = %d.0%2d %c\n\r",whole, thousands,'V');
159 }
160 else
161 {
162 xil_printf("Vin = %d.00%1d %c\n\r",whole, thousands,'V');
163 }
164 }