Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/common_drivers/platform_drivers/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-2015(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
46 #ifdef ALTERA
47 #include <io.h>
48 #include <unistd.h>
49 #include <stdio.h>
50 #include <system.h>
51 #include <alt_stdio.h>
52 #include <alt_cache.h>
53 #include <alt_types.h>
54 #endif
55
56 #ifdef NIOS_II
57 #endif
58
59 #ifdef XILINX
60 #include <xparameters.h>
61 #include <xil_printf.h>
62 #include "platform.h"
63 #endif
64
65 #ifdef ZYNQ
66 #include <sleep.h>
67 #include <xspips.h>
68 #include <xuartps.h>
69 #endif
70
71 #ifdef MICROBLAZE
72 #include <xil_io.h>
73 #include <xil_cache.h>
74 #endif
75
76 /******************************************************************************/
77 /********************** Macros and Constants Definitions **********************/
78 /******************************************************************************/
79
80 // data types using stdint-
81
82 #ifdef ALTERA
83 #define int8_t alt_8
84 #define int32_t alt_32
85 #define uint8_t alt_u8
86 #define uint16_t alt_u16
87 #define uint32_t alt_u32
88 #define uint64_t alt_u64
89 #endif
90
91 // sleep functions
92
93 #define mdelay(msecs) usleep(1000*msecs)
94 #define udelay(usecs) usleep(usecs)
95
96 #ifdef MICROBLAZE
97 void usleep(uint32_t us_count);
98 #endif
99
100 // print functions
101
102 #ifdef ALTERA
103 #define ad_printf printf
104 #endif
105
106 #ifdef XILINX
107 #define ad_printf xil_printf
108 #endif
109
110 // io read/write
111
112 #ifdef ALTERA
113 #define ad_reg_write(x,y) IOWR_32DIRECT(x,0,y)
114 #define ad_reg_read(x) IORD_32DIRECT(x,0)
115 #endif
116
117 #ifdef XILINX
118 #define ad_reg_write(x,y) Xil_Out32(x,y)
119 #define ad_reg_read(x) Xil_In32(x)
120 #endif
121
122 // cache functions
123
124 #ifdef ALTERA
125 #define ad_icache_flush alt_icache_flush_all
126 #define ad_dcache_flush alt_icache_flush_all
127 #endif
128
129 #ifdef XILINX
130 #define ad_icache_flush Xil_ICacheFlush
131 #define ad_dcache_flush Xil_DCacheFlush
132 #endif
133
134 #ifdef ZYNQ
135 void Xil_ICacheEnable();
136 void Xil_ICacheDisable();
137 void Xil_DCacheEnable();
138 void Xil_DCacheDisable();
139 void Xil_DCacheFlush();
140 #endif
141
142 // platform functions
143
144 #ifdef XILINX
145 #define ad_platform_init init_platform
146 #define ad_platform_close cleanup_platform
147 #endif
148
149 #ifdef ALTERA
150 void ad_platform_init(void);
151 void ad_platform_close(void);
152 #endif
153
154 // common macros
155
156 #define min(x, y) (((x) < (y)) ? (x) : (y))
157 #define min_t(type, x, y) (type)min((type)(x), (type)(y))
158 #define max(x, y) (((x) > (y)) ? (x) : (y))
159 #define max_t(type, x, y) (type)max((type)(x), (type)(y))
160 #define clamp(val, min_val, max_val) (max(min((val), (max_val)), (min_val)))
161 #define clamp_t(type, val, min_val, max_val) (type)clamp((type)(val), \
162 (type)(min_val), (type)(max_val))
163
164 /******************************************************************************/
165 /********************** SPI structure and functions ***************************/
166 /******************************************************************************/
167
168 // you may override the default spi structure-- the drivers simply turn around
169 // the spi structure back to spi function calls.
170
171 typedef struct {
172 uint32_t base_address;
173 uint32_t device_id;
174 uint8_t chip_select;
175 uint32_t cpha;
176 uint32_t cpol;
177 } spi_device;
178
179 int32_t ad_spi_init(spi_device *dev);
180 int32_t ad_spi_xfer(spi_device *dev, uint8_t *data, uint8_t no_of_bytes);
181
182 /******************************************************************************/
183 /********************* GPIO structure and functions ***************************/
184 /******************************************************************************/
185
186 int32_t ad_gpio_set(uint8_t pin, uint8_t data);
187 int32_t ad_gpio_get(uint8_t pin, uint8_t *data);
188
189 /******************************************************************************/
190 /********************* MISC structure and functions ***************************/
191 /******************************************************************************/
192
193 uint64_t do_div(uint64_t* n, uint64_t base);
194 void ad_reg_write_16(uint32_t addr, uint32_t data);
195 uint8_t ad_uart_read();
196
197 #endif