Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad5766-sdz/platform_drivers.h

raw symbols SCIP
1 /***************************************************************************//**
2 * @file platform_drivers.h
3 * @brief Header file of Platform Drivers.
4 * @author DBogdan ([email protected])
5 ********************************************************************************
6 * Copyright 2014-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 #ifndef PLATFORM_DRIVERS_H_
40 #define PLATFORM_DRIVERS_H_
41
42 /******************************************************************************/
43 /***************************** Include Files **********************************/
44 /******************************************************************************/
45 #include "xparameters.h"
46 #include <stdint.h>
47 #ifdef XPAR_GPIO_0_DEVICE_ID
48 #include <xgpio.h>
49 #endif
50 #ifdef XPAR_PS7_GPIO_0_DEVICE_ID
51 #include <xgpiops.h>
52 #endif
53 #ifdef XPAR_SPI_0_DEVICE_ID
54 #include <xspi.h>
55 #endif
56 #ifdef XPAR_PS7_SPI_0_DEVICE_ID
57 #include <xspips.h>
58 #endif
59
60 /******************************************************************************/
61 /********************** Macros and Constants Definitions **********************/
62 /******************************************************************************/
63 #define min(x, y) (((x) < (y)) ? (x) : (y))
64 #define min_t(type, x, y) (type)min((type)(x), (type)(y))
65 #define max(x, y) (((x) > (y)) ? (x) : (y))
66 #define max_t(type, x, y) (type)max((type)(x), (type)(y))
67 #define clamp(val, min_val, max_val) (max(min((val), (max_val)), (min_val)))
68 #define clamp_t(type, val, min_val, max_val) (type)clamp((type)(val), \
69 (type)(min_val), (type)(max_val))
70
71 #define GPIO_OUT 1
72 #define GPIO_IN 0
73 #define GPIO_HIGH 1
74 #define GPIO_LOW 0
75
76 #define SPI_CPHA 0x01
77 #define SPI_CPOL 0x02
78
79 #define SUCCESS 0
80 #define FAILURE -1
81
82 /******************************************************************************/
83 /*************************** Types Declarations *******************************/
84 /******************************************************************************/
85 typedef enum {
86 AXI_GPIO,
87 PS7_GPIO,
88 } gpio_type;
89
90 typedef struct {
91 gpio_type type;
92 uint32_t device_id;
93 #ifdef XPAR_GPIO_0_DEVICE_ID
94 XGpio_Config *axi_config;
95 XGpio axi_instance;
96 #endif
97 #ifdef XPAR_PS7_GPIO_0_DEVICE_ID
98 XGpioPs_Config *ps7_config;
99 XGpioPs ps7_instance;
100 #endif
101 } gpio_device;
102
103 typedef enum {
104 SPI_MODE_0 = (0 | 0),
105 SPI_MODE_1 = (0 | SPI_CPHA),
106 SPI_MODE_2 = (SPI_CPOL | 0),
107 SPI_MODE_3 = (SPI_CPOL | SPI_CPHA),
108 } spi_mode;
109
110 typedef enum {
111 AXI_SPI,
112 PS7_SPI,
113 SPI_ENGINE,
114 } spi_type;
115
116 typedef struct {
117 uint8_t chip_select;
118 spi_mode mode;
119 spi_type type;
120 uint32_t device_id;
121 #ifdef XPAR_SPI_0_DEVICE_ID
122 XSpi_Config *axi_config;
123 XSpi axi_instance;
124 #endif
125 #ifdef XPAR_PS7_SPI_0_DEVICE_ID
126 XSpiPs_Config *ps7_config;
127 XSpiPs ps7_instance;
128 #endif
129 } spi_device;
130
131 /******************************************************************************/
132 /************************ Functions Declarations ******************************/
133 /******************************************************************************/
134 int32_t spi_init(spi_device *dev);
135 int32_t spi_write_and_read(spi_device *dev,
136 uint8_t *data,
137 uint8_t bytes_number);
138 int32_t gpio_init(gpio_device *dev);
139 int32_t gpio_set_direction(gpio_device *dev,
140 uint8_t pin,
141 uint8_t direction);
142 int32_t gpio_set_value(gpio_device *dev,
143 uint8_t pin,
144 uint8_t data);
145 int32_t gpio_get_value(gpio_device *dev,
146 uint8_t pin,
147 uint8_t *data);
148 void mdelay(uint32_t msecs);
149 uint64_t do_div(uint64_t* n, uint64_t base);
150 #endif