This is Unofficial EPICS BASE Doxygen Site
epicsMMIO.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2014 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * Copyright (c) 2014 UChicago Argonne LLC, as Operator of Argonne
5 * National Laboratory.
6 * Copyright (c) 2006 The Regents of the University of California,
7 * as Operator of Los Alamos National Laboratory.
8 * Copyright (c) 2006 The Board of Trustees of the Leland Stanford Junior
9 * University, as Operator of the Stanford Linear Accelerator Center.
10 * EPICS BASE is distributed subject to a Software License Agreement found
11 * in file LICENSE that is included with this distribution.
12 \*************************************************************************/
13 /*
14  * Original Author: Eric Bjorklund (was called mrfSyncIO.h)
15  * Author: Michael Davidsaver <mdavidsaver@bnl.gov>
16  */
17 
18 #ifndef EPICSMMIO_H
19 #define EPICSMMIO_H
20 
21 #if (CPU_FAMILY != PPC) && (CPU_FAMILY != I80X86)
22 # include "epicsMMIODef.h"
23 #else
24 
25 /**************************************************************************************************/
26 /* Required Header Files */
27 /**************************************************************************************************/
28 
29 /* This is needed on vxWorks 6.8 */
30 #ifndef _VSB_CONFIG_FILE
31 # define _VSB_CONFIG_FILE <../lib/h/config/vsbConfig.h>
32 #endif
33 
34 #include <vxWorks.h> /* vxWorks common definitions */
35 #include <sysLib.h> /* vxWorks System Library Definitions */
36 #include <version.h> /* vxWorks Version Definitions */
37 
38 #include <epicsTypes.h> /* EPICS Common Type Definitions */
39 #include <epicsEndian.h> /* EPICS Byte Order Definitions */
40 #include <compilerSpecific.h>
41 
42 /*=====================
43  * vxAtomicLib.h (which defines the memory barrier macros)
44  * is available on vxWorks 6.6 and above.
45  */
46 
47 #if _WRS_VXWORKS_MAJOR > 6
48 # include <vxAtomicLib.h>
49 #elif _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR >= 6
50 # include <vxAtomicLib.h>
51 #endif
52 
55 bswap16(epicsUInt16 value)
56 {
57  return (((epicsUInt16)(value) & 0x00ff) << 8) |
58  (((epicsUInt16)(value) & 0xff00) >> 8);
59 }
60 
63 bswap32(epicsUInt32 value)
64 {
65  return (((epicsUInt32)(value) & 0x000000ff) << 24) |
66  (((epicsUInt32)(value) & 0x0000ff00) << 8) |
67  (((epicsUInt32)(value) & 0x00ff0000) >> 8) |
68  (((epicsUInt32)(value) & 0xff000000) >> 24);
69 }
70 
71 #if EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
72 # define be16_to_cpu(X) (epicsUInt16)(X)
73 # define be32_to_cpu(X) (epicsUInt32)(X)
74 # define le16_to_cpu(X) bswap16(X)
75 # define le32_to_cpu(X) bswap32(X)
76 
77 #elif EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
78 # define be16_to_cpu(X) bswap16(X)
79 # define be32_to_cpu(X) bswap32(X)
80 # define le16_to_cpu(X) (epicsUInt16)(X)
81 # define le32_to_cpu(X) (epicsUInt32)(X)
82 
83 #else
84 # error Unable to determine native byte order
85 #endif
86 
87 #if CPU_FAMILY == PPC
88 
89 /* All PowerPC BSPs that I have studied implement these functions
90  * with the same definition, byte-swapping the data and adding a
91  * sync and/or eieio instruction as necessary on that CPU board.
92  * They do *not* all implement the sys{In/Out}{Byte/Word/Long}
93  * functions to do the same thing though, so we can't use them.
94  */
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 UINT8 sysPciInByte(UINT8 *addr);
99 void sysPciOutByte(UINT8 *addr, UINT8 data);
100 UINT16 sysPciInWord(UINT16 *addr);
101 void sysPciOutWord(UINT16 *addr, UINT16 data);
102 UINT32 sysPciInLong (UINT32 *addr);
103 void sysPciOutLong (UINT32 *addr, UINT32 data);
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #define ioread8(address) sysPciInByte((UINT8 *)(address))
109 #define iowrite8(address,data) sysPciOutByte((UINT8 *)(address), (epicsUInt8)(data))
110 
111 #define nat_ioread16(address) bswap16(sysPciInWord((UINT16 *)(address)))
112 #define nat_ioread32(address) bswap32(sysPciInLong((UINT32 *)(address)))
113 
114 #define nat_iowrite16(address,data) sysPciOutWord((UINT16 *)(address), bswap16(data))
115 #define nat_iowrite32(address,data) sysPciOutLong((UINT32 *)(address), bswap32(data))
116 
117 #define be_ioread16(address) bswap16(sysPciInWord((UINT16 *)(address)))
118 #define be_ioread32(address) bswap32(sysPciInLong((UINT32 *)(address)))
119 
120 #define be_iowrite16(address,data) sysPciOutWord((UINT16 *)(address), bswap16(data))
121 #define be_iowrite32(address,data) sysPciOutLong((UINT32 *)(address), bswap32(data))
122 
123 #define le_ioread16(address) sysPciInWord((UINT16 *)(address))
124 #define le_ioread32(address) sysPciInLong((UINT32 *)(address))
125 
126 #define le_iowrite16(address,data) sysPciOutWord((UINT16 *)(address), (data))
127 #define le_iowrite32(address,data) sysPciOutLong((UINT32 *)(address), (data))
128 
129 #else /* CPU_FAMILY == I80X86 */
130 
131 /* All Intel BSPs should implement the sys{In/Out}{Byte/Word/Long}
132  * functions, which are declared in the sysLib.h header.
133  */
134 
135 #define ioread8(address) sysInByte ((epicsUInt32)(address))
136 #define iowrite8(address,data) sysOutByte ((epicsUInt32)(address), (epicsUInt8)(data))
137 
138 #define nat_ioread16(address) sysInWord ((epicsUInt32)(address))
139 #define nat_ioread32(address) sysInLong ((epicsUInt32)(address))
140 
141 #define nat_iowrite16(address,data) sysOutWord((epicsUInt32)(address),(data))
142 #define nat_iowrite32(address,data) sysOutLong((epicsUInt32)(address),(data))
143 
144 #define be_ioread16(address) be16_to_cpu (sysInWord ((epicsUInt32)(address)))
145 #define be_ioread32(address) be32_to_cpu (sysInLong ((epicsUInt32)(address)))
146 
147 #define be_iowrite16(address,data) sysOutWord ((epicsUInt32)(address), be16_to_cpu((epicsUInt16)(data)))
148 #define be_iowrite32(address,data) sysOutLong ((epicsUInt32)(address), be32_to_cpu((epicsUInt32)(data)))
149 
150 #define le_ioread16(address) le16_to_cpu (sysInWord ((epicsUInt32)(address)))
151 #define le_ioread32(address) le32_to_cpu (sysInLong ((epicsUInt32)(address)))
152 
153 #define le_iowrite16(address,data) sysOutWord ((epicsUInt32)(address), le16_to_cpu((epicsUInt16)(data)))
154 #define le_iowrite32(address,data) sysOutLong ((epicsUInt32)(address), le32_to_cpu((epicsUInt32)(data)))
155 
156 #endif /* I80X86 */
157 
158 
159 #ifndef VX_MEM_BARRIER_R
160 # define VX_MEM_BARRIER_R() do{}while(0)
161 #endif
162 #ifndef VX_MEM_BARRIER_W
163 # define VX_MEM_BARRIER_W() do{}while(0)
164 #endif
165 #ifndef VX_MEM_BARRIER_RW
166 # define VX_MEM_BARRIER_RW() do{}while(0)
167 #endif
168 
169 #define rbarr() VX_MEM_BARRIER_R()
170 #define wbarr() VX_MEM_BARRIER_W()
171 #define rwbarr() VX_MEM_BARRIER_RW()
172 
173 #endif /* CPU_FAMILY */
174 #endif /* EPICSMMIO_H */
Definition: link.h:174
#define EPICS_ALWAYS_INLINE
void sysPciOutWord(UINT16 *addr, UINT16 data)
unsigned short epicsUInt16
Definition: epicsTypes.h:41
unsigned int epicsUInt32
Definition: epicsTypes.h:43
void sysPciOutByte(UINT8 *addr, UINT8 data)
UINT16 sysPciInWord(UINT16 *addr)
void sysPciOutLong(UINT32 *addr, UINT32 data)
Memory Mapped I/O.
UINT32 sysPciInLong(UINT32 *addr)
UINT8 sysPciInByte(UINT8 *addr)