mrfioc2  2.3.0
mrfIoOpsDef.h
Go to the documentation of this file.
1 
2 #ifndef MRFIOOPSDEF_H
3 #define MRFIOOPSDEF_H
4 
5 #include <epicsTypes.h>
6 #include <epicsEndian.h>
7 #include <shareLib.h>
8 
9 #ifdef __cplusplus
10 # ifndef INLINE
11 # define INLINE inline
12 # endif
13 #endif
14 
15 /* So that code will compile on host systems, define some (in)sane defaults
16  */
17 
18 INLINE
19 epicsUInt8
20 ioread8(volatile void* addr)
21 {
22  return *(volatile epicsUInt8*)(addr);
23 }
24 
25 INLINE
26 void
27 iowrite8(volatile void* addr, epicsUInt8 val)
28 {
29  *(volatile epicsUInt8*)(addr) = val;
30 }
31 
32 INLINE
33 epicsUInt16
34 nat_ioread16(volatile void* addr)
35 {
36  return *(volatile epicsUInt16*)(addr);
37 }
38 
39 INLINE
40 void
41 nat_iowrite16(volatile void* addr, epicsUInt16 val)
42 {
43  *(volatile epicsUInt16*)(addr) = val;
44 }
45 
46 INLINE
47 epicsUInt32
48 nat_ioread32(volatile void* addr)
49 {
50  return *(volatile epicsUInt32*)(addr);
51 }
52 
53 INLINE
54 void
55 nat_iowrite32(volatile void* addr, epicsUInt32 val)
56 {
57  *(volatile epicsUInt32*)(addr) = val;
58 }
59 
60 #if EPICS_BYTE_ORDER == EPICS_ENDIAN_BIG
61 
62 #define bswap16(value) ((epicsUInt16) ( \
63  (((epicsUInt16)(value) & 0x00ff) << 8) | \
64  (((epicsUInt16)(value) & 0xff00) >> 8)))
65 
66 #define bswap32(value) ( \
67  (((epicsUInt32)(value) & 0x000000ff) << 24) | \
68  (((epicsUInt32)(value) & 0x0000ff00) << 8) | \
69  (((epicsUInt32)(value) & 0x00ff0000) >> 8) | \
70  (((epicsUInt32)(value) & 0xff000000) >> 24))
71 
72 # define be_ioread16(A) nat_ioread16(A)
73 # define be_ioread32(A) nat_ioread32(A)
74 # define be_iowrite16(A,D) nat_iowrite16(A,D)
75 # define be_iowrite32(A,D) nat_iowrite32(A,D)
76 
77 # define le_ioread16(A) bswap16(nat_ioread16(A))
78 # define le_ioread32(A) bswap32(nat_ioread32(A))
79 # define le_iowrite16(A,D) nat_iowrite16(A,bswap16(D))
80 # define le_iowrite32(A,D) nat_iowrite32(A,bswap32(D))
81 
82 #elif EPICS_BYTE_ORDER == EPICS_ENDIAN_LITTLE
83 
84 #ifdef _WIN32
85  #include <Winsock2.h>
86 #else
87  // for htons() et al.
88  #include <netinet/in.h> // on rtems
89  #include <arpa/inet.h> // on linux
90 #endif
91 
92 /* hton* is optimized or a builtin for most compilers
93  * so use it if possible
94  */
95 #define bswap16(v) htons(v)
96 #define bswap32(v) htonl(v)
97 
98 # define be_ioread16(A) bswap16(nat_ioread16(A))
99 # define be_ioread32(A) bswap32(nat_ioread32(A))
100 # define be_iowrite16(A,D) nat_iowrite16(A,bswap16(D))
101 # define be_iowrite32(A,D) nat_iowrite32(A,bswap32(D))
102 
103 # define le_ioread16(A) nat_ioread16(A)
104 # define le_ioread32(A) nat_ioread32(A)
105 # define le_iowrite16(A,D) nat_iowrite16(A,D)
106 # define le_iowrite32(A,D) nat_iowrite32(A,D)
107 
108 #else
109 # error Unable to determine native byte order
110 #endif
111 
112 #define rbarr() do{}while(0)
113 #define wbarr() do{}while(0)
114 #define rwbarr() do{}while(0)
115 
116 
117 #endif /* MRFIOOPSDEF_H */
INLINE void nat_iowrite32(volatile void *addr, epicsUInt32 val)
Definition: mrfIoOpsDef.h:55
INLINE void iowrite8(volatile void *addr, epicsUInt8 val)
Definition: mrfIoOpsDef.h:27
INLINE epicsUInt8 ioread8(volatile void *addr)
Definition: mrfIoOpsDef.h:20
INLINE epicsUInt32 nat_ioread32(volatile void *addr)
Definition: mrfIoOpsDef.h:48
INLINE epicsUInt16 nat_ioread16(volatile void *addr)
Definition: mrfIoOpsDef.h:34
Definition: devObj.h:97
INLINE void nat_iowrite16(volatile void *addr, epicsUInt16 val)
Definition: mrfIoOpsDef.h:41