Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad7768-evb/ad7768_evb.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file ad7768evb.c
3 * @brief Implementation of Main Function.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2016(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *******************************************************************************/
39
40 /******************************************************************************/
41 /***************************** Include Files **********************************/
42 /******************************************************************************/
43 #include <xparameters.h>
44 #include "platform_drivers.h"
45 #include "ad7768.h"
46 #include "adc_core.h"
47 #include <xil_io.h>
48 #include <stdio.h>
49
50 #define SPI_DEVICE_ID XPAR_PS7_SPI_0_DEVICE_ID
51 #define SPI_AD7768_CS 0
52 #define GPIO_DEVICE_ID XPAR_PS7_GPIO_0_DEVICE_ID
53 #define GPIO_OFFSET 32 + 54
54 #define AD7768_DMA_BASEADDR XPAR_AD7768_DMA_BASEADDR
55 #define ADC_DDR_BASEADDR XPAR_DDR_MEM_BASEADDR + 0x800000
56 #define GPIO_RESET_N GPIO_OFFSET + 8
57 #define GPIO_START_N GPIO_OFFSET + 9
58 #define GPIO_SYNC_IN_N GPIO_OFFSET + 10
59 #define GPIO_SYNC_OUT_N GPIO_OFFSET + 11
60 #define GPIO_MODE_0_GPIO_0 GPIO_OFFSET + 16
61 #define GPIO_MODE_1_GPIO_1 GPIO_OFFSET + 17
62 #define GPIO_MODE_2_GPIO_2 GPIO_OFFSET + 18
63 #define GPIO_MODE_3_GPIO_3 GPIO_OFFSET + 19
64 #define GPIO_FILTER_GPIO_4 GPIO_OFFSET + 20
65
66 /* HDL Control Interface */
67
68 #define GPIO_UP_SSHOT GPIO_OFFSET + 4
69 #define GPIO_UP_FORMAT_1 GPIO_OFFSET + 3
70 #define GPIO_UP_FORMAT_0 GPIO_OFFSET + 2
71 #define GPIO_UP_CRC_ENABLE GPIO_OFFSET + 1
72 #define GPIO_UP_CRC_4_OR_16_N GPIO_OFFSET + 0
73 #define GPIO_STATUS_DEVICE_ID XPAR_AD7768_GPIO_DEVICE_ID
74 #define GPIO_STATUS_OFFSET 0
75 #define UP_STATUS_CLR_OFFSET GPIO_STATUS_OFFSET + 0
76 #define UP_STATUS_OFFSET GPIO_STATUS_OFFSET + 0
77
78 ad7768_init_param default_init_param = {
79 /* SPI */
80 SPI_AD7768_CS, // spi_chip_select
81 SPI_MODE_0, // spi_mode
82 PS7_SPI, // spi_type
83 SPI_DEVICE_ID, // spi_device_id
84 /* GPIO */
85 PS7_GPIO, // gpio_type
86 GPIO_DEVICE_ID, // gpio_device_id
87 GPIO_RESET_N, // gpio_reset
88 GPIO_HIGH, // gpio_reset_value
89 GPIO_MODE_0_GPIO_0, // gpio_mode0
90 GPIO_MODE_1_GPIO_1, // gpio_mode1
91 GPIO_MODE_2_GPIO_2, // gpio_mode2
92 GPIO_MODE_3_GPIO_3, // gpio_mode3
93 /* Configuration */
94 1, // pin_spi_input_value;
95 AD7768_ACTIVE, // sleep_mode
96 AD7768_FAST, // power_mode
97 AD7768_MCLK_DIV_4, // mclk_div
98 AD7768_DCLK_DIV_1, // dclk_div
99 AD7768_STANDARD_CONV, // conv_op
100 AD7768_CRC_16, // crc_sel
101 };
102
103 /***************************************************************************//**
104 * @brief ad7768evb_clear_status
105 *******************************************************************************/
106 void ad7768_evb_clear_status(gpio_device *gpio_dev)
107 {
108 uint8_t i;
109
110 for (i = 0; i < 32; i ++)
111 {
112 gpio_set_direction(gpio_dev,
113 UP_STATUS_OFFSET + i, GPIO_OUT);
114 gpio_set_value(gpio_dev,
115 UP_STATUS_OFFSET + i, 1);
116 }
117 }
118
119 /***************************************************************************//**
120 * @brief ad7768evb_verify_status
121 *******************************************************************************/
122 uint8_t ad7768_evb_verify_status(gpio_device *gpio_dev)
123 {
124 uint8_t i;
125 uint8_t value;
126 uint8_t status = 0;
127
128 for (i = 0; i < 32; i ++)
129 {
130 gpio_set_direction(gpio_dev,
131 UP_STATUS_OFFSET + i, GPIO_IN);
132 gpio_get_value(gpio_dev,
133 UP_STATUS_OFFSET + i, &value);
134 status += value;
135 }
136
137 return status;
138 }
139
140 /***************************************************************************//**
141 * @brief main
142 *******************************************************************************/
143 int main(void)
144 {
145 ad7768_dev *dev;
146 gpio_device gpio_dev;
147 adc_core core;
148
149 ad7768_setup(&dev, default_init_param);
150
151 /* Configure HDL */
152 gpio_set_direction(&dev->gpio_dev, GPIO_UP_FORMAT_1, GPIO_OUT);
153 gpio_set_value(&dev->gpio_dev, GPIO_UP_FORMAT_1, 0);
154 gpio_set_direction(&dev->gpio_dev, GPIO_UP_FORMAT_0, GPIO_OUT);
155 gpio_set_value(&dev->gpio_dev, GPIO_UP_FORMAT_0, 0);
156 gpio_set_direction(&dev->gpio_dev, GPIO_UP_CRC_ENABLE, GPIO_OUT);
157 gpio_set_value(&dev->gpio_dev, GPIO_UP_CRC_ENABLE,
158 dev->crc_sel ? 1 : 0);
159 gpio_set_direction(&dev->gpio_dev, GPIO_UP_CRC_4_OR_16_N, GPIO_OUT);
160 gpio_set_value(&dev->gpio_dev, GPIO_UP_CRC_4_OR_16_N,
161 dev->crc_sel == AD7768_CRC_4 ? 1 : 0);
162
163 gpio_dev.type = AXI_GPIO;
164 gpio_dev.device_id = XPAR_AD7768_GPIO_DEVICE_ID;
165 gpio_init(&gpio_dev);
166
167 ad7768_evb_clear_status(&gpio_dev);
168 if (ad7768_evb_verify_status(&gpio_dev))
169 printf("Interface errors\n");
170 else
171 printf("Interface OK\n");
172
173 core.dmac_baseaddr = AD7768_DMA_BASEADDR;
174 core.no_of_channels = 8;
175 core.resolution = 24;
176
177 printf("Capture samples...\n");
178 adc_capture(core, 1024, ADC_DDR_BASEADDR);
179 printf("Capture done\n");
180
181 if (ad7768_evb_verify_status(&gpio_dev))
182 printf("Interface errors\n");
183 else
184 printf("Interface OK\n");
185
186 return 0;
187 }