devLib2  2.12
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 * devLib2 is distributed subject to a Software License Agreement found
5 * in file LICENSE that is included with this distribution.
6 \*************************************************************************/
7 /*
8  * Author: Michael Davidsaver <mdavidsaver@gmail.com>
9  */
10 
11 #ifndef EPICSMMIODEF_H
12 #define EPICSMMIODEF_H
13 
14 #include <epicsTypes.h>
15 #include <epicsEndian.h>
16 #include <shareLib.h>
17 
18 #ifdef __cplusplus
19 # ifndef INLINE
20 # define INLINE inline
21 # endif
22 #endif
23 
30 INLINE
31 epicsUInt8
32 ioread8(volatile void* addr)
33 {
34  return *(volatile epicsUInt8*)(addr);
35 }
36 
39 INLINE
40 void
41 iowrite8(volatile void* addr, epicsUInt8 val)
42 {
43  *(volatile epicsUInt8*)(addr) = val;
44 }
45 
49 INLINE
50 epicsUInt16
51 nat_ioread16(volatile void* addr)
52 {
53  return *(volatile epicsUInt16*)(addr);
54 }
55 
59 INLINE
60 void
61 nat_iowrite16(volatile void* addr, epicsUInt16 val)
62 {
63  *(volatile epicsUInt16*)(addr) = val;
64 }
65 
69 INLINE
70 epicsUInt32
71 nat_ioread32(volatile void* addr)
72 {
73  return *(volatile epicsUInt32*)(addr);
74 }
75 
79 INLINE
80 void
81 nat_iowrite32(volatile void* addr, epicsUInt32 val)
82 {
83  *(volatile epicsUInt32*)(addr) = val;
84 }
85 
86 #if EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
87 
92 INLINE
93 epicsUInt16
94 bswap16(epicsUInt16 value)
95 {
96  return (((epicsUInt16)(value) & 0x00ff) << 8) |
97  (((epicsUInt16)(value) & 0xff00) >> 8);
98 }
99 
100 INLINE
101 epicsUInt32
102 bswap32(epicsUInt32 value)
103 {
104  return (((epicsUInt32)(value) & 0x000000ff) << 24) |
105  (((epicsUInt32)(value) & 0x0000ff00) << 8) |
106  (((epicsUInt32)(value) & 0x00ff0000) >> 8) |
107  (((epicsUInt32)(value) & 0xff000000) >> 24);
108 }
109 
110 # define be_ioread16(A) nat_ioread16(A)
111 # define be_ioread32(A) nat_ioread32(A)
112 # define be_iowrite16(A,D) nat_iowrite16(A,D)
113 # define be_iowrite32(A,D) nat_iowrite32(A,D)
114 
115 # define le_ioread16(A) bswap16(nat_ioread16(A))
116 # define le_ioread32(A) bswap32(nat_ioread32(A))
117 # define le_iowrite16(A,D) nat_iowrite16(A,bswap16(D))
118 # define le_iowrite32(A,D) nat_iowrite32(A,bswap32(D))
119 
122 #elif EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
123 
124 #include <arpa/inet.h>
125 #ifdef __rtems__
126  /* some rtems bsps (pc386) don't provide htonl correctly */
127 # include <rtems/endian.h>
128 #endif
129 
134 /* hton* is optimized or a builtin for most compilers
135  * so use it if possible
136  */
137 #define bswap16(v) htons(v)
138 #define bswap32(v) htonl(v)
139 
140 # define be_ioread16(A) bswap16(nat_ioread16(A))
141 # define be_ioread32(A) bswap32(nat_ioread32(A))
142 # define be_iowrite16(A,D) nat_iowrite16(A,bswap16(D))
143 # define be_iowrite32(A,D) nat_iowrite32(A,bswap32(D))
144 
145 # define le_ioread16(A) nat_ioread16(A)
146 # define le_ioread32(A) nat_ioread32(A)
147 # define le_iowrite16(A,D) nat_iowrite16(A,D)
148 # define le_iowrite32(A,D) nat_iowrite32(A,D)
149 
152 #else
153 # error Unable to determine native byte order
154 #endif
155 
194 #define rbarr() do{}while(0)
195 
198 #define wbarr() do{}while(0)
199 
202 #define rwbarr() do{}while(0)
203 
276 #endif /* EPICSMMIODEF_H */
INLINE void nat_iowrite16(volatile void *addr, epicsUInt16 val)
Write two byte in host order. Not byte swapping.
Definition: epicsMMIODef.h:61
INLINE epicsUInt32 bswap32(epicsUInt32 value)
Definition: epicsMMIODef.h:102
INLINE epicsUInt32 nat_ioread32(volatile void *addr)
Read four bytes in host order. Not byte swapping.
Definition: epicsMMIODef.h:71
INLINE epicsUInt16 bswap16(epicsUInt16 value)
Definition: epicsMMIODef.h:94
INLINE epicsUInt16 nat_ioread16(volatile void *addr)
Read two bytes in host order. Not byte swapping.
Definition: epicsMMIODef.h:51
INLINE void iowrite8(volatile void *addr, epicsUInt8 val)
Write a single byte.
Definition: epicsMMIODef.h:41
INLINE epicsUInt8 ioread8(volatile void *addr)
Read a single byte.
Definition: epicsMMIODef.h:32
INLINE void nat_iowrite32(volatile void *addr, epicsUInt32 val)
Write four byte in host order. Not byte swapping.
Definition: epicsMMIODef.h:81