OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [tags/] [v0.0/] [sw/] [dev/] [test_main/] [src/] [_hdl/] [bsp/] [libsrc/] [standalone_v5_3/] [src/] [xil_io.c] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 kuzmi4
/******************************************************************************
2
*
3
* Copyright (C) 2009 - 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 xil_io.c
36
*
37
* Contains I/O functions for memory-mapped architectures.  These functions
38
* encapsulate generic CPU I/O requirements.
39
*
40
* <pre>
41
* MODIFICATION HISTORY:
42
*
43
* Ver   Who  Date        Changes
44
* ----- ---- -------- -------------------------------------------------------
45
* 3.00a hbm  07/28/09 Initial release
46
* 3.00a hbm  07/21/10 Added Xil_EndianSwap32/16, Xil_Htonl/s, Xil_Ntohl/s
47
*
48
* </pre>
49
*
50
* @note
51
*
52
* This file may contain architecture-dependent code.
53
*
54
******************************************************************************/
55
 
56
/***************************** Include Files *********************************/
57
 
58
#include "xil_io.h"
59
#include "xil_types.h"
60
 
61
/************************** Constant Definitions *****************************/
62
 
63
 
64
/**************************** Type Definitions *******************************/
65
 
66
 
67
/***************** Macros (Inline Functions) Definitions *********************/
68
 
69
 
70
/************************** Function Prototypes ******************************/
71
 
72
 
73
/***************** Macros (Inline Functions) and Functions Definitions *******/
74
 
75
/*****************************************************************************/
76
/**
77
*
78
* Perform an input operation for an 8-bit memory location by reading from the
79
* specified address and returning the value read from that address.
80
*
81
* @param        Addr contains the address to perform the input operation at.
82
*
83
* @return       The value read from the specified input address.
84
*
85
* @note         None.
86
*
87
******************************************************************************/
88
u8 Xil_In8(u32 Addr) {
89
//      return *(volatile u8 *)Addr;
90
    return( (u8)(axi_read_(Addr, 0x01)) );
91
}
92
 
93
/*****************************************************************************/
94
/**
95
*
96
* Perform an input operation for a 16-bit memory location by reading from the
97
* specified address and returning the value read from that address.
98
*
99
* @param        Addr contains the address to perform the input operation at.
100
*
101
* @return       The value read from the specified input address.
102
*
103
* @note         None.
104
*
105
******************************************************************************/
106
u16 Xil_In16(u32 Addr) {
107
//      return *(volatile u16 *)Addr;
108
    return( (u16)(axi_read_(Addr, 0x03)) );
109
}
110
 
111
/*****************************************************************************/
112
/**
113
*
114
* Performs an input operation for a 32-bit memory location by reading from the
115
* specified address and returning the Value read from that address.
116
*
117
* @param        Addr contains the address to perform the input operation at.
118
*
119
* @return       The value read from the specified input address.
120
*
121
* @note         None.
122
*
123
******************************************************************************/
124
u32 Xil_In32(u32 Addr) {
125
//      return *(volatile u32 *)Addr;
126
    return( (u32)(axi_read_(Addr, 0x0F)) );
127
}
128
 
129
 
130
/*****************************************************************************/
131
/**
132
*
133
* Perform an output operation for an 8-bit memory location by writing the
134
* specified value to the specified address.
135
*
136
* @param        Addr contains the address to perform the output operation at.
137
* @param        value contains the value to be output at the specified address.
138
*
139
* @return       None
140
*
141
* @note         None.
142
*
143
******************************************************************************/
144
void Xil_Out8(u32 Addr, u8 Value) {
145
//      u8 *LocalAddr = (u8 *)Addr;
146
//      *LocalAddr = Value;
147
    axi_write(Addr, 0x01 , Value);
148
}
149
 
150
/*****************************************************************************/
151
/**
152
*
153
* Perform an output operation for a 16-bit memory location by writing the
154
* specified value to the specified address.
155
*
156
* @param        Addr contains the address to perform the output operation at.
157
* @param        value contains the value to be output at the specified address.
158
*
159
* @return       None
160
*
161
* @note         None.
162
*
163
******************************************************************************/
164
void Xil_Out16(u32 Addr, u16 Value) {
165
//      u16 *LocalAddr = (u16 *)Addr;
166
//      *LocalAddr = Value;
167
    axi_write(Addr, 0x03, Value);
168
}
169
 
170
/*****************************************************************************/
171
/**
172
*
173
* Perform an output operation for a 32-bit memory location by writing the
174
* specified value to the specified address.
175
*
176
* @param        addr contains the address to perform the output operation at.
177
* @param        value contains the value to be output at the specified address.
178
*
179
* @return       None
180
*
181
* @note         None.
182
*
183
******************************************************************************/
184
void Xil_Out32(u32 Addr, u32 Value) {
185
//      u32 *LocalAddr = (u32 *)Addr;
186
//      *LocalAddr = Value;
187
    axi_write(Addr, 0x0F, Value);
188
}
189
 
190
/*****************************************************************************/
191
/**
192
*
193
* Perform a 16-bit endian converion.
194
*
195
* @param        Data contains the value to be converted.
196
*
197
* @return       converted value.
198
*
199
* @note         None.
200
*
201
******************************************************************************/
202
u16 Xil_EndianSwap16(u16 Data)
203
{
204
        return (u16) (((Data & 0xFF00U) >> 8U) | ((Data & 0x00FFU) << 8U));
205
}
206
 
