RTEMS 6.1-rc1
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/*****************************************************************************/
39#ifndef XIL_IO_H /* prevent circular inclusions */
40#define XIL_IO_H /* by using protection macros */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46/***************************** Include Files *********************************/
47
48#include "xil_types.h"
49#include "xil_printf.h"
50#include "xstatus.h"
51
52#if defined (__MICROBLAZE__)
53#include "mb_interface.h"
54#else
55#include "xpseudo_asm.h"
56#endif
57
58/************************** Function Prototypes ******************************/
59#ifdef ENABLE_SAFETY
60extern u32 XStl_RegUpdate(u32 RegAddr, u32 RegVal);
61#endif
62
63/***************** Macros (Inline Functions) Definitions *********************/
64#if defined __GNUC__
65#if defined (__MICROBLAZE__)
66# define INST_SYNC mbar(0)
67# define DATA_SYNC mbar(1)
68# else
69# define SYNCHRONIZE_IO dmb()
70# define INST_SYNC isb()
71# define DATA_SYNC dsb()
72# endif
73#else
74# define SYNCHRONIZE_IO
75# define INST_SYNC
76# define DATA_SYNC
77# define INST_SYNC
78# define DATA_SYNC
79#endif
80
81#if defined (__GNUC__) || defined (__ICCARM__) || defined (__MICROBLAZE__)
82#define INLINE inline
83#else
84#define INLINE __inline
85#endif
86
87/*****************************************************************************/
100static INLINE u8 Xil_In8(UINTPTR Addr)
101{
102 return *(volatile u8 *) Addr;
103}
104
105/*****************************************************************************/
117static INLINE u16 Xil_In16(UINTPTR Addr)
118{
119 return *(volatile u16 *) Addr;
120}
121
122/*****************************************************************************/
134static INLINE u32 Xil_In32(UINTPTR Addr)
135{
136 return *(volatile u32 *) Addr;
137}
138
139/*****************************************************************************/
151static INLINE u64 Xil_In64(UINTPTR Addr)
152{
153 return *(volatile u64 *) Addr;
154}
155
156/*****************************************************************************/
169static INLINE void Xil_Out8(UINTPTR Addr, u8 Value)
170{
171 /* write 8 bit value to specified address */
172 volatile u8 *LocalAddr = (volatile u8 *)Addr;
173 *LocalAddr = Value;
174}
175
176/*****************************************************************************/
188static INLINE void Xil_Out16(UINTPTR Addr, u16 Value)
189{
190 /* write 16 bit value to specified address */
191 volatile u16 *LocalAddr = (volatile u16 *)Addr;
192 *LocalAddr = Value;
193}
194
195/*****************************************************************************/
208static INLINE void Xil_Out32(UINTPTR Addr, u32 Value)
209{
210 /* write 32 bit value to specified address */
211#ifndef ENABLE_SAFETY
212 volatile u32 *LocalAddr = (volatile u32 *)Addr;
213 *LocalAddr = Value;
214#else
215 XStl_RegUpdate(Addr, Value);
216#endif
217}
218
219/*****************************************************************************/
231static INLINE void Xil_Out64(UINTPTR Addr, u64 Value)
232{
233 /* write 64 bit value to specified address */
234 volatile u64 *LocalAddr = (volatile u64 *)Addr;
235 *LocalAddr = Value;
236}
237
238/*****************************************************************************/
253static INLINE int Xil_SecureOut32(UINTPTR Addr, u32 Value)
254{
255 int Status = XST_FAILURE;
256 u32 ReadReg;
257 u32 ReadRegTemp;
258
259 /* writing 32 bit value to specified address */
260 Xil_Out32(Addr, Value);
261
262 /* verify value written to specified address with multiple reads */
263 ReadReg = Xil_In32(Addr);
264 ReadRegTemp = Xil_In32(Addr);
265
266 if( (ReadReg == Value) && (ReadRegTemp == Value) ) {
267 Status = XST_SUCCESS;
268 }
269
270 return Status;
271}
272
273/*****************************************************************************/
283static INLINE __attribute__((always_inline)) u16 Xil_EndianSwap16(u16 Data)
284{
285 return (u16) (((Data & 0xFF00U) >> 8U) | ((Data & 0x00FFU) << 8U));
286}
287
288/*****************************************************************************/
298static INLINE __attribute__((always_inline)) u32 Xil_EndianSwap32(u32 Data)
299{
300 u16 LoWord;
301 u16 HiWord;
302
303 /* get each of the half words from the 32 bit word */
304
305 LoWord = (u16) (Data & 0x0000FFFFU);
306 HiWord = (u16) ((Data & 0xFFFF0000U) >> 16U);
307
308 /* byte swap each of the 16 bit half words */
309
310 LoWord = (u16)(((LoWord & 0xFF00U) >> 8U) | ((LoWord & 0x00FFU) << 8U));
311 HiWord = (u16)(((HiWord & 0xFF00U) >> 8U) | ((HiWord & 0x00FFU) << 8U));
312
313 /* swap the half words before returning the value */
314
315 return ((((u32)LoWord) << (u32)16U) | (u32)HiWord);
316}
317
318#if defined (__MICROBLAZE__)
319#ifdef __LITTLE_ENDIAN__
320# define Xil_In16LE Xil_In16
321# define Xil_In32LE Xil_In32
322# define Xil_Out16LE Xil_Out16
323# define Xil_Out32LE Xil_Out32
324# define Xil_Htons Xil_EndianSwap16
325# define Xil_Htonl Xil_EndianSwap32
326# define Xil_Ntohs Xil_EndianSwap16
327# define Xil_Ntohl Xil_EndianSwap32
328# else
329# define Xil_In16BE Xil_In16
330# define Xil_In32BE Xil_In32
331# define Xil_Out16BE Xil_Out16
332# define Xil_Out32BE Xil_Out32
333# define Xil_Htons(Data) (Data)
334# define Xil_Htonl(Data) (Data)
335# define Xil_Ntohs(Data) (Data)
336# define Xil_Ntohl(Data) (Data)
337#endif
338#else
339# define Xil_In16LE Xil_In16
340# define Xil_In32LE Xil_In32
341# define Xil_Out16LE Xil_Out16
342# define Xil_Out32LE Xil_Out32
343# define Xil_Htons Xil_EndianSwap16
344# define Xil_Htonl Xil_EndianSwap32
345# define Xil_Ntohs Xil_EndianSwap16
346# define Xil_Ntohl Xil_EndianSwap32
347#endif
348
349#if defined (__MICROBLAZE__)
350#ifdef __LITTLE_ENDIAN__
351static INLINE u16 Xil_In16BE(UINTPTR Addr)
352#else
353static INLINE u16 Xil_In16LE(UINTPTR Addr)
354#endif
355#else
356static INLINE u16 Xil_In16BE(UINTPTR Addr)
357#endif
358{
359 u16 value = Xil_In16(Addr);
360 return Xil_EndianSwap16(value);
361}
362
363#if defined (__MICROBLAZE__)
364#ifdef __LITTLE_ENDIAN__
365static INLINE u32 Xil_In32BE(UINTPTR Addr)
366#else
367static INLINE u32 Xil_In32LE(UINTPTR Addr)
368#endif
369#else
370static INLINE u32 Xil_In32BE(UINTPTR Addr)
371#endif
372{
373 u32 value = Xil_In32(Addr);
374 return Xil_EndianSwap32(value);
375}
376
377#if defined (__MICROBLAZE__)
378#ifdef __LITTLE_ENDIAN__
379static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
380#else
381static INLINE void Xil_Out16LE(UINTPTR Addr, u16 Value)
382#endif
383#else
384static INLINE void Xil_Out16BE(UINTPTR Addr, u16 Value)
385#endif
386{
387 Value = Xil_EndianSwap16(Value);
388 Xil_Out16(Addr, Value);
389}
390
391#if defined (__MICROBLAZE__)
392#ifdef __LITTLE_ENDIAN__
393static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
394#else
395static INLINE void Xil_Out32LE(UINTPTR Addr, u32 Value)
396#endif
397#else
398static INLINE void Xil_Out32BE(UINTPTR Addr, u32 Value)
399#endif
400{
401 Value = Xil_EndianSwap32(Value);
402 Xil_Out32(Addr, Value);
403}
404
405#ifdef __cplusplus
406}
407#endif
408
409#endif /* end of protection macro */
Definition: xnandpsu_onfi.h:181