Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/ad7616-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 /******************************************************************************/
80 /*************************** Types Declarations *******************************/
81 /******************************************************************************/
82 typedef enum {
83 AXI_GPIO,
84 PS7_GPIO,
85 } gpio_type;
86
87 typedef struct {
88 gpio_type type;
89 uint32_t device_id;
90 #ifdef XPAR_GPIO_0_DEVICE_ID
91 XGpio_Config *axi_config;
92 XGpio axi_instance;
93 #endif
94 #ifdef XPAR_PS7_GPIO_0_DEVICE_ID
95 XGpioPs_Config *ps7_config;
96 XGpioPs ps7_instance;
97 #endif
98 } gpio_device;
99
100 typedef enum {
101 SPI_MODE_0 = (0 | 0),
102 SPI_MODE_1 = (0 | SPI_CPHA),
103 SPI_MODE_2 = (SPI_CPOL | 0),
104 SPI_MODE_3 = (SPI_CPOL | SPI_CPHA),
105 } spi_mode;
106
107 typedef enum {
108 AXI_SPI,
109 PS7_SPI,
110 SPI_ENGINE,
111 } spi_type;
112
113 typedef struct {
114 uint8_t chip_select;
115 spi_mode mode;
116 spi_type type;
117 uint32_t device_id;
118 #ifdef XPAR_SPI_0_DEVICE_ID
119 XSpi_Config *axi_config;
120 XSpi axi_instance;
121 #endif
122 #ifdef XPAR_PS7_SPI_0_DEVICE_ID
123 XSpiPs_Config *ps7_config;
124 XSpiPs ps7_instance;
125 #endif
126 } spi_device;
127
128 /******************************************************************************/
129 /************************ Functions Declarations ******************************/
130 /******************************************************************************/
131 int32_t spi_init(spi_device *dev);
132 int32_t spi_write_and_read(spi_device *dev,
133 uint8_t *data,
134 uint8_t bytes_number);
135 int32_t gpio_init(gpio_device *dev);
136 int32_t gpio_set_direction(gpio_device *dev,
137 uint8_t pin,
138 uint8_t direction);
139 int32_t gpio_set_value(gpio_device *dev,
140 uint8_t pin,
141 uint8_t data);
142 int32_t gpio_get_value(gpio_device *dev,
143 uint8_t pin,
144 uint8_t *data);
145 void mdelay(uint32_t msecs);
146 uint64_t do_div(uint64_t* n, uint64_t base);
147 #endif