207
/*****************************************************************************/
208
/**
209
*
210
* Perform a 32-bit endian converion.
211
*
212
* @param        Data contains the value to be converted.
213
*
214
* @return       converted value.
215
*
216
* @note         None.
217
*
218
******************************************************************************/
219
u32 Xil_EndianSwap32(u32 Data)
220
{
221
        u16 LoWord;
222
        u16 HiWord;
223
 
224
        /* get each of the half words from the 32 bit word */
225
 
226
        LoWord = (u16) (Data & 0x0000FFFFU);
227
        HiWord = (u16) ((Data & 0xFFFF0000U) >> 16U);
228
 
229
        /* byte swap each of the 16 bit half words */
230
 
231
        LoWord = (((LoWord & 0xFF00U) >> 8U) | ((LoWord & 0x00FFU) << 8U));
232
        HiWord = (((HiWord & 0xFF00U) >> 8U) | ((HiWord & 0x00FFU) << 8U));
233
 
234
        /* swap the half words before returning the value */
235
 
236
        return ((((u32)LoWord) << (u32)16U) | (u32)HiWord);
237
}
238
 
239
/*****************************************************************************/
240
/**
241
*
242
* Perform a little-endian input operation for a 16-bit memory location
243
* by reading from the specified address and returning the byte-swapped value
244
* read from that address.
245
*
246
* @param        Addr contains the address to perform the input operation at.
247
*
248
* @return       The value read from the specified input address with the
249
*               proper endianness. The return value has the same endianness
250
*               as that of the processor, i.e. if the processor is big-engian,
251
*               the return value is the byte-swapped value read from the
252
*               address.
253
*
254
*
255
* @note         None.
256
*
257
******************************************************************************/
258
#ifndef __LITTLE_ENDIAN__
259
u16 Xil_In16LE(u32 Addr)
260
#else
261
u16 Xil_In16BE(u32 Addr)
262
#endif
263
{
264
        u16 Value;
265
 
266
        /* get the data then swap it */
267
        Value = Xil_In16(Addr);
268
 
269
        return Xil_EndianSwap16(Value);
270
}
271
 
272
/*****************************************************************************/
273
/**
274
*
275
* Perform a little-endian input operation for a 32-bit memory location
276
* by reading from the specified address and returning the byte-swapped value
277
* read from that address.
278
*
279
* @param        Addr contains the address to perform the input operation at.
280
*
281
* @return       The value read from the specified input address with the
282
*               proper endianness. The return value has the same endianness
283
*               as that of the processor, i.e. if the processor is big-engian,
284
*               the return value is the byte-swapped value read from the
285
*               address.
286
*
287
* @note         None.
288
*
289
******************************************************************************/
290
#ifndef __LITTLE_ENDIAN__
291
u32 Xil_In32LE(u32 Addr)
292
#else
293
u32 Xil_In32BE(u32 Addr)
294
#endif
295
{
296
        u32 InValue;
297
 
298
        /* get the data then swap it */
299
        InValue = Xil_In32(Addr);
300
        return Xil_EndianSwap32(InValue);
301
}
302
 
303
/*****************************************************************************/
304
/**
305
*
306
* Perform a little-endian output operation for a 16-bit memory location by
307
* writing the specified value to the the specified address. The value is
308
* byte-swapped before being written.
309
*
310
* @param        Addr contains the address to perform the output operation at.
311
* @param        Value contains the value to be output at the specified address.
312
*               The value has the same endianness as that of the processor.
313
*               If the processor is big-endian, the byte-swapped value is
314
*               written to the address.
315
*
316
* @return       None.
317
*
318
* @note         None.
319
*
320
******************************************************************************/
321
#ifndef __LITTLE_ENDIAN__
322
void Xil_Out16LE(u32 Addr, u16 Value)
323
#else
324
void Xil_Out16BE(u32 Addr, u16 Value)
325
#endif
326
{
327
        u16 OutValue;
328
 
329
        /* swap the data then output it */
330
        OutValue = Xil_EndianSwap16(Value);
331
 
332
        Xil_Out16(Addr, OutValue);
333
}
334
 
335
/*****************************************************************************/
336
/**
337
*
338
* Perform a little-endian output operation for a 32-bit memory location
339
* by writing the specified value to the the specified address. The value is
340
* byte-swapped before being written.
341
*
342
* @param        Addr contains the address at which the output operation at.
343
* @param        Value contains the value to be output at the specified address.
344
*               The value has the same endianness as that of the processor.
345
*               If the processor is big-endian, the byte-swapped value is
346
*               written to the address.
347
*
348
* @return       None.
349
*
350
* @note         None.
351
*
352
******************************************************************************/
353
#ifndef __LITTLE_ENDIAN__
354
void Xil_Out32LE(u32 Addr, u32 Value)
355
#else
356
void Xil_Out32BE(u32 Addr, u32 Value)
357
#endif
358
{
359
        u32 OutValue;
360
 
361
        /* swap the data then output it */
362
        OutValue = Xil_EndianSwap32(Value);
363
        Xil_Out32(Addr, OutValue);
364
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.