Zen API

- Home
- Topics
- Types
- Files

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