| Demo HCI Implementation for WiMOD-LR Devices V2.0.3

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 //
22
23
24
25 #ifndef WMDEFS_H
26 #define WMDEFS_H
27
28 #include <stdint.h>
29 #include <stdbool.h>
30
31 // enable the next line for C++11 support
32 //#define WIMOD_USE_CPP11
33
34 /*
35 * The user has to use the .Process() function at regular base in oder to
36 * process the incomming messages on the serial interface bewtween the host
37 * (Arduino) and the WiMOD radio module.
38 * If the frequency of the calling of the Process() function is too low there
39 * is a certain risk of missing / mixing messages.
40 * Using a 2nd RxBuffer will reduce this risk alot, but costs more RAM memory
41 */
42 #define WIMOD_USE_2ND_RXBUFFER
43
44
45 typedef uint8_t UINT8;
46 typedef uint16_t UINT16;
47 typedef uint32_t UINT32;
48 typedef uint64_t UINT64;
49
50 typedef int8_t INT8;
51 typedef int16_t INT16;
52 typedef int32_t INT32;
53
54
55 #ifndef MAKEWORD
56 #define MAKEWORD(lo,hi) (UINT16)(((UINT16)((UINT8)(hi)) << 8) | ((UINT16)((UINT8)(lo))))
57 #endif
58
59 #ifndef MAKELONG
60 #define MAKELONG(lo,hi) (UINT32)(((UINT32)((UINT16)(hi)) << 16) | ((UINT32)((UINT16)(lo))))
61 #endif
62
63 #ifndef LOBYTE
64 #define LOBYTE(w) (UINT8)((UINT16)(w))
65 #endif
66
67 #ifndef HIBYTE
68 #define HIBYTE(w) (UINT8)((UINT16)(w) >> 8)
69 #endif
70
71 #ifndef LOWORD
72 #define LOWORD(w) (UINT16)((UINT32)(w))
73 #endif
74
75 #ifndef HIWORD
76 #define HIWORD(w) (UINT16)((UINT32)(w) >> 16)
77 #endif
78
79
80
81
82 static inline UINT16
83 NTOH16(const UINT8* srcPtr)
84 {
85 UINT16 value;
86
87 value = MAKEWORD(srcPtr[0], srcPtr[1]);
88
89 return value;
90 }
91
92 static inline void
93 HTON16(UINT8* dstPtr, UINT16 value)
94 {
95 dstPtr[0] = LOBYTE(value);
96 dstPtr[1] = HIBYTE(value);
97 }
98
99 static inline UINT32
100 NTOH24(const UINT8* srcPtr)
101 {
102 UINT32 value;
103
104 value = MAKELONG(MAKEWORD(srcPtr[0], srcPtr[1]),
105 MAKEWORD(srcPtr[2], 0x00));
106
107 return value;
108 }
109
110 static inline UINT32
111 HTOH24_DUMMY(const UINT8* srcPtr)
112 {
113 UINT32 value;
114
115 value = (((uint32_t) srcPtr[0]) << 16);
116 value |= (((uint32_t) srcPtr[1]) << 8);
117 value |= (((uint32_t) srcPtr[2]) << 0);
118
119 return value;
120 }
121
122
123 static inline void
124 HTON24(UINT8* dstPtr, UINT32 value)
125 {
126 dstPtr[0] = LOBYTE(LOWORD(value));
127 dstPtr[1] = HIBYTE(LOWORD(value));
128 dstPtr[2] = LOBYTE(HIWORD(value));
129 }
130
131 static inline UINT32
132 NTOH32(const UINT8* srcPtr)
133 {
134 UINT32 value;
135
136 value = MAKELONG(MAKEWORD(srcPtr[0], srcPtr[1]),
137 MAKEWORD(srcPtr[2], srcPtr[3]));
138
139 return value;
140 }
141
142 static inline void
143 HTON32(UINT8* dstPtr, UINT32 value)
144 {
145 dstPtr[0] = LOBYTE(LOWORD(value));
146 dstPtr[1] = HIBYTE(LOWORD(value));
147 dstPtr[2] = LOBYTE(HIWORD(value));
148 dstPtr[3] = HIBYTE(HIWORD(value));
149 }
150
151
152 #ifndef MIN
153 #define MIN(a, b) ((a) < (b) ? (a) : (b))
154 #define MAX(a, b) ((a) < (b) ? (b) : (a))
155 #endif
156
157 #endif // WMDEFS_H
158
160
161 //------------------------------------------------------------------------------
162 // end of file
163 //------------------------------------------------------------------------------