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 * Contains I/O functions for memory-mapped or non-memory-mapped I/O
38 * architectures. These functions encapsulate generic CPU I/O requirements.
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- ---- -------- -------------------------------------------------------
45 * 1.00a rpm 11/07/03 Added InSwap/OutSwap routines for endian conversion
46 * 1.01a ecm 02/24/06 CR225908 corrected the extra curly braces in macros
47 * and bumped version to 1.01.a.
48 * 2.11a mta 03/21/07 Updated to new coding style.
54 * This file may contain architecture-dependent code.
56 ******************************************************************************/
58 /***************************** Include Files *********************************/
61 #include "xil_types.h"
62 #include "xil_assert.h"
64 /************************** Constant Definitions *****************************/
67 /**************************** Type Definitions *******************************/
70 /***************** Macros (Inline Functions) Definitions *********************/
73 /************************** Function Prototypes ******************************/
76 /*****************************************************************************/
79 * Performs a 16-bit endian converion.
81 * @param Source contains the value to be converted.
82 * @param DestPtr contains a pointer to the location to put the
89 ******************************************************************************/
90 void XIo_EndianSwap16(u16 Source, u16 *DestPtr)
92 *DestPtr = (u16) (((Source & 0xFF00) >> 8) | ((Source & 0x00FF) << 8));
95 /*****************************************************************************/
98 * Performs a 32-bit endian converion.
100 * @param Source contains the value to be converted.
101 * @param DestPtr contains a pointer to the location to put the
108 ******************************************************************************/
109 void XIo_EndianSwap32(u32 Source, u32 *DestPtr)
111 /* get each of the half words from the 32 bit word */
113 u16 LoWord = (u16) (Source & 0x0000FFFF);
114 u16 HiWord = (u16) ((Source & 0xFFFF0000) >> 16);
116 /* byte swap each of the 16 bit half words */
118 LoWord = (((LoWord & 0xFF00) >> 8) | ((LoWord & 0x00FF) << 8));
119 HiWord = (((HiWord & 0xFF00) >> 8) | ((HiWord & 0x00FF) << 8));
121 /* swap the half words before returning the value */
123 *DestPtr = (u32) ((LoWord << 16) | HiWord);
126 /*****************************************************************************/
129 * Performs an input operation for a 16-bit memory location by reading from the
130 * specified address and returning the byte-swapped value read from that
133 * @param InAddress contains the address to perform the input
136 * @return The byte-swapped value read from the specified input address.
140 ******************************************************************************/
141 u16 XIo_InSwap16(XIo_Address InAddress)
145 /* get the data then swap it */
146 InData = XIo_In16(InAddress);
148 return (u16) (((InData & 0xFF00) >> 8) | ((InData & 0x00FF) << 8));
151 /*****************************************************************************/
154 * Performs an input operation for a 32-bit memory location by reading from the
155 * specified address and returning the byte-swapped value read from that
158 * @param InAddress contains the address to perform the input
161 * @return The byte-swapped value read from the specified input address.
165 ******************************************************************************/
166 u32 XIo_InSwap32(XIo_Address InAddress)
171 /* get the data then swap it */
172 InData = XIo_In32(InAddress);
173 XIo_EndianSwap32(InData, &SwapData);
178 /*****************************************************************************/
181 * Performs an output operation for a 16-bit memory location by writing the
182 * specified value to the the specified address. The value is byte-swapped
183 * before being written.
185 * @param OutAddress contains the address to perform the output
187 * @param Value contains the value to be output at the specified address.
193 ******************************************************************************/
194 void XIo_OutSwap16(XIo_Address OutAddress, u16 Value)
198 /* swap the data then output it */
199 OutData = (u16) (((Value & 0xFF00) >> 8) | ((Value & 0x00FF) << 8));
201 XIo_Out16(OutAddress, OutData);
204 /*****************************************************************************/
207 * Performs an output operation for a 32-bit memory location by writing the
208 * specified value to the the specified address. The value is byte-swapped
209 * before being written.
211 * @param OutAddress contains the address at which the
212 * output operation has to be done.
213 * @param Value contains the value to be output at the specified address.
219 ******************************************************************************/
220 void XIo_OutSwap32(XIo_Address OutAddress, u32 Value)
224 /* swap the data then output it */
225 XIo_EndianSwap32(Value, &OutData);
226 XIo_Out32(OutAddress, OutData);