1 /******************************************************************************
3 * Copyright (C) 2007 - 2014 Xilinx, Inc. All rights reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
31 ******************************************************************************/
32 /*****************************************************************************/
37 * This file contains the interface for the XIo component, which encapsulates
38 * the Input/Output functions for processors that do not require any special
42 * MODIFICATION HISTORY:
44 * Ver Who Date Changes
45 * ----- ---- -------- -------------------------------------------------------
46 * 1.00a rpm 11/07/03 Added InSwap/OutSwap routines for endian conversion
47 * 1.00a xd 11/04/04 Improved support for doxygen
48 * 1.01a ecm 02/24/06 CR225908 corrected the extra curly braces in macros
49 * and bumped version to 1.01.a.
50 * 1.11a mta 03/21/07 Updated to new coding style.
51 * 1.11b va 04/17/08 Updated Tcl for better CORE_CLOCK_FREQ_HZ definition
52 * 1.11a sdm 03/12/09 Updated Tcl to define correct value for CORE_CLOCK_FREQ_HZ
54 * 1.13a sdm 03/12/09 Updated the Tcl to pull appropriate libraries for Little
56 * 2.0 adk 19/12/13 Updated as per the New Tcl API's
57 * 2.1 bss 04/14/14 Updated tcl to copy libgloss.a and libgcc.a libraries
58 * 2.1 bss 04/29/14 Updated to copy libgloss.a if exists otherwise libxil.a
60 * 2.2 bss 08/04/14 Updated driver tcl to add protection macros for
61 * xparameters.h (CR#802257).
67 * This file may contain architecture-dependent items (memory-mapped or
68 * non-memory-mapped I/O).
70 ******************************************************************************/
72 #ifndef XIO_H /* prevent circular inclusions */
73 #define XIO_H /* by using protection macros */
79 /***************************** Include Files *********************************/
81 #include "xil_types.h"
82 #include "xil_assert.h"
84 /************************** Constant Definitions *****************************/
87 /**************************** Type Definitions *******************************/
90 * Typedef for an I/O address. Typically correlates to the width of the
93 typedef u32 XIo_Address;
95 /***************** Macros (Inline Functions) Definitions *********************/
98 * The following macros allow optimized I/O operations for memory mapped I/O.
99 * It should be noted that macros cannot be used if synchronization of the I/O
100 * operation is needed as it will likely break some code.
103 /*****************************************************************************/
106 * Performs an input operation for an 8-bit memory location by reading from the
107 * specified address and returning the value read from that address.
109 * @param InputPtr contains the address to perform the input operation at.
111 * @return The value read from the specified input address.
115 ******************************************************************************/
116 #define XIo_In8(InputPtr) (*(volatile u8 *)(InputPtr))
118 /*****************************************************************************/
121 * Performs an input operation for a 16-bit memory location by reading from the
122 * specified address and returning the value read from that address.
124 * @param InputPtr contains the address to perform the input operation at.
126 * @return The value read from the specified input address.
130 ******************************************************************************/
131 #define XIo_In16(InputPtr) (*(volatile u16 *)(InputPtr))
133 /*****************************************************************************/
136 * Performs an input operation for a 32-bit memory location by reading from the
137 * specified address and returning the value read from that address.
139 * @param InputPtr contains the address to perform the input operation at.
141 * @return The value read from the specified input address.
145 ******************************************************************************/
146 #define XIo_In32(InputPtr) (*(volatile u32 *)(InputPtr))
149 /*****************************************************************************/
152 * Performs an output operation for an 8-bit memory location by writing the
153 * specified value to the the specified address.
155 * @param OutputPtr contains the address to perform the output operation
157 * @param Value contains the value to be output at the specified address.
163 ******************************************************************************/
164 #define XIo_Out8(OutputPtr, Value) \
165 (*(volatile u8 *)((OutputPtr)) = (Value))
167 /*****************************************************************************/
170 * Performs an output operation for a 16-bit memory location by writing the
171 * specified value to the the specified address.
173 * @param OutputPtr contains the address to perform the output operation
175 * @param Value contains the value to be output at the specified address.
181 ******************************************************************************/
182 #define XIo_Out16(OutputPtr, Value) \
183 (*(volatile u16 *)((OutputPtr)) = (Value))
185 /*****************************************************************************/
188 * Performs an output operation for a 32-bit memory location by writing the
189 * specified value to the the specified address.
191 * @param OutputPtr contains the address to perform the output operation
193 * @param Value contains the value to be output at the specified address.
199 ******************************************************************************/
200 #define XIo_Out32(OutputPtr, Value) \
201 (*(volatile u32 *)((OutputPtr)) = (Value))
204 /* The following macros allow the software to be transportable across
205 * processors which use big or little endian memory models.
207 * Defined first is a no-op endian conversion macro. This macro is not to
208 * be used directly by software. Instead, the XIo_To/FromLittleEndianXX and
209 * XIo_To/FromBigEndianXX macros below are to be used to allow the endian
210 * conversion to only be performed when necessary
212 #define XIo_EndianNoop(Source, DestPtr) (*DestPtr = Source)
214 #ifdef XLITTLE_ENDIAN
216 #define XIo_ToLittleEndian16 XIo_EndianNoop
217 #define XIo_ToLittleEndian32 XIo_EndianNoop
218 #define XIo_FromLittleEndian16 XIo_EndianNoop
219 #define XIo_FromLittleEndian32 XIo_EndianNoop
221 #define XIo_ToBigEndian16(Source, DestPtr) XIo_EndianSwap16(Source, DestPtr)
222 #define XIo_ToBigEndian32(Source, DestPtr) XIo_EndianSwap32(Source, DestPtr)
223 #define XIo_FromBigEndian16 XIo_ToBigEndian16
224 #define XIo_FromBigEndian32 XIo_ToBigEndian32
228 #define XIo_ToLittleEndian16(Source, DestPtr) XIo_EndianSwap16(Source, DestPtr)
229 #define XIo_ToLittleEndian32(Source, DestPtr) XIo_EndianSwap32(Source, DestPtr)
230 #define XIo_FromLittleEndian16 XIo_ToLittleEndian16
231 #define XIo_FromLittleEndian32 XIo_ToLittleEndian32
233 #define XIo_ToBigEndian16 XIo_EndianNoop
234 #define XIo_ToBigEndian32 XIo_EndianNoop
235 #define XIo_FromBigEndian16 XIo_EndianNoop
236 #define XIo_FromBigEndian32 XIo_EndianNoop
240 /************************** Function Prototypes ******************************/
242 /* The following functions allow the software to be transportable across
243 * processors which use big or little endian memory models. These functions
244 * should not be directly called, but the macros XIo_To/FromLittleEndianXX and
245 * XIo_To/FromBigEndianXX should be used to allow the endian conversion to only
246 * be performed when necessary.
248 void XIo_EndianSwap16(u16 Source, u16 *DestPtr);
249 void XIo_EndianSwap32(u32 Source, u32 *DestPtr);
251 /* The following functions handle IO addresses where data must be swapped
252 * They cannot be implemented as macros
254 u16 XIo_InSwap16(XIo_Address InAddress);
255 u32 XIo_InSwap32(XIo_Address InAddress);
256 void XIo_OutSwap16(XIo_Address OutAddress, u16 Value);
257 void XIo_OutSwap32(XIo_Address OutAddress, u32 Value);
263 #endif /* end of protection macro */