Zen API

- Home
- Help Topics
- Types by Category
- All Types
- Files

All Classes Files Functions Variables Typedefs Macros Groups Pages
kApiCfg.h
Go to the documentation of this file.
1 /**
2 * @file kApiCfg.h
3 * @brief Architecture/compiler-specific definitions.
4 *
5 * @internal
6 * Copyright (C) 2005-2014 by LMI Technologies Inc.
7 * Licensed under the MIT License.
8 * Redistributed files must retain the above copyright notice.
9 */
10 #ifndef K_API_API_CFG_H
11 #define K_API_API_CFG_H
12
13 #if defined(_MSC_VER)
14 # define K_MSVC
15 #elif defined(__TI_COMPILER_VERSION__)
16 # define K_TI_CCS
17 #else
18 # define K_GCC
19 #endif
20
21 #if defined(_WIN32) || defined(_WIN64)
22 # define K_WINDOWS
23 #elif defined(K_TI_CCS)
24 # define K_DSP_BIOS
25 #else
26 # define K_POSIX
27 # if defined(__linux__)
28 # define K_LINUX
29 # endif
30 # if defined(__APPLE__)
31 # define K_DARWIN
32 # endif
33 # if defined(__QNXNTO__)
34 # define K_QNX
35 # endif
36 #endif
37
38 #if defined(K_DM647) && !defined(CHIP_DM648)
39 # define CHIP_DM648
40 #endif
41
42 #if defined(K_DEBUG)
43 # define K_DEBUG_ENABLED (1)
44 #else
45 # define K_DEBUG_ENABLED (0)
46 #endif
47
48 #if defined(K_PROFILE)
49 # define K_PROFILE_ENABLED (1)
50 #else
51 # define K_PROFILE_ENABLED (0)
52 #endif
53
54 #if defined(K_MSVC) && defined(K_DEBUG)
55 # define _CRTDBG_MAP_ALLOC
56 # include <stdlib.h>
57 # include <crtdbg.h>
58 #endif
59
60 #include <stdarg.h>
61 #include <stddef.h>
62 #include <stdlib.h>
63 #include <string.h>
64 #include <assert.h>
65
66 #if !defined(K_MSVC)
67 # include <stdint.h>
68 #endif
69
70 #if defined(_WIN64) || defined(WIN64)
71 # define K_POINTER_SIZE (8)
72 #elif defined(_WIN32) || defined(WIN32)
73 # define K_POINTER_SIZE (4)
74 #elif defined(_TMS320C6X)
75 # define K_POINTER_SIZE (4)
76 #elif (UINTPTR_MAX == UINT32_MAX)
77 # define K_POINTER_SIZE (4)
78 #elif (UINTPTR_MAX == UINT64_MAX)
79 # define K_POINTER_SIZE (8)
80 #else
81 # error "Unsupported pointer size."
82 #endif
83
84 #if defined(K_GCC) && defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
85 # define K_BIG_ENDIAN
86 # define K_IS_LITTLE_ENDIAN (kFALSE)
87 #elif defined(K_TI_CCS) && defined(_LITTLE_ENDIAN)
88 # define K_LITTLE_ENDIAN
89 # define K_IS_LITTLE_ENDIAN (kTRUE)
90 #elif !defined(K_LITTLE_ENDIAN) && !defined(K_BIG_ENDIAN)
91 # define K_LITTLE_ENDIAN
92 # define K_IS_LITTLE_ENDIAN (kTRUE)
93 #endif
94
95 #if defined(K_MSVC)
96
97 # define kxCall __stdcall
98 # define kxDlCall __cdecl
99
100 # define kExportFx(TYPE) __declspec(dllexport) TYPE kCall
101 # define kImportFx(TYPE) __declspec(dllimport) TYPE kCall
102
103 # define kExportCx(TYPE) __declspec(dllexport) TYPE kxDlCall
104 # define kImportCx(TYPE) __declspec(dllimport) TYPE kxDlCall
105
106 # define kInFx(TYPE) TYPE kCall
107 # define kInCx(TYPE) TYPE kCall
108
109 # define kExportDx(TYPE) __declspec(dllexport) TYPE
110 # define kImportDx(TYPE) __declspec(dllimport) TYPE
111
112 # define kInDx(TYPE) TYPE
113
114 typedef unsigned __int8 kx8u;
115 typedef unsigned __int16 kx16u;
116 typedef unsigned __int32 kx32u;
117 typedef unsigned __int64 kx64u;
118 typedef __int8 kx8s;
119 typedef __int16 kx16s;
120 typedef __int32 kx32s;
121 typedef __int64 kx64s;
122 typedef float kx32f;
123 typedef double kx64f;
124 typedef char kxChar;
125 typedef unsigned char kxByte;
126
127 # define kx64U(CONSTANT) (CONSTANT##ui64)
128 # define kx64S(CONSTANT) (CONSTANT##i64)
129
130 #elif defined(K_TI_CCS)
131
132 # define kxCall
133 # define kxDlCall
134
135 # define kExportFx(TYPE) TYPE kCall
136 # define kImportFx(TYPE) TYPE kCall
137
138 # define kExportCx(TYPE) TYPE kDlCall
139 # define kImportCx(TYPE) TYPE kDlCall
140
141 # define kInFx(TYPE) TYPE kCall
142 # define kInCx(TYPE) TYPE kCall
143
144 # define kExportDx(TYPE) TYPE
145 # define kImportDx(TYPE) TYPE
146
147 # define kInDx(TYPE) TYPE
148
149 typedef unsigned char kx8u;
150 typedef unsigned short kx16u;
151 typedef unsigned int kx32u;
152 typedef unsigned long long kx64u;
153 typedef signed char kx8s;
154 typedef signed short kx16s;
155 typedef signed int kx32s;
156 typedef signed long long kx64s;
157 typedef float kx32f;
158 typedef double kx64f;
159 typedef char kxChar;
160 typedef unsigned char kxByte;
161
162 # define kx64U(CONSTANT) (CONSTANT##LLU)
163 # define kx64S(CONSTANT) (CONSTANT##LL)
164
165 #else
166
167 # define kxCall
168 # define kxDlCall
169
170 # define kExportFx(TYPE) TYPE kCall
171 # define kImportFx(TYPE) TYPE kCall
172
173 # define kExportCx(TYPE) TYPE kDlCall
174 # define kImportCx(TYPE) TYPE kDlCall
175
176 # define kInFx(TYPE) TYPE kCall
177 # define kInCx(TYPE) TYPE kCall
178
179 # define kExportDx(TYPE) TYPE
180 # define kImportDx(TYPE) TYPE
181
182 # define kInDx(TYPE) TYPE
183
184 typedef unsigned char kx8u;
185 typedef unsigned short kx16u;
186 typedef unsigned int kx32u;
187 typedef unsigned long long kx64u;
188 typedef signed char kx8s;
189 typedef signed short kx16s;
190 typedef signed int kx32s;
191 typedef signed long long kx64s;
192 typedef float kx32f;
193 typedef double kx64f;
194 typedef char kxChar;
195 typedef unsigned char kxByte;
196
197 # define kx64U(CONSTANT) (CONSTANT##LLU)
198 # define kx64S(CONSTANT) (CONSTANT##LL)
199
200 #endif
201
202 #if (K_POINTER_SIZE == 4)
203
204 typedef kx32u kxSize;
205 # define kxSIZE_MAX k32U_MAX
206
207 typedef kx32s kxSSize;
208 # define kxSSIZE_MIN k32S_MIN
209 # define kxSSIZE_MAX k32S_MAX
210
211 #elif (K_POINTER_SIZE == 8)
212
213 typedef kx64u kxSize;
214 # define kxSIZE_MAX k64U_MAX
215
216 typedef kx64s kxSSize;
217 # define kxSSIZE_MIN k64S_MIN
218 # define kxSSIZE_MAX k64S_MAX
219
220 #endif
221
222 #define kALIGN_ANY (3)
223 #define kALIGN_ANY_SIZE (1 << kALIGN_ANY)
224
225 #define kVarArgList va_list
226
227 #if defined(K_MSVC) || defined(K_TI_CCS)
228 # define kVarArgList_Start_(ARG_PTR, PREV_PARAM) va_start(ARG_PTR, PREV_PARAM)
229 # define kVarArgList_End_(ARG_PTR) va_end(ARG_PTR)
230 # define kVarArgList_Copy_(ARG_PTR, SOURCE) ((ARG_PTR) = (SOURCE))
231 # define kVarArgList_Next_(ARG_PTR, TYPE) va_arg(ARG_PTR, TYPE)
232 #else
233 # define kVarArgList_Start_(ARG_PTR, PREV_PARAM) va_start(ARG_PTR, PREV_PARAM)
234 # define kVarArgList_End_(ARG_PTR) va_end(ARG_PTR)
235 # define kVarArgList_Copy_(ARG_PTR, SOURCE) va_copy(ARG_PTR, SOURCE)
236 # define kVarArgList_Next_(ARG_PTR, TYPE) va_arg(ARG_PTR, TYPE)
237 #endif
238
239 #if defined (__cplusplus)
240 # define kBeginHeader() extern "C" {
241 # define kEndHeader() }
242 #else
243 # define kBeginHeader()
244 # define kEndHeader()
245 #endif
246
247 /*
248 * Some source files require platform library headers to be included. And, at least
249 * for Windows, there can sometimes exist complicated rules about the particular order
250 * in which headers have to be included. The K_PLATFORM symbol helps to deal with
251 * these issues.
252 *
253 * Any kApi source file that requires platform headers should have #define K_PLATFORM as the
254 * first line in the source file. This ensures that the most common platform headers are
255 * included here, in the correct order.
256 */
257 #if defined(K_PLATFORM)
258 # if defined(K_WINDOWS)
259 # include <winsock2.h>
260 # include <ws2tcpip.h>
261 # include <windows.h>
262 # include <process.h>
263 # endif
264 # if defined(K_DSP_BIOS)
265 # include <std.h>
266 # include <gbl.h>
267 # include <clk.h>
268 # include <tsk.h>
269 # include <lck.h>
270 # include <sem.h>
271 # include <prd.h>
272 # include <netmain.h>
273 # include <nettools/nettools.h>
274 # include <nettools/inc/inet.h>
275 # endif
276 # if defined(K_POSIX)
277 # include <errno.h>
278 # include <unistd.h>
279 # include <pthread.h>
280 # include <semaphore.h>
281 # include <sys/types.h>
282 # include <sys/stat.h>
283 # include <sys/fcntl.h>
284 # include <sys/socket.h>
285 # include <sys/select.h>
286 # include <sys/ioctl.h>
287 # include <sys/time.h>
288 # include <sys/timeb.h>
289 # include <netinet/in.h>
290 # include <netinet/tcp.h>
291 # include <dlfcn.h>
292 # include <dirent.h>
293 # include <net/if.h>
294 # include <netdb.h>
295 # endif
296 # if defined(K_DARWIN)
297 # include <mach-o/dyld.h>
298 # endif
299 #endif
300
301 #if defined(K_PLATFORM)
302 # if defined(K_WINDOWS)
303 # define K_OS_INFINITE INFINITE
304 typedef DWORD kThreadId;
305 # elif defined(K_DSP_BIOS)
306 # define K_OS_INFINITE SYS_FOREVER
307 typedef TSK_Handle kThreadId;
308 # elif defined(K_POSIX)
309 # define K_OS_INFINITE kINFINITE //no special "infinite" value
310 typedef pthread_t kThreadId;
311 # endif
312 #endif
313
314 #if defined(K_COMPAT_5)
315
316 // simple renaming (handled by porting script)
317 # define KAPI_ALIGN_SHIFT kALIGN_ANY
318 # define KAPI_ALIGN kALIGN_ANY_SIZE
319
320 /*
321 * These flags probably shouldn't exist; but since they're going to be
322 * required for some time (FS 5 compatibility), we may as well use an
323 * up-to-date style.
324 */
325 # if defined(K_DSP)
326 # define KAPI_DSP
327 # elif defined(K_HOST)
328 # define KAPI_HOST
329 # elif defined(K_VIRTUAL)
330 # define KAPI_VIRTUAL
331 # endif
332
333 # if defined(K_WINDOWS)
334 # define KAPI_MS_WINDOWS
335 # elif defined(K_DSP_BIOS)
336 # define KAPI_TI_DSP_BIOS
337 # endif
338
339 #endif
340
341 #endif