c66ccc0b41fa461c60c22151238ee1e621bfcd71
1 /*-----------------------------------------------------------------------------
2 * EcOs.h
3 * Copyright acontis technologies GmbH, Weingarten, Germany
4 * Response Stefan Zintgraf
5 * Description EC-Master OS-Layer header
6 *---------------------------------------------------------------------------*/
8 #ifndef INC_ECOS
9 #define INC_ECOS
11 /*-INCLUDES------------------------------------------------------------------*/
12 #ifndef INC_ECTYPE
13 #include "EcType.h"
14 #endif
15 #if (defined INSTRUMENT_OS)
16 #include "EcOsInstr.h"
17 #endif
18 #include <EcOsPlatform.h>
19 /* No OS specific includes files allowed */
20 #if (defined __cplusplus) && !(defined EC_NEW)
21 #include <new>
22 #endif
23 #include <limits.h>
25 /*-DEFINES-------------------------------------------------------------------*/
27 /* *** EC_INT32_MAX, EC_INT64_MAX *** */
28 #if (!defined EC_INT32_MAX) && (defined LONG_MAX)
29 #define EC_INT32_MAX LONG_MAX
30 #endif
31 #if (!defined EC_INT64_MAX) && (defined LLONG_MAX)
32 #define EC_INT64_MAX LLONG_MAX
33 #endif
34 #if (!defined EC_INT64_MAX) && (defined LONG_LONG_MAX)
35 #define EC_INT64_MAX LONG_LONG_MAX
36 #endif
37 #if (!defined EC_INT32_MAX) && (defined _I32_MAX)
38 #define EC_INT32_MAX _I32_MAX
39 #endif
40 #if (!defined EC_INT64_MAX) && (defined _I64_MAX)
41 #define EC_INT64_MAX _I64_MAX
42 #endif
44 /* *** Socket support *** */
45 #if (defined EC_SOCKET_IP_SUPPORTED) || (defined EC_SOCKET_MSGQUEUE_WIN32_SUPPORTED) || (defined EC_SOCKET_MSGQUEUE_RTOSSHM_SUPPORTED) || (defined EC_SOCKET_RTOSLIB_SUPPORTED)
46 #define EC_SOCKET_SUPPORTED
47 #endif
49 #if (defined EC_SOCKET_SUPPORTED)
51 /* Socket layer internal error code selection */
52 #ifndef EC_SOCKET_NOERROR
53 #define EC_SOCKET_NOERROR 0
54 #endif
56 #if !(defined EC_E_BSD_ENOTCONN) && (defined ENOTCONN)
57 #define EC_E_BSD_ENOTCONN ENOTCONN
58 #endif
59 #if !(defined EC_E_BSD_ENOTSOCK) && (defined ENOTSOCK)
60 #define EC_E_BSD_ENOTSOCK ENOTSOCK
61 #endif
62 #if !(defined EC_E_BSD_ESHUTDOWN) && (defined ESHUTDOWN)
63 #define EC_E_BSD_ESHUTDOWN ESHUTDOWN
64 #endif
65 #if !(defined EC_E_BSD_EHOSTUNREACH) && (defined EHOSTUNREACH)
66 #define EC_E_BSD_EHOSTUNREACH EHOSTUNREACH
67 #endif
68 #if !(defined EC_E_BSD_EINVAL) && (defined EINVAL)
69 #define EC_E_BSD_EINVAL EINVAL
70 #endif
71 #if !(defined EC_E_BSD_EMSGSIZE) && (defined EMSGSIZE)
72 #define EC_E_BSD_EMSGSIZE EMSGSIZE
73 #endif
74 #if !(defined EC_E_BSD_ECONNABORTED) && (defined ECONNABORTED)
75 #define EC_E_BSD_ECONNABORTED ECONNABORTED
76 #endif
77 #if !(defined EC_E_BSD_ETIMEDOUT) && (defined ETIMEDOUT)
78 #define EC_E_BSD_ETIMEDOUT ETIMEDOUT
79 #endif
80 #if !(defined EC_E_BSD_ECONNRESET) && (defined ECONNRESET)
81 #define EC_E_BSD_ECONNRESET ECONNRESET
82 #endif
83 #if !(defined EC_E_BSD_EPIPE) && (defined EPIPE)
84 #define EC_E_BSD_EPIPE EPIPE
85 #endif
87 #ifndef EC_INVALID_SOCKET
88 #define EC_INVALID_SOCKET INVALID_SOCKET
89 #endif
91 #ifndef EC_SOCKET_ERROR
92 #define EC_SOCKET_ERROR SOCKET_ERROR
93 #endif
95 #ifndef EC_T_SOCKET
96 #define EC_T_SOCKET EC_T_INT
97 #endif
99 #ifndef EC_SOMAXCONN
100 #define EC_SOMAXCONN SOMAXCONN
101 #endif
103 #ifndef OsInetAddr
104 #define OsInetAddr inet_addr
105 #endif
106 #endif /* EC_SOCKET_SUPPORTED */
108 /*-FORWARD DECLARATIONS------------------------------------------------------*/
109 struct _EC_T_LINK_DRV_DESC;
111 /*-TYPEDEFS------------------------------------------------------------------*/
112 typedef EC_T_VOID (*EC_PF_OSTIMER)(EC_T_VOID);
113 typedef EC_T_BOOL (*EC_PF_OSDBGMSGHK)(const EC_T_CHAR* szFormat, EC_T_VALIST vaArgs);
114 typedef EC_T_VOID (*EC_PF_THREADENTRY)(EC_T_VOID* pvParams);
115 typedef ATECAT_API EC_T_DWORD (*EC_PF_LLREGISTER)(struct _EC_T_LINK_DRV_DESC* pLinkDrvDesc, EC_T_DWORD dwLinkDrvDescSize);
117 /* SMP support */
118 #ifndef EC_CPUSET_DEFINED
119 typedef unsigned long EC_T_CPUSET; /* CPU-set for SMP systems */
120 #endif
122 typedef EC_T_DWORD (*EC_PF_SYSTIME)(EC_T_UINT64* pqwSystemTime);
124 #if (defined EC_SOCKET_SUPPORTED)
126 #ifndef EC_T_FD_SET
127 typedef struct fd_set EC_T_FD_SET;
128 #endif
130 #ifndef EC_T_TIMEVAL
131 typedef struct timeval EC_T_TIMEVAL;
132 #endif
134 #ifndef EC_T_SOCKADDR
135 typedef struct sockaddr EC_T_SOCKADDR;
136 #endif
138 #ifndef EC_T_SOCKADDR_IN
139 typedef struct sockaddr_in EC_T_SOCKADDR_IN;
140 #endif
142 #endif /* EC_SOCKET_SUPPORTED */
144 /* -PACKED STRUCTURES------------------------------------------------------- */
145 #include EC_PACKED_INCLUDESTART(8)
147 typedef struct _EC_T_OS_PARMS
148 {
149 EC_T_DWORD dwValPattern; /*< in Validation pattern */
150 EC_T_DWORD dwSize;
151 EC_PF_SYSTIME pfSystemTimeGet;
152 EC_T_DWORD dwSupportedFeatures;
153 EC_T_DWORD dwReserved;
154 } EC_PACKED(8) EC_T_OS_PARMS; /* was: EC_T_OS_INIT_DESC */
156 #include EC_PACKED_INCLUDESTOP
158 /*-MACROS--------------------------------------------------------------------*/
159 #ifndef ATECAT_PLATFORMSTR
160 #define ATECAT_PLATFORMSTR ""
161 #endif
163 /* *** EC_INLINE *** */
164 #ifndef EC_INLINEKEYWORD
165 #define EC_INLINEKEYWORD __inline
166 #endif
167 #ifndef EC_INLINEATTRIBUTE
168 #define EC_INLINEATTRIBUTE
169 #endif
171 #ifndef EC_INLINESTART
172 #define EC_INLINESTART __inline
173 #endif
174 #ifndef EC_INLINESTOP
175 #define EC_INLINESTOP
176 #endif
178 #if (defined INSTRUMENT_OS) || (defined INSTRUMENT_MASTER) || (defined INSTRUMENT_LL)
179 #define EC_INSTRUMENT_MOCKABLE_FUNC virtual
180 #define EC_INSTRUMENT_MOCKABLE_VAR public:
181 #else
182 #define EC_INSTRUMENT_MOCKABLE_FUNC
183 #define EC_INSTRUMENT_MOCKABLE_VAR
184 #endif
186 #define EC_OFFSETOF(s,m) ((size_t)&(((s *)0)->m))
188 #define EC_INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )
189 #ifndef EC_VASTART
190 #define EC_VASTART(ap,v) ( ap = (EC_T_VALIST)&v + EC_INTSIZEOF(v) )
191 #endif
192 #ifndef EC_VAARG
193 #define EC_VAARG(ap,t) ( *(t *)((ap += EC_INTSIZEOF(t)) - EC_INTSIZEOF(t)) )
194 #endif
195 #ifndef EC_VAEND
196 #define EC_VAEND(ap) ( ap = (EC_T_VALIST)0 )
197 #endif
199 #define EC_UNREFPARM(p) {(p)=(p);}
200 #define EC_MAX(a,b) (((a) > (b)) ? (a) : (b))
201 #define EC_MIN(a,b) (((a) < (b)) ? (a) : (b))
202 #define EC_ENDOF(p) ((p)+1)
204 #define SafeOsFree(p) {if (EC_NULL!=(p)) {OsFree (p); (p) = EC_NULL;}}
205 #ifndef SafeDelete
206 #define SafeDelete(p) {if (EC_NULL!=(p)) {delete (p); (p) = EC_NULL;}}
207 #endif
208 #ifndef SafeDeleteArray
209 #define SafeDeleteArray(p) {if (EC_NULL!=(p)) {delete [] (p); (p) = EC_NULL;}}
210 #endif
212 /* SMP support */
213 #ifndef EC_CPUSET_DEFINED
214 /* This macros will be overloaded by the specific EcOsPlatform.h */
215 #define EC_CPUSET_ZERO(CpuSet) (CpuSet) = 0 /* clear all CPU indexes in the CPU set */
216 #define EC_CPUSET_SET(CpuSet,nCpuIndex) (CpuSet) = (1<<(nCpuIndex)) /* set CPU index nCpuIndex (0..x) in the CPU set */
217 #define EC_CPUSET_SETALL(CpuSet) (CpuSet) = 0xFFFFFFFF /* set all CPU indexes in the CPU set */
218 #endif
220 #define EC_BIT_MASK(Bitsize) ((1<<(Bitsize))-1)
221 #define EC_BITFIELD_MASK(Bitpos,Bitsize) ((EC_BIT_MASK((Bitsize)))<<(Bitpos))
222 #define EC_RESET_WORD_IN_BITFIELD(wVal,Bitpos,Bitsize) ((wVal)&(~EC_BITFIELD_MASK((Bitpos),(Bitsize))))
223 #define EC_SET_WORD_IN_BITFIELD(Bitpos,Bitsize,wVal) (((wVal)&(EC_BIT_MASK((Bitsize))))<<(Bitpos))
224 #define EC_GET_WORD_IN_BITFIELD(Bitpos,Bitsize,wVal) (((wVal)>>(Bitpos))&EC_BIT_MASK((Bitsize)))
226 #define EC_BYTE0(x) (EC_T_BYTE)(((x) >> 0) & 0xff)
227 #define EC_BYTE1(x) (EC_T_BYTE)(((x) >> 8) & 0xff)
228 #define EC_BYTE2(x) (EC_T_BYTE)(((x) >> 16) & 0xff)
229 #define EC_BYTE3(x) (EC_T_BYTE)(((x) >> 24) & 0xff)
230 #define EC_BYTE4(x) (EC_T_BYTE)(((x) >> 32) & 0xff)
231 #define EC_BYTE5(x) (EC_T_BYTE)(((x) >> 40) & 0xff)
232 #define EC_BYTE6(x) (EC_T_BYTE)(((x) >> 48) & 0xff)
233 #define EC_BYTE7(x) (EC_T_BYTE)(((x) >> 56) & 0xff)
235 #define EC_BYTEN(ptr, n) \
236 ((EC_T_BYTE*)(ptr))[(n)]
238 #define EC_WORD0(x) (((x) >> 0) & 0xffff)
239 #define EC_WORD1(x) (((x) >> 16) & 0xffff)
241 #if (!defined EC_WORDSWAP)
242 #define EC_WORDSWAP(x) (EC_T_WORD)( \
243 (( (EC_T_WORD)EC_BYTE0((x))) << 8) | \
244 (( (EC_T_WORD)EC_BYTE1((x))) << 0))
245 #endif
247 #if (!defined EC_DWORDSWAP)
248 #define EC_DWORDSWAP(x) (EC_T_DWORD)( \
249 (( (EC_T_DWORD)EC_BYTE0((x))) << 24) | \
250 (( (EC_T_DWORD)EC_BYTE1((x))) << 16) | \
251 (( (EC_T_DWORD)EC_BYTE2((x))) << 8) | \
252 (( (EC_T_DWORD)EC_BYTE3((x))) << 0))
253 #endif
255 #if (!defined EC_QWORDSWAP)
256 #define EC_QWORDSWAP(x) (EC_T_UINT64)( \
257 (((EC_T_UINT64)EC_BYTE0((x))) << 56) | \
258 (((EC_T_UINT64)EC_BYTE1((x))) << 48) | \
259 (((EC_T_UINT64)EC_BYTE2((x))) << 40) | \
260 (((EC_T_UINT64)EC_BYTE3((x))) << 32) | \
261 (((EC_T_UINT64)EC_BYTE4((x))) << 24) | \
262 (((EC_T_UINT64)EC_BYTE5((x))) << 16) | \
263 (((EC_T_UINT64)EC_BYTE6((x))) << 8) | \
264 (((EC_T_UINT64)EC_BYTE7((x))) << 0))
265 #endif
267 #if !(defined EC_REALSWAP)
268 static EC_INLINESTART EC_T_REAL EC_REALSWAP_INLINE(EC_T_REAL fSrc)
269 {
270 EC_T_VOID* pvSrc = (EC_T_VOID*)&fSrc;
271 EC_T_UINT64 qwHelper = EC_QWORDSWAP(*((EC_T_UINT64*)pvSrc));
272 EC_T_VOID* pvDest = (EC_T_VOID*)&qwHelper;
273 return *((EC_T_REAL*)pvDest);
274 } EC_INLINESTOP
275 #define EC_REALSWAP(fSrc) EC_REALSWAP_INLINE(fSrc)
276 #endif /* EC_REALSWAP */
278 /* memory access */
279 #if (defined WITHALIGNMENT)
280 #if !(defined EC_SETWORD)
281 #define EC_SETWORD(ptr, val) \
282 { \
283 EC_BYTEN((ptr), 0) = EC_BYTE0(((EC_T_WORD)val)); \
284 EC_BYTEN((ptr), 1) = EC_BYTE1(((EC_T_WORD)val)); \
285 }
286 #endif
288 #if !(defined EC_SETDWORD)
289 /* little endian! LSB on [0], MSB on [3] */
290 #define EC_SETDWORD(ptr, val) \
291 { \
292 EC_BYTEN((ptr), 0) = EC_BYTE0(((EC_T_DWORD)val)); \
293 EC_BYTEN((ptr), 1) = EC_BYTE1(((EC_T_DWORD)val)); \
294 EC_BYTEN((ptr), 2) = EC_BYTE2(((EC_T_DWORD)val)); \
295 EC_BYTEN((ptr), 3) = EC_BYTE3(((EC_T_DWORD)val)); \
296 }
297 #endif
299 #if !(defined EC_SETQWORD)
300 #define EC_SETQWORD(ptr, val) \
301 { \
302 EC_BYTEN((ptr), 0) = EC_BYTE0(((EC_T_UINT64)val)); \
303 EC_BYTEN((ptr), 1) = EC_BYTE1(((EC_T_UINT64)val)); \
304 EC_BYTEN((ptr), 2) = EC_BYTE2(((EC_T_UINT64)val)); \
305 EC_BYTEN((ptr), 3) = EC_BYTE3(((EC_T_UINT64)val)); \
306 EC_BYTEN((ptr), 4) = EC_BYTE4(((EC_T_UINT64)val)); \
307 EC_BYTEN((ptr), 5) = EC_BYTE5(((EC_T_UINT64)val)); \
308 EC_BYTEN((ptr), 6) = EC_BYTE6(((EC_T_UINT64)val)); \
309 EC_BYTEN((ptr), 7) = EC_BYTE7(((EC_T_UINT64)val)); \
310 }
311 #endif
313 #if !(defined EC_GETWORD)
314 #define EC_GETWORD(ptr) (EC_T_WORD) \
315 ((EC_BYTEN((ptr), 0) << 0) | \
316 (EC_BYTEN((ptr), 1) << 8) \
317 )
318 #endif
320 #if !(defined EC_GETDWORD)
321 #define EC_GETDWORD(ptr) (EC_T_DWORD) \
322 ((EC_BYTEN((ptr), 0) << 0) | \
323 (EC_BYTEN((ptr), 1) << 8) | \
324 (EC_BYTEN((ptr), 2) << 16) | \
325 (EC_BYTEN((ptr), 3) << 24) \
326 )
327 #endif
329 #if !(defined EC_GETQWORD)
330 #define EC_GETQWORD(ptr) (EC_T_UINT64) \
331 ((((EC_T_UINT64)(EC_BYTEN((ptr), 0))) << 0) | \
332 (((EC_T_UINT64)(EC_BYTEN((ptr), 1))) << 8) | \
333 (((EC_T_UINT64)(EC_BYTEN((ptr), 2))) << 16) | \
334 (((EC_T_UINT64)(EC_BYTEN((ptr), 3))) << 24) | \
335 (((EC_T_UINT64)(EC_BYTEN((ptr), 4))) << 32) | \
336 (((EC_T_UINT64)(EC_BYTEN((ptr), 5))) << 40) | \
337 (((EC_T_UINT64)(EC_BYTEN((ptr), 6))) << 48) | \
338 (((EC_T_UINT64)(EC_BYTEN((ptr), 7))) << 56) \
339 )
340 #endif
342 #else
343 #if !(defined EC_SETWORD)
344 static EC_INLINESTART EC_T_VOID EC_SETWORD(EC_T_VOID* pvAddress, EC_T_WORD wVal)
345 {
346 /* alignment does not need to be consired on x86 */
347 *(EC_T_WORD*)pvAddress = wVal;
348 } EC_INLINESTOP
349 #endif
350 #if !(defined EC_SETDWORD)
351 static EC_INLINESTART EC_T_VOID EC_SETDWORD(EC_T_VOID* pvAddress, EC_T_DWORD dwVal)
352 {
353 /* alignment does not need to be consired on x86 */
354 *(EC_T_DWORD*)pvAddress = dwVal;
355 } EC_INLINESTOP
356 #endif
357 #if !(defined EC_SETQWORD)
358 static EC_INLINESTART EC_T_VOID EC_SETQWORD(EC_T_VOID* pvAddress, EC_T_UINT64 qwVal)
359 {
360 /* alignment does not need to be consired on x86 */
361 *(EC_T_UINT64*)pvAddress = qwVal;
362 } EC_INLINESTOP
363 #endif
364 #if !(defined EC_GETWORD)
365 static EC_INLINESTART EC_T_WORD EC_GETWORD(EC_T_VOID* pvAddress)
366 {
367 /* alignment does not need to be consired on x86 */
368 return *(EC_T_WORD*)pvAddress;
369 } EC_INLINESTOP
370 #endif
371 #if !(defined EC_GETDWORD)
372 static EC_INLINESTART EC_T_DWORD EC_GETDWORD(EC_T_VOID* pvAddress)
373 {
374 /* alignment does not need to be consired on x86 */
375 return *(EC_T_DWORD*)pvAddress;
376 } EC_INLINESTOP
377 #endif
378 #if !(defined EC_GETQWORD)
379 static EC_INLINESTART EC_T_UINT64 EC_GETQWORD(EC_T_VOID* pvAddress)
380 {
381 /* alignment does not need to be consired on x86 */
382 return *(EC_T_UINT64*)pvAddress;
383 } EC_INLINESTOP
384 #endif
385 #endif
387 #if !(defined EC_SETBOOL)
388 #define EC_SETBOOL(ptr, val) EC_SETDWORD(ptr, (EC_T_DWORD)val)
389 #endif
390 #if !(defined EC_GETBOOL)
391 #define EC_GETBOOL(ptr) ((EC_T_BOOL)(EC_GETDWORD(ptr))!=EC_FALSE)
392 #endif
394 static EC_INLINESTART EC_T_VOID EC_COPYBITS_INLINE(EC_T_BYTE* pbyDst, EC_T_INT nDstBitOffs, EC_T_BYTE* pbySrc, EC_T_INT nSrcBitOffs, EC_T_INT nBitSize)
395 {
396 EC_T_INT nRemLen = nBitSize; /* remaining length */
397 EC_T_BYTE byMask;
398 EC_T_INT nNumBits = 0;
399 EC_T_BYTE* pSrcHelp = EC_NULL;
400 EC_T_WORD wSrcWork;
402 if (nBitSize == 0)
403 {
404 return;
405 }
406 /* how many bits we need for the next "destination" byte */
407 nNumBits = EC_MIN((8 - (nDstBitOffs & 7)), nRemLen);
409 byMask = (EC_T_BYTE)((1 << nNumBits) - 1);
410 byMask = (EC_T_BYTE)(byMask<<(nDstBitOffs & 7));
412 /* copy first byte */
413 pSrcHelp = &pbySrc[nSrcBitOffs / 8];
414 if (nSrcBitOffs + nBitSize <= 8)
415 {
416 wSrcWork = (EC_T_WORD)pSrcHelp[0];
417 }
418 else
419 {
420 wSrcWork = (EC_T_WORD)((EC_T_WORD)pSrcHelp[0] | (((EC_T_WORD)pSrcHelp[1]) << 8)); /* xxxx xxxx xx-- ---- e. g. nSrcBitOffs=6, nDstBitOffs=2 */
421 }
422 wSrcWork = (EC_T_WORD)(wSrcWork >> (nSrcBitOffs & 7)); /* 0000 00xx xxxx xxxx */
423 wSrcWork = (EC_T_WORD)(wSrcWork & ((1 << nNumBits) - 1));
425 pbyDst = &pbyDst[nDstBitOffs/8];
426 *pbyDst = (EC_T_BYTE)((*pbyDst & ~byMask) | (wSrcWork<<(nDstBitOffs & 7)));
427 pbyDst++;
429 nSrcBitOffs = (EC_T_WORD)(nSrcBitOffs + nNumBits);
430 nRemLen -= nNumBits;
432 while (nRemLen > 0)
433 {
434 nNumBits = EC_MIN(8, nRemLen);
436 byMask = (EC_T_BYTE)((1 << nNumBits) - 1);
438 pSrcHelp = &pbySrc[nSrcBitOffs / 8];
439 wSrcWork = (EC_T_WORD)(pSrcHelp[0] | (pSrcHelp[1] << 8));
440 wSrcWork = (EC_T_WORD)(wSrcWork >> (nSrcBitOffs & 7));
441 wSrcWork &= (EC_T_WORD)byMask;
443 *pbyDst = (EC_T_BYTE)((*pbyDst & ~byMask) | (wSrcWork));
444 pbyDst++;
446 nSrcBitOffs = (EC_T_WORD)(nSrcBitOffs + nNumBits);
447 nRemLen -= nNumBits;
448 }
449 } EC_INLINESTOP
450 #if !(defined EC_COPYBITS)
451 #define EC_COPYBITS(pbyDst, nDstBitOffs, pbySrc, nSrcBitOffs, nBitSize) \
452 EC_COPYBITS_INLINE(pbyDst, nDstBitOffs, pbySrc, nSrcBitOffs, nBitSize)
453 #endif /* EC_COPYBITS */
455 #ifndef OsCopyBitsPdIn
456 #define OsCopyBitsPdIn EC_COPYBITS
457 #endif
459 #ifndef OsCopyBitsPdOut
460 #define OsCopyBitsPdOut EC_COPYBITS
461 #endif
463 #if !(defined EC_SETBITS)
464 #define EC_SETBITS(pbyBuf, pbyData, nDstBitOffs, nBitSize) \
465 EC_COPYBITS(pbyBuf, nDstBitOffs, pbyData, 0, nBitSize)
466 #endif
468 #if !(defined EC_GETBITS)
469 #define EC_GETBITS(pbyBuf, pbyData, nDstBitOffs, nBitSize) \
470 EC_COPYBITS(pbyData, 0, pbyBuf, nDstBitOffs, nBitSize)
471 #endif
473 #if !(defined EC_MAKEWORD)
474 #define EC_MAKEWORD(hi, lo) ((EC_T_WORD )(((EC_T_BYTE)(lo)) | ((EC_T_WORD )((EC_T_BYTE)(hi))) << 8))
475 #endif
476 #if !(defined EC_MAKEDWORD)
477 #define EC_MAKEDWORD(hi, lo) ((EC_T_DWORD)(((EC_T_WORD)(lo)) | ((EC_T_DWORD)((EC_T_WORD)(hi))) << 16))
478 #endif
479 #if !(defined EC_MAKEQWORD)
480 #define EC_MAKEQWORD(hi, lo) ((EC_T_UINT64)(((EC_T_DWORD)(lo)) | ((EC_T_UINT64)((EC_T_DWORD)(hi))) << 32))
481 #endif
483 #if !(defined EC_LODWORD)
484 #define EC_LODWORD(qw) ((EC_T_DWORD)((EC_T_UINT64)(qw) & 0xFFFFFFFF))
485 #endif
486 #if !(defined EC_HIDWORD)
487 #define EC_HIDWORD(qw) ((EC_T_DWORD)(((EC_T_UINT64)(qw) >> 32) & 0xFFFFFFFF))
488 #endif
490 #if !(defined EC_LOWORD)
491 #define EC_LOWORD(dw) ((EC_T_WORD)((dw) & 0xFFFF))
492 #endif
493 #if !(defined EC_HIWORD)
494 #define EC_HIWORD(dw) ((EC_T_WORD)(((EC_T_DWORD)(dw) >> 16) & 0xFFFF))
495 #endif
497 #if !(defined EC_LOBYTE)
498 #define EC_LOBYTE(w) ((EC_T_BYTE)((w) & 0xFF))
499 #endif
500 #if !(defined EC_HIBYTE)
501 #define EC_HIBYTE(w) ((EC_T_BYTE)(((EC_T_WORD)(w) >> 8) & 0xFF))
502 #endif
504 static EC_INLINESTART EC_T_BYTE EcBoolToByte(EC_T_BOOL bValue) { return (EC_T_BYTE)(bValue ? 1 : 0);} EC_INLINESTOP
505 static EC_INLINESTART EC_T_BOOL EcByteToBool(EC_T_BYTE bValue) { return bValue == 1;} EC_INLINESTOP
506 static EC_INLINESTART EC_T_DWORD EcPtrToDword(EC_T_VOID* pvVal) {return (EC_T_DWORD)((EC_T_BYTE*)pvVal-(EC_T_BYTE*)EC_NULL);} EC_INLINESTOP
508 #ifdef EC_BIG_ENDIAN
510 #define EC_NO_BITFIELDS /* big endian: do not use bitfields! */
512 #define EC_GET_FRM_BOOL(ptr) EC_DWORDSWAP(EC_GETDWORD((ptr)))
513 #define EC_GET_FRM_WORD(ptr) EC_WORDSWAP( EC_GETWORD((ptr)))
514 #define EC_GET_FRM_DWORD(ptr) EC_DWORDSWAP(EC_GETDWORD((ptr)))
515 #define EC_GET_FRM_QWORD(ptr) EC_QWORDSWAP(EC_GETQWORD((ptr)))
517 #define EC_SET_FRM_BOOL(ptr, dw) EC_SETDWORD((ptr), EC_DWORDSWAP((dw)))
518 #define EC_SET_FRM_WORD(ptr, w) EC_SETWORD((ptr), EC_WORDSWAP((w)))
519 #define EC_SET_FRM_DWORD(ptr, dw) EC_SETDWORD((ptr), EC_DWORDSWAP((dw)))
520 #define EC_SET_FRM_QWORD(ptr, qw) EC_SETQWORD((ptr), EC_QWORDSWAP((qw)))
522 #define EC_GET_FRM_WORD_BITFIELD(Bitpos,Bitsize,wVal) EC_GET_WORD_IN_BITFIELD((Bitpos),(Bitsize),EC_WORDSWAP((wVal)))
523 #define EC_SET_FRM_WORD_BITFIELD(wVal,wNewVal,Bitpos,Bitsize) {(wVal) = ((wVal) & ~EC_WORDSWAP(EC_BITFIELD_MASK((Bitpos),(Bitsize)))) | (EC_WORDSWAP((wNewVal)<<(Bitpos)));}
525 #define EC_NTOHS(w) EC_WORDSWAP((w))
526 #define EC_NTOHL(dw) EC_DWORDSWAP((dw))
527 #define EC_NTOHLL(qw) EC_QWORDSWAP((qw))
529 #define EC_HTONS(w) EC_WORDSWAP((w))
530 #define EC_HTONL(dw) EC_DWORDSWAP((dw))
531 #define EC_HTONLL(qw) EC_QWORDSWAP((qw))
533 #else /* EC_BIG_ENDIAN */
535 #define EC_GET_FRM_BOOL(ptr) EC_GETBOOL((ptr))
536 #define EC_GET_FRM_WORD(ptr) EC_GETWORD((ptr))
537 #define EC_GET_FRM_DWORD(ptr) EC_GETDWORD((ptr))
538 #define EC_GET_FRM_QWORD(ptr) EC_GETQWORD((ptr))
540 #define EC_SET_FRM_BOOL(ptr,b) EC_SETBOOL((ptr),(b))
541 #define EC_SET_FRM_WORD(ptr,w) EC_SETWORD((ptr),(w))
542 #define EC_SET_FRM_DWORD(ptr,dw) EC_SETDWORD((ptr),(dw))
543 #define EC_SET_FRM_QWORD(ptr,qw) EC_SETQWORD((ptr),(qw))
545 #define EC_GET_FRM_WORD_BITFIELD(Bitpos,Bitsize,wVal) EC_GET_WORD_IN_BITFIELD((Bitpos),(Bitsize),(wVal))
546 #define EC_SET_FRM_WORD_BITFIELD(wVal,wNewVal,Bitpos,Bitsize) {(wVal) = (EC_T_WORD)(((wVal) & ~EC_BITFIELD_MASK((Bitpos),(Bitsize))) | ((wNewVal)<<(Bitpos)));}
548 #define EC_NTOHS(w) ((EC_T_WORD)(w))
549 #define EC_NTOHL(dw) ((EC_T_DWORD)(dw))
550 #define EC_NTOHLL(qw) ((EC_T_UINT64)(qw))
552 #define EC_HTONS(w) ((EC_T_WORD)(w))
553 #define EC_HTONL(dw) ((EC_T_DWORD)(dw))
554 #define EC_HTONLL(qw) ((EC_T_UINT64)(qw))
556 #endif /* EC_BIG_ENDIAN */
559 /*-MACROS--------------------------------------------------------------------*/
562 /*-FUNCTION DECLARATION------------------------------------------------------*/
564 #ifdef __cplusplus
565 extern "C"
566 {
567 #endif
569 ATECAT_API EC_T_DWORD OsInit(EC_T_OS_PARMS* pOsParms);
570 ATECAT_API EC_T_DWORD OsDeinit(EC_T_VOID);
571 ATECAT_API EC_T_VOID OsAddDbgMsgHook(EC_PF_OSDBGMSGHK pfOsDbgMsgHook);
573 #ifndef OsMalloc
574 #define OsMalloc(nSize) malloc((size_t)(nSize))
575 #endif
577 #ifndef OsFree
578 #define OsFree(pvMem) free((void*)(pvMem))
579 #endif
581 #ifndef OsRealloc
582 #define OsRealloc(pMem,nSize) realloc((void*)(pMem),(size_t)(nSize))
583 #endif
585 #ifndef OsMemset
586 #define OsMemset(pDest,nVal,nSize) memset((void*)(pDest),(int)(nVal),(size_t)(nSize))
587 #endif
589 #ifndef OsMemcpy
590 #define OsMemcpy(pDest,pSrc,nSize) memcpy((void*)(pDest),(const void*)(pSrc),(size_t)(nSize))
591 #endif
593 #ifndef OsMemcpyPdIn
594 #define OsMemcpyPdIn OsMemcpy
595 #endif
597 #ifndef OsMemcpyPdOut
598 #define OsMemcpyPdOut OsMemcpy
599 #endif
601 #ifndef OsMemcmp
602 #define OsMemcmp(pBuf1,pBuf2,nSize) memcmp((void*)(pBuf1),(const void*)(pBuf2),(size_t)(nSize))
603 #endif
605 #ifndef OsMemmove
606 #define OsMemmove(pDest,pSrc,nSize) memmove((void*)(pDest),(const void*)(pSrc),(size_t)(nSize))
607 #endif
609 #ifndef OsStrlen
610 #define OsStrlen(szString) strlen((const char*)(szString))
611 #endif
613 #ifndef OsStrcpy
614 #define OsStrcpy(szDest,szSrc) strcpy((char*)(szDest),(const char*)(szSrc))
615 #endif
617 #ifndef OsStrncpy
618 #define OsStrncpy(szDest,szSrc,nSize) strncpy((char*)(szDest),(const char*)(szSrc),(size_t)(nSize))
619 #endif
621 #ifndef OsStrcmp
622 #define OsStrcmp(szStr1,szStr2) strcmp((const char*)(szStr1),(const char*)(szStr2))
623 #endif
625 #ifndef OsStrncmp
626 #define OsStrncmp(szStr1,szStr2, nSize) strncmp((const char*)(szStr1),(const char*)(szStr2), (size_t)(nSize))
627 #endif
629 #ifndef OsStricmp
630 #define OsStricmp(szStr1,szStr2) stricmp((const char*)(szStr1),(const char*)(szStr2))
631 #endif
633 #ifndef OsStrtok
634 #define OsStrtok(szToken,szDelimit) strtok((char*)(szToken), (const char*)(szDelimit))
635 #endif
637 #ifndef OsStrtol
638 #define OsStrtol(szToken,ppEnd,nRadix) strtol((const char*)(szToken), (ppEnd), (nRadix))
639 #endif
641 #ifndef OsAtoi
642 #define OsAtoi(szString) atoi((const char*)(szString))
643 #endif
645 #ifndef OsStrtoul
646 #define OsStrtoul(szString,ptr,base) strtoul((const char*)(szString), (ptr), (base))
647 #endif
649 #ifndef OsPrintf
650 #define OsPrintf printf
651 #endif
653 #ifndef OsVprintf
654 #define OsVprintf vprintf
655 #endif
657 #ifndef OsVsnprintf
658 #define OsVsnprintf EcVsnprintf
659 #endif
661 #ifndef OsSnprintf
662 /** \def OsSnprintf(EC_T_CHAR* szDest, EC_T_DWORD dwSize, const EC_T_CHAR* szFormat, ...)
663 \brief An macro for platform-abstracted snprintf().
664 \param szDest buffer to write to
665 \param dwSize max bytes to print
666 \param szFormat format text to print
667 \param ... variable args to be formatted printed.
668 \return Length of string (without terminating zero character).
669 Securely prints given parameters formatted to buffer.
670 */
671 #define OsSnprintf EcSnprintf
672 #endif
674 #ifndef OsFopen
675 #define OsFopen fopen
676 #endif
678 #ifndef OsFclose
679 #define OsFclose(pFile) fclose(((FILE*)pFile))
680 #endif
682 #ifndef OsFwrite
683 #define OsFwrite fwrite
684 #endif
686 #ifndef OsFread
687 #define OsFread(pDstBuf,dwElemSize,dwCnt,hFile) fread((pDstBuf),(dwElemSize),(dwCnt),((FILE*)hFile))
688 #endif
690 #ifndef OsFflush
691 #define OsFflush fflush
692 #endif
694 /* this function currently is only used in the MotionDemo application, see also AtXmlParser.cpp */
695 /*
696 #ifndef OsGetFileSize
697 EC_T_INLINE(EC_T_DWORD OsGetFileSize(FILE* fp)) {long l;fseek((fp),0,SEEK_END);l=ftell((fp));fseek((fp),0,SEEK_SET);return l;}
698 #endif
699 */
701 #ifndef OsDbgAssert
702 #define OsDbgAssert assert
703 #endif
705 #ifndef OsSetLastError
706 #define OsSetLastError(dwError) dwError
707 #endif
709 #ifndef OsSetEvent
710 #define OsSetEvent(hEvent) SetEvent((HANDLE)(hEvent))
711 #endif
713 #ifndef OsResetEvent
714 #define OsResetEvent(hEvent) ResetEvent(hEvent)
715 #endif
717 #ifndef OsMemoryBarrier
718 #define OsMemoryBarrier() { EC_T_DWORD dwDummy = 0; __asm xchg dwDummy, eax }
719 #endif
721 /*! \def OsSleep(dwMsec)
722 \brief An macro for platform-abstracted Sleep().
723 \param dwMsec time to sleep in msecs.
724 \return N/A.
725 Suspends the execution of the current thread for a specified interval.
726 Aligned to ticks it sleeps until the next dwMsec/(tick period) tick.
727 */
728 #ifndef OsSleep
729 #error "OsSleep has to be defined in EcOsPlatform.h"
730 #endif
732 #ifndef OsReleaseLinkLayerRegFunc
733 #define OsReleaseLinkLayerRegFunc(szDriverIdent)
734 #endif
736 #ifdef __cplusplus
737 #ifndef EC_NEW
738 #define EC_NEW(x) new (std::nothrow) x
739 #endif
740 #endif /* __cplusplus */
742 EC_T_VOID* OsCfgFileOpen(const EC_T_CHAR* szCfgFileName);
743 EC_T_INT OsCfgFileClose(EC_T_VOID* pvCfgFile);
744 EC_T_INT OsCfgFileRead(EC_T_VOID* pvCfgFile, EC_T_VOID* pvDst, EC_T_INT nLen);
745 EC_T_INT OsCfgFileError(EC_T_VOID* pvCfgFile);
746 EC_T_INT OsCfgFileEof(EC_T_VOID* pvCfgFile);
748 /* these functions are actually part of the master core */
749 ATECAT_API EC_T_INT EcVsnprintf(EC_T_CHAR* szDest, EC_T_INT nMaxSize, const EC_T_CHAR* szFormat, EC_T_VALIST vaList);
750 ATECAT_API EC_T_INT EcSnprintf(EC_T_CHAR* szDest, EC_T_INT nMaxSize, const EC_T_CHAR* szFormat, ...);
752 #ifndef OsQueryMsecCount
753 ATECAT_API EC_T_DWORD OsQueryMsecCount(EC_T_VOID);
754 #endif
755 #ifndef OsSleep
756 EC_T_VOID OsSleep(EC_T_DWORD dwMsec);
757 #endif
759 /***********/
760 /* logging */
761 /***********/
762 #define EC_LOG_LEVEL_UNDEFINED 0
763 #define EC_LOG_LEVEL_CRITICAL 1
764 #define EC_LOG_LEVEL_ERROR 2
765 #define EC_LOG_LEVEL_WARNING 3
766 #define EC_LOG_LEVEL_INFO 4
767 #define EC_LOG_LEVEL_VERBOSE 5
769 ATECAT_API EC_T_VOID OsDbgMsg(const EC_T_CHAR* szFormat, ...); /* obsolete. Use LogMsg to log to buffer and OsPrintf when logging from buffer. */
770 ATECAT_API EC_T_DWORD OsLogMsg(EC_T_DWORD dwLogLevel, const EC_T_CHAR* szFormat, ...);
771 ATECAT_API EC_T_DWORD OsSetLogLevel(EC_T_DWORD dwLogLevel);
773 #ifdef INCLUDE_LOG_MESSAGES
774 #define EcLinkErrorMsg m_poEcDevice->LinkErrorMsg
775 #define EcLinkDbgMsg m_poEcDevice->LinkDbgMsg
776 #define EC_ERRORMSG(Msg) OsDbgMsg Msg; OsDbgAssert(EC_FALSE) /* print an error message and jump into debugger */
777 #define EC_ERRORMSGC(Msg) OsDbgMsg Msg /* print an error message and continue */
778 #define EC_DBGMSG OsDbgMsg /* print an error message and continue */
779 #define EC_ERRORMSGL(Msg) EcLinkErrorMsg Msg /* send an error message to the link layer for debugging purposes */
780 #define EC_DBGMSGL(Msg) EcLinkDbgMsg Msg /* send an debug message to the link layer for debugging purposes */
781 #define EC_ERRORMSGC_L(Msg) EC_ERRORMSGL(Msg); EC_ERRORMSGC(Msg)
782 #define EC_ERRORMSG_L(Msg) EC_ERRORMSGL(Msg); EC_ERRORMSG(Msg)
783 #define EC_DBGMSG_L(Msg) EC_DBGMSG(Msg); EC_DBGMSGL(Msg)
784 #else
785 #define EC_ERRORMSG(...)
786 #define EC_ERRORMSGC(...)
787 #define EC_DBGMSG(...)
788 #define EC_ERRORMSGL(...)
789 #define EC_DBGMSGL(...)
790 #define EC_ERRORMSGC_L(...)
791 #define EC_ERRORMSG_L(...)
792 #define EC_DBGMSG_L(...)
793 #endif
795 /***************************/
796 /* performance measurement */
797 /***************************/
798 /* timestamp counter interface for performance measurements (main functions are part of the master core) */
799 #ifndef INCLUDE_OS_PLATFORM_TSC_SUPPORT
801 /* if platform does not have specific TSC support, check for defaults if it is yet available */
802 #if (defined UNDER_CE && defined _M_IX86) || (defined RTOS_32) || (defined VXWORKS && defined CPU && ((CPU==PENTIUM) || (CPU==PENTIUM4))) || (defined QNX6) || ((defined WIN32) && !(defined UNDER_CE)) || ((defined LINUX) && (defined __i386__)) || defined __INTIME__
803 #define INCLUDE_OS_PLATFORM_TSC_SUPPORT
804 #define INCLUDE_PENTIUM_TSC
805 #endif
806 #if (defined __RCX__)
807 #define INCLUDE_ARM_TSC
808 #endif
810 #endif
812 typedef EC_T_VOID (*EC_T_FNMESSAGE) (EC_T_CHAR* szMsg);
814 /* performance measurement descriptors */
815 #include EC_PACKED_INCLUDESTART(8)
816 typedef struct _EC_T_TSC_TIME
817 {
818 EC_T_UINT64 qwStart; /* start time */
819 EC_T_UINT64 qwEnd; /* end time */
820 EC_T_DWORD dwCurr; /* [1/10 usec] */
821 EC_T_DWORD dwMax; /* [1/10 usec] */
822 EC_T_DWORD dwAvg; /* [1/100 usec] */
823 EC_T_BOOL bMeasReset; /* EC_TRUE if measurement values shall be reset */
824 EC_T_INT nIntLevel; /* for interrupt lockout handling */
825 } EC_PACKED(8) EC_T_TSC_TIME;
826 #include EC_PACKED_INCLUDESTOP
828 #include EC_PACKED_INCLUDESTART(8)
829 typedef struct _EC_T_TSC_MEAS_DESC
830 {
831 EC_T_TSC_TIME* aTscTime; /* timestamp info array */
832 EC_T_DWORD dwNumMeas; /* number of elements in aTscTime */
833 EC_T_BOOL bMeasEnabled; /* EC_TRUE if measurement is enabled */
834 EC_T_VOID* pPrivateData; /* OS layer private data */
835 EC_T_FNMESSAGE pfnMessage; /* Function pointer for message drop */
836 } EC_PACKED(8) EC_T_TSC_MEAS_DESC;
837 #include EC_PACKED_INCLUDESTOP
839 #ifndef OsTscMeasDisableIrq
840 /* default macros to enable/disable interrupts */
841 # if (defined UNDER_CE) && (defined _M_IX86)
842 # define OsTscMeasDisableIrq(pTscMeasDesc,dwIndex) { __asm cli };
843 # define OsTscMeasEnableIrq(pTscMeasDesc,dwIndex) { __asm sti };
844 # elif (defined VXWORKS)
845 # include "intLib.h"
846 /* Some customers don't define _WRS_VX_SMP, but using an SMP kernel.
847 * intCpuLock() should also work with the UP kernel (at least for versions > 6)
848 * and will then fall back to intLock().
849 */
850 # if ( defined(_WRS_VXWORKS_MAJOR) && ((_WRS_VXWORKS_MAJOR == 6) && (_WRS_VXWORKS_MINOR >= 6)) \
851 || (_WRS_VXWORKS_MAJOR > 6) ) || defined(_WRS_VX_SMP)
852 # define OsTscMeasDisableIrq(pTscMeasDesc,dwIndex) { pTscMeasDesc->aTscTime[dwIndex].nIntLevel = intCpuLock(); };
853 # define OsTscMeasEnableIrq(pTscMeasDesc,dwIndex) { intCpuUnlock(pTscMeasDesc->aTscTime[dwIndex].nIntLevel); };
854 # else
855 # define OsTscMeasDisableIrq(pTscMeasDesc,dwIndex) { pTscMeasDesc->aTscTime[dwIndex].nIntLevel = intLock(); };
856 # define OsTscMeasEnableIrq(pTscMeasDesc,dwIndex) { intUnlock(pTscMeasDesc->aTscTime[dwIndex].nIntLevel); };
857 # endif /* if ((defined _WRS_VXWORKS_MAJOR) && (_WRS_VXWORKS_MAJOR >= 6)) */
858 # elif (defined QNX6)
859 # define OsTscMeasDisableIrq(pTscMeasDesc,dwIndex) { ThreadCtl( _NTO_TCTL_IO, 0 );InterruptDisable(); };
860 # define OsTscMeasEnableIrq(pTscMeasDesc,dwIndex) { ThreadCtl( _NTO_TCTL_IO, 0 );InterruptEnable(); };
861 # elif (defined RTOS_32)
862 # define OsTscMeasDisableIrq(pTscMeasDesc,dwIndex) { __asm {cli }};
863 # define OsTscMeasEnableIrq(pTscMeasDesc,dwIndex) { __asm {sti }};
864 # else
865 # define OsTscMeasDisableIrq(pTscMeasDesc,dwIndex)
866 # define OsTscMeasEnableIrq(pTscMeasDesc,dwIndex)
867 # endif
868 #endif /* ifndef OsTscMeasDisableIrq */
870 ATECAT_API EC_T_VOID OsMeasCalibrate(EC_T_UINT64 dwlFreqSet);
871 ATECAT_API EC_T_DWORD OsMeasGet100kHzFrequency(EC_T_VOID);
872 ATECAT_API EC_T_UINT64 OsMeasGetCounterTicks(EC_T_VOID);
874 /* optional: redirect trace messages into OS specific function, e.g. to store trace log into file
875 * default: print trace log as debug message
876 */
877 #ifndef OsTrcMsg
878 #define OsTrcMsg EC_DBGMSG
879 #endif
881 ATECAT_API EC_T_VOID* OsCreateLock(EC_T_VOID);
882 ATECAT_API EC_T_VOID* OsCreateLockTyped(EC_T_OS_LOCK_TYPE eLockType);
883 ATECAT_API EC_T_VOID OsDeleteLock(EC_T_VOID* pvLock);
884 ATECAT_API EC_T_VOID OsLock(EC_T_VOID* pvLock);
885 ATECAT_API EC_T_VOID OsUnlock(EC_T_VOID* pvLock);
887 ATECAT_API EC_T_VOID* OsCreateEvent(EC_T_VOID);
888 ATECAT_API EC_T_VOID OsDeleteEvent(EC_T_VOID* pvEvent);
889 #ifndef OsWaitForEvent
890 ATECAT_API EC_T_DWORD OsWaitForEvent(EC_T_VOID* pvEvent, EC_T_DWORD dwTimeout);
891 #endif
892 #ifndef OsSetEvent
893 EC_T_VOID OsSetEvent(EC_T_VOID* pvEvent);
894 #endif
896 #ifndef OsCreateThread
897 ATECAT_API EC_T_VOID* OsCreateThread(EC_T_CHAR* szThreadName, EC_PF_THREADENTRY pfThreadEntry, EC_T_DWORD dwPrio, EC_T_DWORD dwStackSize, EC_T_VOID* pvParams);
898 #endif
899 #ifndef OsDeleteThreadHandle
900 ATECAT_API EC_T_VOID OsDeleteThreadHandle(EC_T_VOID* pvThreadObject);
901 #endif
902 #ifndef OsSetThreadPriority
903 ATECAT_API EC_T_VOID OsSetThreadPriority( EC_T_VOID* pvThreadObject, EC_T_DWORD dwPrio);
904 #endif
905 #ifndef OsSetThreadAffinity
906 ATECAT_API EC_T_BOOL OsSetThreadAffinity( EC_T_VOID* pvThreadObject, EC_T_CPUSET CpuSet);
907 #endif
908 #ifndef OsGetThreadAffinity
909 EC_T_BOOL OsGetThreadAffinity( EC_T_VOID* pvThreadObject, EC_T_CPUSET* pCpuSet);
910 #endif
912 ATECAT_API EC_PF_LLREGISTER OsGetLinkLayerRegFunc( EC_T_CHAR* szDriverIdent );
913 ATECAT_API EC_T_DWORD OsSystemTimeGet(EC_T_UINT64* pqwSystemTime);
915 #ifndef OsMemoryBarrier
916 EC_T_VOID OsMemoryBarrier(EC_T_VOID);
917 #endif
919 ATECAT_API EC_PF_OSDBGMSGHK OsGetDbgMsgHook(EC_T_VOID);
921 #ifndef OsForceThreadPrioNormal
922 ATECAT_API EC_T_DWORD OsForceThreadPrioNormal(EC_T_VOID);
923 #endif
926 #if (defined EC_SOCKET_IP_SUPPORTED)
928 #ifndef EC_FD_SET
929 #define EC_FD_SET FD_SET
930 #endif
932 #ifndef EC_FD_ZERO
933 #define EC_FD_ZERO FD_ZERO
934 #endif
936 #ifndef EC_FD_ISSET
937 #define EC_FD_ISSET FD_ISSET
938 #endif
940 ATECAT_API EC_T_DWORD OsSocketInit(EC_T_VOID);
941 ATECAT_API EC_T_DWORD OsSocketDeInit(EC_T_VOID);
943 #ifndef OsSocket
944 #define OsSocket(nAddrFamily, nSockType, nProtocol) socket(nAddrFamily, nSockType, nProtocol)
945 #endif
947 #ifndef OsSocketBind
948 #define OsSocketBind(hSockHandle, oSockAddr, nSockAddrLen) bind(hSockHandle, oSockAddr, nSockAddrLen)
949 #endif
951 #ifndef OsSocketListen
952 #define OsSocketListen(hSockHandle, nBacklog) listen(hSockHandle, nBacklog)
953 #endif
955 #ifndef OsSocketSelect
956 #define OsSocketSelect(nNfds, poReadFds, poWriteFds, poExceptFds, poTimeout) select(nNfds, poReadFds, poWriteFds, poExceptFds, poTimeout)
957 #endif
959 #ifndef OsSocketAccept
960 #define OsSocketAccept(hSockHandle, oSockAddr, nSockAddrLen) accept(hSockHandle, oSockAddr, nSockAddrLen)
961 #endif
963 #ifndef OsSocketConnect
964 #define OsSocketConnect(hSockHandle, oSockAddr, nSockAddrLen) connect(hSockHandle, oSockAddr, nSockAddrLen)
965 #endif
967 #ifndef OsSocketShutdown
968 #define OsSocketShutdown(hSockHandle, nFlags) shutdown(hSockHandle, nFlags)
969 #endif
971 #ifndef OsSocketSend
972 #define OsSocketSend(hSockHandle, pbyBuffer, dwBufferLen, dwFlags) send(hSockHandle, pbyBuffer, dwBufferLen, dwFlags)
973 #endif
975 #ifndef OsSocketSendTo
976 #define OsSocketSendTo(hSockHandle, pbyBuffer, dwBufferLen, dwFlags, oDstAddr, dwDstAddrLen) sendto(hSockHandle, pbyBuffer, dwBufferLen, dwFlags, oDstAddr, dwDstAddrLen)
977 #endif
979 #ifndef OsSocketRecv
980 #define OsSocketRecv(hSockHandle, pbyBuffer, dwBufferLen, dwFlags) recv(hSockHandle, pbyBuffer, dwBufferLen, dwFlags)
981 #endif
983 #ifndef OsSocketRecvFrom
984 #define OsSocketRecvFrom(hSockHandle, pbyBuffer, dwBufferLen, dwFlags, oSrcAddr, dwSrcAddrLen) recvfrom(hSockHandle, pbyBuffer, dwBufferLen, dwFlags, oSrcAddr, dwSrcAddrLen)
985 #endif
987 #ifndef OsSocketCloseSocket
988 #define OsSocketCloseSocket(hSockHandle) close(hSockHandle)
989 #endif
991 #ifndef OsSocketGetLastError
992 #error "OsSocketGetLastError has to be defined in EcOsPlatform.h"
993 #endif
995 #ifndef OsSocketSetSockOpt
996 #define OsSocketSetSockOpt(hSockHandle, nLevel, nOptName, pOptValue, nOptLen ) setsockopt(hSockHandle, nLevel, nOptName, pOptValue, nOptLen)
997 #endif
999 #ifndef OsHTONS
1000 #define OsHTONS(wHostVal) htons(wHostVal)
1001 #endif
1003 #endif /* EC_SOCKET_IP_SUPPORTED */
1005 #ifndef OsAuxClkInit
1006 #define OsAuxClkInit(dwCpuIndex, dwFrequencyHz, pvOsEvent) EC_FALSE
1007 #endif
1009 #ifndef OsAuxClkDeinit
1010 #define OsAuxClkDeinit(x)
1011 #endif
1013 #ifndef OsAuxClkInitialCountGet
1014 #define OsAuxClkInitialCountGet(pdwInitialCount) EC_E_NOTSUPPORTED
1015 #endif
1017 #ifndef OsAuxClkInputFrequencyGet
1018 #define OsAuxClkInputFrequencyGet(pdwFrequencyHz) EC_E_NOTSUPPORTED
1019 #endif
1021 #ifndef OsAuxClkOutputFrequencyGet
1022 #define OsAuxClkOutputFrequencyGet(pdwFrequencyHz) EC_E_NOTSUPPORTED
1023 #endif
1025 #ifndef OsAuxClkCorrectionSet
1026 #define OsAuxClkCorrectionSet(dwInitialCountNew, nIncrementDif, dwIntCountSet) EC_E_NOTSUPPORTED
1027 #endif
1029 #ifndef OsAuxClkTickSinceInterrupt
1030 #define OsAuxClkTickSinceInterrupt(pqwTicksSinceInterrupt) EC_E_NOTSUPPORTED
1031 #endif
1033 #ifndef OsHwTimerGetInputFrequency
1034 #define OsHwTimerGetInputFrequency(pdwFrequencyHz) EC_E_NOTSUPPORTED
1035 #endif
1037 #ifndef OsHwTimerModifyInitialCount
1038 #define OsHwTimerModifyInitialCount(nAdjustPermil) EC_E_NOTSUPPORTED
1039 #endif
1041 /* request application to terminate, if not implemented: return FALSE */
1042 #ifndef OsTerminateAppRequest
1043 #define OsTerminateAppRequest() EC_FALSE
1044 #endif
1046 #ifdef __cplusplus
1047 } /* extern "C"*/
1048 #endif
1050 #endif /* INC_ECOS */
1052 /*-END OF SOURCE FILE--------------------------------------------------------*/