Demo HCI Implementation for WiMOD-LR Devices  V1.3.1
WMDefs.h
1 //------------------------------------------------------------------------------
2 //
3 // File: WMDefs.h
4 //
5 // Abstract: Basic Type and Macro Definitions
6 //
7 // Version: 0.1
8 //
9 // Date: 14.05.2014
10 //
11 // Disclaimer: This example code is provided by IMST GmbH on an "AS IS" basis
12 // without any warranties.
13 //
14 //------------------------------------------------------------------------------
15 //@brief Basic Type and Macro Definitions
16 //------------------------------------------------------------------------------
18 
19 
20 
21 #ifndef WMDEFS_H
22 #define WMDEFS_H
23 
24 #include <stdint.h>
25 #include <stdbool.h>
26 
27 // enable the next line for C++11 support
28 //#define WIMOD_USE_CPP11
29 
30 
31 typedef uint8_t UINT8;
32 typedef uint16_t UINT16;
33 typedef uint32_t UINT32;
34 typedef uint64_t UINT64;
35 
36 typedef int8_t INT8;
37 typedef int16_t INT16;
38 typedef int32_t INT32;
39 
40 
41 #ifndef MAKEWORD
42  #define MAKEWORD(lo,hi) (UINT16)(((UINT16)((UINT8)(hi)) << 8) | ((UINT16)((UINT8)(lo))))
43 #endif
44 
45 #ifndef MAKELONG
46  #define MAKELONG(lo,hi) (UINT32)(((UINT32)((UINT16)(hi)) << 16) | ((UINT32)((UINT16)(lo))))
47 #endif
48 
49 #ifndef LOBYTE
50  #define LOBYTE(w) (UINT8)((UINT16)(w))
51 #endif
52 
53 #ifndef HIBYTE
54  #define HIBYTE(w) (UINT8)((UINT16)(w) >> 8)
55 #endif
56 
57 #ifndef LOWORD
58  #define LOWORD(w) (UINT16)((UINT32)(w))
59 #endif
60 
61 #ifndef HIWORD
62  #define HIWORD(w) (UINT16)((UINT32)(w) >> 16)
63 #endif
64 
65 
66 
67 
68 static inline UINT16
69 NTOH16(const UINT8* srcPtr)
70 {
71  UINT16 value;
72 
73  value = MAKEWORD(srcPtr[0], srcPtr[1]);
74 
75  return value;
76 }
77 
78 static inline void
79 HTON16(UINT8* dstPtr, UINT16 value)
80 {
81  dstPtr[0] = LOBYTE(value);
82  dstPtr[1] = HIBYTE(value);
83 }
84 
85 static inline UINT32
86 NTOH24(const UINT8* srcPtr)
87 {
88  UINT32 value;
89 
90  value = MAKELONG(MAKEWORD(srcPtr[0], srcPtr[1]),
91  MAKEWORD(srcPtr[2], 0x00));
92 
93  return value;
94 }
95 
96 static inline void
97 HTON24(UINT8* dstPtr, UINT32 value)
98 {
99  dstPtr[0] = LOBYTE(LOWORD(value));
100  dstPtr[1] = HIBYTE(LOWORD(value));
101  dstPtr[2] = LOBYTE(HIWORD(value));
102 }
103 
104 static inline UINT32
105 NTOH32(const UINT8* srcPtr)
106 {
107  UINT32 value;
108 
109  value = MAKELONG(MAKEWORD(srcPtr[0], srcPtr[1]),
110  MAKEWORD(srcPtr[2], srcPtr[3]));
111 
112  return value;
113 }
114 
115 static inline void
116 HTON32(UINT8* dstPtr, UINT32 value)
117 {
118  dstPtr[0] = LOBYTE(LOWORD(value));
119  dstPtr[1] = HIBYTE(LOWORD(value));
120  dstPtr[2] = LOBYTE(HIWORD(value));
121  dstPtr[3] = HIBYTE(HIWORD(value));
122 }
123 
124 
125 #ifndef MIN
126  #define MIN(a, b) ((a) < (b) ? (a) : (b))
127  #define MAX(a, b) ((a) < (b) ? (b) : (a))
128 #endif
129 
130 #endif // WMDEFS_H
131 
133 
134 //------------------------------------------------------------------------------
135 // end of file
136 //------------------------------------------------------------------------------