libpynq (release 5EWC0-2023 version 0.2.4 of 2023-10-07 15:07)
Loading...
Searching...
No Matches
xil_io.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2014 - 2021 Xilinx, Inc. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 ******************************************************************************/
5
6/*****************************************************************************/
35#ifndef XIL_IO_H /* prevent circular inclusions */
36#define XIL_IO_H /* by using protection macros */
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/***************************** Include Files *********************************/
43
44#include "xil_types.h"
45
46/************************** Function Prototypes ******************************/
47#ifdef ENABLE_SAFETY
48extern u32 XStl_RegUpdate(u32 RegAddr, u32 RegVal);
49#endif
50
51/***************** Macros (Inline Functions) Definitions *********************/
52#if defined __GNUC__
53#if defined(__MICROBLAZE__)
54#define INST_SYNC mbar(0)
55#define DATA_SYNC mbar(1)
56#else
57#define SYNCHRONIZE_IO dmb()
58#define INST_SYNC isb()
59#define DATA_SYNC dsb()
60#endif
61#else
62#define SYNCHRONIZE_IO
63#define INST_SYNC
64#define DATA_SYNC
65#define INST_SYNC
66#define DATA_SYNC
67#endif
68
69#if defined(__GNUC__) || defined(__ICCARM__) || defined(__MICROBLAZE__)
70#define INLINE inline
71#else
72#define INLINE __inline
73#endif
74
75/*****************************************************************************/
88static INLINE u8 Xil_In8(UINTPTR Addr) { return *(volatile u8 *)Addr; }
89
90/*****************************************************************************/
102static INLINE u16 Xil_In16(UINTPTR Addr) { return *(volatile u16 *)Addr; }
103
104/*****************************************************************************/
116static INLINE u32 Xil_In32(UINTPTR Addr) { return *(volatile u32 *)Addr; }
117
118/*****************************************************************************/
130static INLINE u64 Xil_In64(UINTPTR Addr) { return *(volatile u64 *)Addr; }
131
132/*****************************************************************************/
145static INLINE void Xil_Out8(UINTPTR Addr, u8 Value) {
146 /* write 8 bit value to specified address */
147 volatile u8 *LocalAddr = (volatile u8 *)Addr;
148 *LocalAddr = Value;
149}
150
151/*****************************************************************************/
163static INLINE void Xil_Out16(UINTPTR Addr, u16 Value) {
164 /* write 16 bit value to specified address */
165 volatile u16 *LocalAddr = (volatile u16 *)Addr;
166 *LocalAddr = Value;
167}
168
169/*****************************************************************************/
182static INLINE void Xil_Out32(UINTPTR Addr, u32 Value) {
183 /* write 32 bit value to specified address */
184#ifndef ENABLE_SAFETY
185 volatile u32 *LocalAddr = (volatile u32 *)Addr;
186 *LocalAddr = Value;
187#else
188 XStl_RegUpdate(Addr, Value);
189#endif
190}
191
192/*****************************************************************************/
205static INLINE void Xil_Out64(UINTPTR Addr, u64 Value) {
206 /* write 64 bit value to specified address */
207 volatile u64 *LocalAddr = (volatile u64 *)Addr;
208 *LocalAddr = Value;
209}
210
211/*****************************************************************************/
227static INLINE int Xil_SecureOut32(UINTPTR Addr, u32 Value) {
228 int Status = XST_FAILURE;
229 u32 ReadReg;
230 u32 ReadRegTemp;
231
232 /* writing 32 bit value to specified address */
233 Xil_Out32(Addr, Value);
234
235 /* verify value written to specified address with multiple reads */
236 ReadReg = Xil_In32(Addr);
237 ReadRegTemp = Xil_In32(Addr);
238
239 if ((ReadReg == Value) && (ReadRegTemp == Value)) {
240 Status = XST_SUCCESS;
241 }
242
243 return Status;
244}
245
246/*****************************************************************************/
256static INLINE __attribute__((always_inline)) u16 Xil_EndianSwap16(u16 Data) {
257 return (u16)(((Data & 0xFF00U) >> 8U) | ((Data & 0x00FFU) << 8U));
258}
259
260/*****************************************************************************/
270static INLINE __attribute__((always_inline)) u32 Xil_EndianSwap32(u32 Data) {
271 u16 LoWord;
272 u16 HiWord;
273
274 /* get each of the half words from the 32 bit word */
275
276 LoWord = (u16)(Data & 0x0000FFFFU);
277 HiWord = (u16)((Data & 0xFFFF0000U) >> 16U);
278
279 /* byte swap each of the 16 bit half words */
280
281 LoWord = (u16)(((LoWord & 0xFF00U) >> 8U) | ((LoWord & 0x00FFU) << 8U));
282 HiWord = (u16)(((HiWord & 0xFF00U) >> 8U) | ((HiWord & 0x00FFU) << 8U));
283
284 /* swap the half words before returning the value */
285
286 return ((((u32)LoWord) << (u32)16U) | (u32)HiWord);
287}
288
289#if defined(__MICROBLAZE__)
290#ifdef __LITTLE_ENDIAN__
291#define Xil_In16LE Xil_In16
292#define Xil_In32LE Xil_In32
293#define Xil_Out16LE Xil_Out16
294#define Xil_Out32LE Xil_Out32
295#define Xil_Htons Xil_EndianSwap16
296#define Xil_Htonl Xil_EndianSwap32
297#define Xil_Ntohs Xil_EndianSwap16
298#define Xil_Ntohl Xil_EndianSwap32
299#else
300#define Xil_In16BE Xil_In16
301#define Xil_In32BE Xil_In32
302#define Xil_Out16BE Xil_Out16
303#define Xil_Out32BE Xil_Out32
304#define Xil_Htons(Data) (Data)
305#define Xil_Htonl(Data) (Data)
306#define Xil_Ntohs(Data) (Data)
307#define Xil_Ntohl(Data) (Data)
308#endif
309#else
310#define Xil_In16LE Xil_In16
311#define Xil_In32LE Xil_In32
312#define Xil_Out16LE Xil_Out16
313#define Xil_Out32LE Xil_Out32
314#define Xil_Htons Xil_EndianSwap16
315#define Xil_Htonl Xil_EndianSwap32
316#define Xil_Ntohs Xil_EndianSwap16
317#define Xil_Ntohl Xil_EndianSwap32
318#endif
319
320#if defined(__MICROBLAZE__)
321#ifdef __LITTLE_ENDIAN__
322static INLINE u16 Xil_In16BE(UINTPTR Addr)
323#else
324static INLINE u16 Xil_In16LE(UINTPTR Addr)
325#endif
326#else
327static INLINE u16 Xil_In16BE(UINTPTR Addr)
328#endif
329{
330 u16 value = Xil_In16(Addr);
331 return Xil_EndianSwap16(value);
332}
333
334#if defined(__MICROBLAZE__)
335#ifdef __LITTLE_ENDIAN__
336static INLINE u32 Xil_In32BE(UINTPTR Addr)
337#else
338static INLINE u32 Xil_In32LE(UINTPTR Addr)
339#endif
340#else
341static INLINE u32 Xil_In32BE(UINTPTR Addr)
342#endif
343{
344 u32 value = Xil_In32(Addr);
345 return Xil_EndianSwap32(value);
346}
347
348#if defined(__MICROBLAZE__)
349#ifdef __LITTLE_ENDIAN__
350static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
351#else
352static INLINE void Xil_Out16LE(UINTPTR Addr, u16 Value)
353#endif
354#else
355static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
356#endif
357{
358 Value = Xil_EndianSwap16(Value);
359 Xil_Out16(Addr, Value);
360}
361
362#if defined(__MICROBLAZE__)
363#ifdef __LITTLE_ENDIAN__
364static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
365#else
366static INLINE void Xil_Out32LE(UINTPTR Addr, u32 Value)
367#endif
368#else
369static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
370#endif
371{
372 Value = Xil_EndianSwap32(Value);
373 Xil_Out32(Addr, Value);
374}
375
376#ifdef __cplusplus
377}
378#endif
379
380#endif /* end of protection macro */
#define INLINE
Definition xil_io.h:72
#define Xil_Out32LE
Definition xil_io.h:313
#define Xil_In16LE
Definition xil_io.h:310
#define Xil_Out16LE
Definition xil_io.h:312
#define Xil_In32LE
Definition xil_io.h:311