| 1 | /***************************************************************************//** |
| 2 | * @file ad7616_sdz.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 <stdbool.h> |
| 44 | #include <stdint.h> |
| 45 | #include <stdio.h> |
| 46 | #include "spi_engine.h" |
| 47 | #include <xil_cache.h> |
| 48 | #include <xparameters.h> |
| 49 | #include "platform_drivers.h" |
| 50 | #include "ad7616_core.h" |
| 51 | #include "ad7616.h" |
| 52 | |
| 53 | /******************************************************************************/ |
| 54 | /********************** Macros and Constants Definitions **********************/ |
| 55 | /******************************************************************************/ |
| 56 | #define AD7616_CORE_BASEADDR XPAR_AXI_AD7616_BASEADDR |
| 57 | #define AD7616_DMA_BASEADDR XPAR_AXI_AD7616_DMA_BASEADDR |
| 58 | #define SPI_AD7616_CS 0 |
| 59 | #define GPIO_DEVICE_ID XPAR_PS7_GPIO_0_DEVICE_ID |
| 60 | #define GPIO_OFFSET 32 + 54 |
| 61 | #define GPIO_ADC_CRCEN GPIO_OFFSET + 0 |
| 62 | #define GPIO_ADC_CHSEL0 GPIO_OFFSET + 1 |
| 63 | #define GPIO_ADC_CHSEL1 GPIO_OFFSET + 2 |
| 64 | #define GPIO_ADC_CHSEL2 GPIO_OFFSET + 3 |
| 65 | #define GPIO_ADC_BURST GPIO_OFFSET + 4 |
| 66 | #define GPIO_ADC_SEQEN GPIO_OFFSET + 5 |
| 67 | #define GPIO_ADC_OS0 GPIO_OFFSET + 6 |
| 68 | #define GPIO_ADC_OS1 GPIO_OFFSET + 7 |
| 69 | #define GPIO_ADC_OS2 GPIO_OFFSET + 8 |
| 70 | #define GPIO_ADC_HW_RNGSEL0 GPIO_OFFSET + 9 |
| 71 | #define GPIO_ADC_HW_RNGSEL1 GPIO_OFFSET + 10 |
| 72 | #define GPIO_ADC_RESET_N GPIO_OFFSET + 11 |
| 73 | #define ADC_DDR_BASEADDR XPAR_DDR_MEM_BASEADDR + 0x800000 |
| 74 | |
| 75 | /******************************************************************************/ |
| 76 | /************************ Variables Definitions *******************************/ |
| 77 | /******************************************************************************/ |
| 78 | ad7616_init_param default_init_param = { |
| 79 | /* SPI */ |
| 80 | SPI_AD7616_CS, // spi_chip_select |
| 81 | SPI_MODE_2, // spi_mode |
| 82 | SPI_ENGINE, // spi_type |
| 83 | -1, // spi_device_id |
| 84 | /* GPIO */ |
| 85 | PS7_GPIO, // gpio_type |
| 86 | GPIO_DEVICE_ID, // gpio_device_id |
| 87 | -1, // gpio_hw_rngsel0 |
| 88 | -1, // gpio_hw_rngsel1 |
| 89 | GPIO_ADC_RESET_N, // gpio_reset |
| 90 | -1, // gpio_os0 |
| 91 | -1, // gpio_os1 |
| 92 | -1, // gpio_os2 |
| 93 | /* Device Settings */ |
| 94 | AD7616_SW, // mode |
| 95 | {AD7616_10V, AD7616_10V, AD7616_10V, AD7616_10V, |
| 96 | AD7616_10V, AD7616_10V, AD7616_10V, AD7616_10V}, // va[8] |
| 97 | {AD7616_10V, AD7616_10V, AD7616_10V, AD7616_10V, |
| 98 | AD7616_10V, AD7616_10V, AD7616_10V, AD7616_10V}, // vb[8] |
| 99 | AD7616_OSR_0, // osr |
| 100 | }; |
| 101 | |
| 102 | /***************************************************************************//** |
| 103 | * @brief main |
| 104 | *******************************************************************************/ |
| 105 | int main(void) |
| 106 | { |
| 107 | ad7616_dev *dev; |
| 108 | adc_core core; |
| 109 | uint8_t reg_addr; |
| 110 | uint16_t reg_data; |
| 111 | |
| 112 | Xil_ICacheEnable(); |
| 113 | Xil_DCacheEnable(); |
| 114 | |
| 115 | printf("Hello\n"); |
| 116 | |
| 117 | core.adc_baseaddr = AD7616_CORE_BASEADDR; |
| 118 | core.dmac_baseaddr = AD7616_DMA_BASEADDR; |
| 119 | core.no_of_channels = 2; |
| 120 | core.resolution = 16; |
| 121 | ad7616_core_setup(core); |
| 122 | |
| 123 | ad7616_setup(&dev, &core, default_init_param); |
| 124 | |
| 125 | for (reg_addr = 2; reg_addr <= 0x07; reg_addr++) { |
| 126 | ad7616_read(dev, reg_addr, ®_data); |
| 127 | printf("0x%x = 0x%x\n", reg_addr, reg_data); |
| 128 | } |
| 129 | |
| 130 | if (dev->interface == AD7616_PARALLEL) |
| 131 | ad7616_capture_parallel(core, 16384, ADC_DDR_BASEADDR); |
| 132 | else |
| 133 | ad7616_capture_serial(core, 16384, ADC_DDR_BASEADDR); |
| 134 | |
| 135 | printf("Bye\n"); |
| 136 | |
| 137 | Xil_DCacheDisable(); |
| 138 | Xil_ICacheDisable(); |
| 139 | |
| 140 | return 0; |
| 141 | } |