]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Kintex7_EthernetLite/BSP/microblaze_0/libsrc/cpu_v2_2/src/xio.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / MicroBlaze_Kintex7_EthernetLite / BSP / microblaze_0 / libsrc / cpu_v2_2 / src / xio.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2007 - 2014 Xilinx, Inc.  All rights reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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.
18 *
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
25 * SOFTWARE.
26 *
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.
30 *
31 ******************************************************************************/
32 /*****************************************************************************/
33 /**
34 *
35 * @file xio.c
36 *
37 * Contains I/O functions for memory-mapped or non-memory-mapped I/O
38 * architectures.  These functions encapsulate generic CPU I/O requirements.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
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.
49 *
50 * </pre>
51 *
52 * @note
53 *
54 * This file may contain architecture-dependent code.
55 *
56 ******************************************************************************/
57
58 /***************************** Include Files *********************************/
59
60 #include "xio.h"
61 #include "xil_types.h"
62 #include "xil_assert.h"
63
64 /************************** Constant Definitions *****************************/
65
66
67 /**************************** Type Definitions *******************************/
68
69
70 /***************** Macros (Inline Functions) Definitions *********************/
71
72
73 /************************** Function Prototypes ******************************/
74
75
76 /*****************************************************************************/
77 /**
78 *
79 * Performs a 16-bit endian converion.
80 *
81 * @param        Source contains the value to be converted.
82 * @param        DestPtr contains a pointer to the location to put the
83 *               converted value.
84 *
85 * @return       None.
86 *
87 * @note         None.
88 *
89 ******************************************************************************/
90 void XIo_EndianSwap16(u16 Source, u16 *DestPtr)
91 {
92         *DestPtr = (u16) (((Source & 0xFF00) >> 8) | ((Source & 0x00FF) << 8));
93 }
94
95 /*****************************************************************************/
96 /**
97 *
98 * Performs a 32-bit endian converion.
99 *
100 * @param        Source contains the value to be converted.
101 * @param        DestPtr contains a pointer to the location to put the
102 *               converted value.
103 *
104 * @return       None.
105 *
106 * @note         None.
107 *
108 ******************************************************************************/
109 void XIo_EndianSwap32(u32 Source, u32 *DestPtr)
110 {
111         /* get each of the half words from the 32 bit word */
112
113         u16 LoWord = (u16) (Source & 0x0000FFFF);
114         u16 HiWord = (u16) ((Source & 0xFFFF0000) >> 16);
115
116         /* byte swap each of the 16 bit half words */
117
118         LoWord = (((LoWord & 0xFF00) >> 8) | ((LoWord & 0x00FF) << 8));
119         HiWord = (((HiWord & 0xFF00) >> 8) | ((HiWord & 0x00FF) << 8));
120
121         /* swap the half words before returning the value */
122
123         *DestPtr = (u32) ((LoWord << 16) | HiWord);
124 }
125
126 /*****************************************************************************/
127 /**
128 *
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
131 * address.
132 *
133 * @param        InAddress contains the address to perform the input
134 *               operation at.
135 *
136 * @return       The byte-swapped value read from the specified input address.
137 *
138 * @note         None.
139 *
140 ******************************************************************************/
141 u16 XIo_InSwap16(XIo_Address InAddress)
142 {
143         u16 InData;
144
145         /* get the data then swap it */
146         InData = XIo_In16(InAddress);
147
148         return (u16) (((InData & 0xFF00) >> 8) | ((InData & 0x00FF) << 8));
149 }
150
151 /*****************************************************************************/
152 /**
153 *
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
156 * address.
157 *
158 * @param        InAddress contains the address to perform the input
159 *               operation at.
160 *
161 * @return       The byte-swapped value read from the specified input address.
162 *
163 * @note         None.
164 *
165 ******************************************************************************/
166 u32 XIo_InSwap32(XIo_Address InAddress)
167 {
168         u32 InData;
169         u32 SwapData;
170
171         /* get the data then swap it */
172         InData = XIo_In32(InAddress);
173         XIo_EndianSwap32(InData, &SwapData);
174
175         return SwapData;
176 }
177
178 /*****************************************************************************/
179 /**
180 *
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.
184 *
185 * @param        OutAddress contains the address to perform the output
186 *               operation at.
187 * @param        Value contains the value to be output at the specified address.
188 *
189 * @return       None.
190 *
191 * @note         None.
192 *
193 ******************************************************************************/
194 void XIo_OutSwap16(XIo_Address OutAddress, u16 Value)
195 {
196         u16 OutData;
197
198         /* swap the data then output it */
199         OutData = (u16) (((Value & 0xFF00) >> 8) | ((Value & 0x00FF) << 8));
200
201         XIo_Out16(OutAddress, OutData);
202 }
203
204 /*****************************************************************************/
205 /**
206 *
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.
210 *
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.
214 *
215 * @return       None.
216 *
217 * @note         None.
218 *
219 ******************************************************************************/
220 void XIo_OutSwap32(XIo_Address OutAddress, u32 Value)
221 {
222         u32 OutData;
223
224         /* swap the data then output it */
225         XIo_EndianSwap32(Value, &OutData);
226         XIo_Out32(OutAddress, OutData);
227 }