types.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2013
  6. All rights reserved.
  7. */
  8. #ifndef DSI_TYPES_H
  9. #define DSI_TYPES_H
  10. #if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(_WIN64) || defined(__TOS_WIN__) || defined(__WINDOWS__) //Windows Platform
  11. #define DSI_TYPES_WINDOWS
  12. #if defined(_WIN32_WINNT)
  13. #if (_WIN32_WINNT < 0x501)
  14. #undef _WIN32_WINNT
  15. #define _WIN32_WINNT 0x0501
  16. #endif
  17. #else
  18. #define _WIN32_WINNT 0X0501
  19. #endif
  20. #include <windows.h>
  21. #elif defined(macintosh) || defined (Macintosh) || defined(__APPLE__) || defined(__MACH__)
  22. // Apple platform (first two defines are for Mac OS 9; last two are for Mac OS X)
  23. #define DSI_TYPES_MACINTOSH
  24. #elif defined(linux) || defined (__linux) // Linux platform
  25. #define DSI_TYPES_LINUX
  26. #else
  27. #define DSI_TYPES_OTHER_OS
  28. #endif
  29. //////////////////////////////////////////////////////////////////////////////////
  30. // Public Definitions
  31. //////////////////////////////////////////////////////////////////////////////////
  32. #if !defined(TRUE)
  33. #define TRUE ((BOOL) 1)
  34. #endif
  35. #if !defined(FALSE)
  36. #define FALSE ((BOOL) 0)
  37. #endif
  38. #if !defined(NULL) // <windef.h> compatibility.
  39. #define NULL ((void *) 0)
  40. #endif
  41. #define NUL '\0'
  42. #define MAX_SCHAR ((SCHAR) 0x7F)
  43. #define MIN_SCHAR ((SCHAR) 0x80)
  44. #define MAX_UCHAR ((UCHAR) 0xFF)
  45. #define MIN_UCHAR ((UCHAR) 0)
  46. #define MAX_SSHORT ((SSHORT) 0x7FFF)
  47. #define MIN_SSHORT ((SSHORT) 0x8000)
  48. #define MAX_USHORT ((USHORT) 0xFFFF)
  49. #define MIN_USHORT ((USHORT) 0)
  50. #define MAX_SLONG ((SLONG) 0x7FFFFFFF)
  51. #define MIN_SLONG ((SLONG) 0x80000000)
  52. #define MAX_ULONG ((ULONG) 0xFFFFFFFF)
  53. #define MIN_ULONG ((ULONG) 0)
  54. #if defined (__ICC8051__)
  55. #define C_TYPE __code
  56. #define MEM_TYPE __xdata
  57. #define MEM_TYPE_S static __xdata
  58. #define MEM_TYPE_P __xdata *
  59. #define BIT_TYPE __bdata
  60. #define DIR_TYPE __data
  61. #else
  62. #define C_TYPE
  63. #define MEM_TYPE
  64. #define MEM_TYPE_S
  65. #define MEM_TYPE_P
  66. #define BIT_TYPE
  67. #define DIR_TYPE
  68. #endif
  69. #if defined(__IAR_SYSTEMS_ICC__)
  70. #define BITFIELD_START struct {
  71. #define BITFIELD_END }
  72. #define BITS_1 : 1
  73. #define BITS_2 : 2
  74. #define BITS_3 : 3
  75. #define BITS_4 : 4
  76. #define BITS_5 : 5
  77. #define BITS_6 : 6
  78. #define BITS_7 : 7
  79. #else
  80. #define BITFIELD_START
  81. #define BITFIELD_END
  82. #define BITS_1
  83. #define BITS_2
  84. #define BITS_3
  85. #define BITS_4
  86. #define BITS_5
  87. #define BITS_6
  88. #define BITS_7
  89. #endif
  90. #if !defined(DSI_TYPES_WINDOWS)
  91. #if !defined(BASETYPES) && !defined(_WinToMac_h_)
  92. typedef unsigned char BOOL;
  93. typedef char BYTE; // 1-byte int. Sign is processor/compiler-dependent.
  94. #endif
  95. #endif
  96. typedef unsigned char BOOL_SAFE; // BOOL that doesn't get redefined to signed int in windows to result in TRUE=-1 when used in bit fields.
  97. typedef signed char SCHAR; // Signed 1-byte int.
  98. typedef unsigned char UCHAR; // Unsigned 1-byte int.
  99. typedef signed short SSHORT; // Signed 2-byte int.
  100. typedef unsigned short USHORT; // Unsigned 2-byte int.
  101. typedef signed long SLONG; // Signed 4-byte int.
  102. #if defined (DSI_TYPES_MACINTOSH)
  103. #include <MacTypes.h>
  104. typedef UInt32 ULONG;
  105. #else
  106. typedef unsigned long ULONG; // Unsigned 4-byte int.
  107. #endif
  108. #if !defined(_WinToMac_h_)
  109. typedef long LONG;
  110. // 4-byte int. Sign is processor/compiler-dependent. Commonly assumed
  111. // to be signed, however this is not guaranteed. Suggested use for
  112. // this type is for efficient data passing and bit manipulation.
  113. // Assuming any sign for math may be problematic, especially on code
  114. // intended to be cross-platform.
  115. #endif
  116. #if !defined(__BORLANDC__)
  117. typedef signed long long SLLONG; // Signed 8-byte int.
  118. typedef unsigned long long ULLONG; // Unsigned 8-byte int.
  119. #endif
  120. typedef float FLOAT; // 2-byte floating point.
  121. typedef double DOUBLE; // 4-byte floating point.
  122. ///////////////////////////////////////////////////////////////////////
  123. // !!NOTE: The structures below assume little endian architecture!!
  124. ///////////////////////////////////////////////////////////////////////
  125. typedef union
  126. {
  127. USHORT usData;
  128. struct
  129. {
  130. UCHAR ucLow;
  131. UCHAR ucHigh;
  132. } stBytes;
  133. } USHORT_UNION;
  134. #define USHORT_HIGH(X) (((USHORT_UNION *)(X))->stBytes.ucHigh)
  135. #define USHORT_LOW(X) (((USHORT_UNION *)(X))->stBytes.ucLow)
  136. typedef union
  137. {
  138. signed short ssData;
  139. struct
  140. {
  141. UCHAR ucLow;
  142. UCHAR ucHigh;
  143. } stBytes;
  144. } SSHORT_UNION;
  145. #define SSHORT_HIGH(X) (((SSHORT_UNION *)(X))->stBytes.ucHigh)
  146. #define SSHORT_LOW(X) (((SSHORT_UNION *)(X))->stBytes.ucLow)
  147. typedef union
  148. {
  149. UCHAR aucData[4];
  150. ULONG ulData;
  151. struct
  152. {
  153. // The least significant byte of the ULONG in this structure is
  154. // referenced by ucByte0.
  155. UCHAR ucByte0;
  156. UCHAR ucByte1;
  157. UCHAR ucByte2;
  158. UCHAR ucByte3;
  159. } stBytes;
  160. } ULONG_UNION;
  161. #define ULONG_LOW_0(X) (((ULONG_UNION *)(X))->stBytes.ucByte0)
  162. #define ULONG_MID_1(X) (((ULONG_UNION *)(X))->stBytes.ucByte1)
  163. #define ULONG_MID_2(X) (((ULONG_UNION *)(X))->stBytes.ucByte2)
  164. #define ULONG_HIGH_3(X) (((ULONG_UNION *)(X))->stBytes.ucByte3)
  165. #endif // defined(DSI_TYPES_H)