EPICS Base  7.0.6.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
epicsMMIODef.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2010 Brookhaven Science Associates, as Operator of
3 * Brookhaven National Laboratory.
4 * SPDX-License-Identifier: EPICS
5 * EPICS BASE is distributed subject to a Software License Agreement found
6 * in file LICENSE that is included with this distribution.
7 \*************************************************************************/
18 #ifndef EPICSMMIODEF_H
19 #define EPICSMMIODEF_H
20 
21 #include <epicsTypes.h>
22 #include <epicsEndian.h>
23 #include <compilerSpecific.h>
24 #include <libComAPI.h>
25 
26 #ifdef __cplusplus
27 # ifndef INLINE
28 # define INLINE inline
29 # endif
30 #endif
31 
38 static EPICS_ALWAYS_INLINE
39 epicsUInt8
40 ioread8(volatile void* addr)
41 {
42  return *(volatile epicsUInt8*)(addr);
43 }
44 
47 static EPICS_ALWAYS_INLINE
48 void
49 iowrite8(volatile void* addr, epicsUInt8 val)
50 {
51  *(volatile epicsUInt8*)(addr) = val;
52 }
53 
57 static EPICS_ALWAYS_INLINE
58 epicsUInt16
59 nat_ioread16(volatile void* addr)
60 {
61  return *(volatile epicsUInt16*)(addr);
62 }
63 
67 static EPICS_ALWAYS_INLINE
68 void
69 nat_iowrite16(volatile void* addr, epicsUInt16 val)
70 {
71  *(volatile epicsUInt16*)(addr) = val;
72 }
73 
77 static EPICS_ALWAYS_INLINE
78 epicsUInt32
79 nat_ioread32(volatile void* addr)
80 {
81  return *(volatile epicsUInt32*)(addr);
82 }
83 
87 static EPICS_ALWAYS_INLINE
88 void
89 nat_iowrite32(volatile void* addr, epicsUInt32 val)
90 {
91  *(volatile epicsUInt32*)(addr) = val;
92 }
93 
94 #if EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
95 
100 static EPICS_ALWAYS_INLINE
101 epicsUInt16
102 bswap16(epicsUInt16 value)
103 {
104  return (((epicsUInt16)(value) & 0x00ff) << 8) |
105  (((epicsUInt16)(value) & 0xff00) >> 8);
106 }
107 
108 static EPICS_ALWAYS_INLINE
109 epicsUInt32
110 bswap32(epicsUInt32 value)
111 {
112  return (((epicsUInt32)(value) & 0x000000ff) << 24) |
113  (((epicsUInt32)(value) & 0x0000ff00) << 8) |
114  (((epicsUInt32)(value) & 0x00ff0000) >> 8) |
115  (((epicsUInt32)(value) & 0xff000000) >> 24);
116 }
117 
118 # define be_ioread16(A) nat_ioread16(A)
119 # define be_ioread32(A) nat_ioread32(A)
120 # define be_iowrite16(A,D) nat_iowrite16(A,D)
121 # define be_iowrite32(A,D) nat_iowrite32(A,D)
122 
123 # define le_ioread16(A) bswap16(nat_ioread16(A))
124 # define le_ioread32(A) bswap32(nat_ioread32(A))
125 # define le_iowrite16(A,D) nat_iowrite16(A,bswap16(D))
126 # define le_iowrite32(A,D) nat_iowrite32(A,bswap32(D))
127 
130 #elif EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
131 
132 /* Get hton[sl] declarations: */
133 #include <osiSock.h>
134 
139 /* hton* is optimized or a builtin for most compilers
140  * so use it if possible
141  */
142 #define bswap16(v) htons(v)
143 #define bswap32(v) htonl(v)
144 
145 # define be_ioread16(A) bswap16(nat_ioread16(A))
146 # define be_ioread32(A) bswap32(nat_ioread32(A))
147 # define be_iowrite16(A,D) nat_iowrite16(A,bswap16(D))
148 # define be_iowrite32(A,D) nat_iowrite32(A,bswap32(D))
149 
150 # define le_ioread16(A) nat_ioread16(A)
151 # define le_ioread32(A) nat_ioread32(A)
152 # define le_iowrite16(A,D) nat_iowrite16(A,D)
153 # define le_iowrite32(A,D) nat_iowrite32(A,D)
154 
157 #else
158 # error Unable to determine native byte order
159 #endif
160 
199 #define rbarr() do{}while(0)
200 
203 #define wbarr() do{}while(0)
204 
207 #define rwbarr() do{}while(0)
208 
283 #endif /* EPICSMMIODEF_H */
Definition: link.h:175
The core data types used by epics.