Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/adaq7980-sdz/adaq7980_sdz.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file adaq7980_sdz.c
3 * @brief Implementation of Main Function.
4 * @author ADI
5 ********************************************************************************
6 * Copyright 2017(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 <stdlib.h>
47 #include <xil_cache.h>
48 #include <xparameters.h>
49 #include "platform_drivers.h"
50 #include "adaq7980.h"
51 #include "spi_engine.h"
52
53 /******************************************************************************/
54 /********************** Macros and Constants Definitions **********************/
55 /******************************************************************************/
56
57 #define ADAQ7980_DMA_BASEADDR XPAR_AXI_ADAQ7980_DMA_BASEADDR
58 #define ADAQ7980_SPI_ENGINE_BASEADDR XPAR_SPI_AXI_BASEADDR
59 #define SPI_ADAQ7980_CS 0
60 #define GPIO_DEVICE_ID XPAR_PS7_GPIO_0_DEVICE_ID
61 #define GPIO_OFFSET 32 + 54
62 #define GPIO_0 GPIO_OFFSET + 0
63 #define GPIO_1 GPIO_OFFSET + 1
64 #define GPIO_2 GPIO_OFFSET + 2
65 #define GPIO_3 GPIO_OFFSET + 3
66 #define GPIO_4 GPIO_OFFSET + 4
67 #define GPIO_5 GPIO_OFFSET + 5
68 #define GPIO_6 GPIO_OFFSET + 6
69 #define GPIO_7 GPIO_OFFSET + 7
70 #define GPIO_REF_PUB GPIO_OFFSET + 8
71 #define GPIO_RBUF_PUB GPIO_OFFSET + 9
72 #define ADC_DDR_BASEADDR XPAR_DDR_MEM_BASEADDR + 0x800000
73
74 /******************************************************************************/
75 /************************ Variables Definitions *******************************/
76 /******************************************************************************/
77
78 adaq7980_init_param default_init_param = {
79 /* SPI */
80 SPI_ADAQ7980_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 GPIO_0, // gpio_ld_ldo
88 GPIO_REF_PUB, // gpio_ref_pd
89 GPIO_RBUF_PUB, // gpio_rbuf_pd
90 };
91
92 uint32_t spi_msg_cmds[6] = {CS_DEASSERT, CS_ASSERT, SLEEP(5000), CS_DEASSERT, TRANSFER_R(4), CS_ASSERT};
93
94 spi_init_param spi_default_init_param = {
95 ADAQ7980_SPI_ENGINE_BASEADDR, // adc_baseaddr
96 0, // chip_select
97 SPI_ENGINE_CONFIG_CPHA, // spi_config
98 1000000, // spi_clk_hz
99 100000000, // ref_clk_hz
100 1, // spi_offload_rx_support_en
101 ADAQ7980_DMA_BASEADDR, // spi_offload_rx_dma_baseaddr
102 0, // spi_offload_tx_support_en
103 ADAQ7980_DMA_BASEADDR, // spi_offload_tx_dma_baseaddr
104 };
105
106 #define SPI_ENGINE_OFFLOAD_EXAMPLE 0
107
108 /***************************************************************************//**
109 * @brief main
110 *******************************************************************************/
111 int main(void)
112 {
113 adaq7980_dev *dev;
114 spi_dev *spi_dev;
115 spi_msg *msg;
116 uint8_t *data;
117 uint32_t i;
118
119 Xil_ICacheEnable();
120 Xil_DCacheEnable();
121
122 adaq7980_setup(&dev, default_init_param);
123 spi_eng_setup(&spi_dev, spi_default_init_param);
124
125 msg = (spi_msg *)malloc(sizeof(*msg));
126 if (!msg)
127 return -1;
128
129 msg->rx_buf_addr = 0x10000000;
130 msg->spi_msg_cmds = spi_msg_cmds;
131 msg->msg_cmd_len = sizeof(spi_msg_cmds) / sizeof(uint32_t);
132
133 if (SPI_ENGINE_OFFLOAD_EXAMPLE == 0) {
134
135 while(1){
136 spi_eng_transfer_message(spi_dev, msg);
137 mdelay(1000);
138 }
139
140 } else {
141 spi_eng_offload_load_msg(spi_dev, msg);
142 spi_eng_transfer_multiple_msgs(spi_dev, 8);
143
144 data = (uint8_t*)spi_dev->rx_dma_startaddr;
145
146 for(i = 0; i < spi_dev->rx_length; i++) {
147 printf("%x\r\n", *data);
148 data += sizeof(uint8_t);
149 }
150 }
151
152 printf("Bye\n");
153
154 Xil_DCacheDisable();
155 Xil_ICacheDisable();
156
157 return 0;
158 }