basic_types.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. *
  19. ******************************************************************************/
  20. #ifndef __BASIC_TYPES_H__
  21. #define __BASIC_TYPES_H__
  22. #define SUCCESS 0
  23. #define FAIL (-1)
  24. #ifndef TRUE
  25. #define _TRUE 1
  26. #else
  27. #define _TRUE TRUE
  28. #endif
  29. #ifndef FALSE
  30. #define _FALSE 0
  31. #else
  32. #define _FALSE FALSE
  33. #endif
  34. #ifdef PLATFORM_WINDOWS
  35. typedef signed char s8;
  36. typedef unsigned char u8;
  37. typedef signed short s16;
  38. typedef unsigned short u16;
  39. typedef signed long s32;
  40. typedef unsigned long u32;
  41. typedef unsigned int uint;
  42. typedef signed int sint;
  43. typedef signed long long s64;
  44. typedef unsigned long long u64;
  45. #ifdef NDIS50_MINIPORT
  46. #define NDIS_MAJOR_VERSION 5
  47. #define NDIS_MINOR_VERSION 0
  48. #endif
  49. #ifdef NDIS51_MINIPORT
  50. #define NDIS_MAJOR_VERSION 5
  51. #define NDIS_MINOR_VERSION 1
  52. #endif
  53. typedef NDIS_PROC proc_t;
  54. typedef LONG atomic_t;
  55. #endif
  56. #ifdef PLATFORM_LINUX
  57. #include <linux/types.h>
  58. #define IN
  59. #define OUT
  60. #define VOID void
  61. #define NDIS_OID uint
  62. #define NDIS_STATUS uint
  63. typedef signed int sint;
  64. #ifndef PVOID
  65. typedef void * PVOID;
  66. //#define PVOID (void *)
  67. #endif
  68. #define UCHAR u8
  69. #define USHORT u16
  70. #define UINT u32
  71. #define ULONG u32
  72. typedef void (*proc_t)(void*);
  73. typedef __kernel_size_t SIZE_T;
  74. typedef __kernel_ssize_t SSIZE_T;
  75. #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
  76. #endif
  77. #ifdef PLATFORM_FREEBSD
  78. typedef signed char s8;
  79. typedef unsigned char u8;
  80. typedef signed short s16;
  81. typedef unsigned short u16;
  82. typedef signed int s32;
  83. typedef unsigned int u32;
  84. typedef unsigned int uint;
  85. typedef signed int sint;
  86. typedef long atomic_t;
  87. typedef signed long long s64;
  88. typedef unsigned long long u64;
  89. #define IN
  90. #define OUT
  91. #define VOID void
  92. #define NDIS_OID uint
  93. #define NDIS_STATUS uint
  94. #ifndef PVOID
  95. typedef void * PVOID;
  96. //#define PVOID (void *)
  97. #endif
  98. typedef u32 dma_addr_t;
  99. #define UCHAR u8
  100. #define USHORT u16
  101. #define UINT u32
  102. #define ULONG u32
  103. typedef void (*proc_t)(void*);
  104. typedef unsigned int __kernel_size_t;
  105. typedef int __kernel_ssize_t;
  106. typedef __kernel_size_t SIZE_T;
  107. typedef __kernel_ssize_t SSIZE_T;
  108. #define FIELD_OFFSET(s,field) ((SSIZE_T)&((s*)(0))->field)
  109. #endif
  110. #define MEM_ALIGNMENT_OFFSET (sizeof (SIZE_T))
  111. #define MEM_ALIGNMENT_PADDING (sizeof(SIZE_T) - 1)
  112. #define SIZE_PTR SIZE_T
  113. #define SSIZE_PTR SSIZE_T
  114. //port from fw by thomas
  115. // TODO: Belows are Sync from SD7-Driver. It is necessary to check correctness
  116. /*
  117. * Call endian free function when
  118. * 1. Read/write packet content.
  119. * 2. Before write integer to IO.
  120. * 3. After read integer from IO.
  121. */
  122. //
  123. // Byte Swapping routine.
  124. //
  125. #define EF1Byte
  126. #define EF2Byte le16_to_cpu
  127. #define EF4Byte le32_to_cpu
  128. //
  129. // Read LE format data from memory
  130. //
  131. #define ReadEF1Byte(_ptr) EF1Byte(*((u8 *)(_ptr)))
  132. #define ReadEF2Byte(_ptr) EF2Byte(*((u16 *)(_ptr)))
  133. #define ReadEF4Byte(_ptr) EF4Byte(*((u32 *)(_ptr)))
  134. //
  135. // Write LE data to memory
  136. //
  137. #define WriteEF1Byte(_ptr, _val) (*((u8 *)(_ptr)))=EF1Byte(_val)
  138. #define WriteEF2Byte(_ptr, _val) (*((u16 *)(_ptr)))=EF2Byte(_val)
  139. #define WriteEF4Byte(_ptr, _val) (*((u32 *)(_ptr)))=EF4Byte(_val)
  140. //
  141. // Example:
  142. // BIT_LEN_MASK_32(0) => 0x00000000
  143. // BIT_LEN_MASK_32(1) => 0x00000001
  144. // BIT_LEN_MASK_32(2) => 0x00000003
  145. // BIT_LEN_MASK_32(32) => 0xFFFFFFFF
  146. //
  147. #define BIT_LEN_MASK_32(__BitLen) \
  148. (0xFFFFFFFF >> (32 - (__BitLen)))
  149. //
  150. // Example:
  151. // BIT_OFFSET_LEN_MASK_32(0, 2) => 0x00000003
  152. // BIT_OFFSET_LEN_MASK_32(16, 2) => 0x00030000
  153. //
  154. #define BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) \
  155. (BIT_LEN_MASK_32(__BitLen) << (__BitOffset))
  156. //
  157. // Description:
  158. // Return 4-byte value in host byte ordering from
  159. // 4-byte pointer in litten-endian system.
  160. //
  161. #define LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
  162. (EF4Byte(*((u32 *)(__pStart))))
  163. //
  164. // Description:
  165. // Translate subfield (continuous bits in little-endian) of 4-byte value in litten byte to
  166. // 4-byte value in host byte ordering.
  167. //
  168. #define LE_BITS_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
  169. ( \
  170. ( LE_P4BYTE_TO_HOST_4BYTE(__pStart) >> (__BitOffset) ) \
  171. & \
  172. BIT_LEN_MASK_32(__BitLen) \
  173. )
  174. //
  175. // Description:
  176. // Mask subfield (continuous bits in little-endian) of 4-byte value in litten byte oredering
  177. // and return the result in 4-byte value in host byte ordering.
  178. //
  179. #define LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
  180. ( \
  181. LE_P4BYTE_TO_HOST_4BYTE(__pStart) \
  182. & \
  183. ( ~BIT_OFFSET_LEN_MASK_32(__BitOffset, __BitLen) ) \
  184. )
  185. //
  186. // Description:
  187. // Set subfield of little-endian 4-byte value to specified value.
  188. //
  189. #define SET_BITS_TO_LE_4BYTE(__pStart, __BitOffset, __BitLen, __Value) \
  190. *((u32 *)(__pStart)) = \
  191. EF4Byte( \
  192. LE_BITS_CLEARED_TO_4BYTE(__pStart, __BitOffset, __BitLen) \
  193. | \
  194. ( (((u32)__Value) & BIT_LEN_MASK_32(__BitLen)) << (__BitOffset) ) \
  195. );
  196. #define BIT_LEN_MASK_16(__BitLen) \
  197. (0xFFFF >> (16 - (__BitLen)))
  198. #define BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) \
  199. (BIT_LEN_MASK_16(__BitLen) << (__BitOffset))
  200. #define LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
  201. (EF2Byte(*((u16 *)(__pStart))))
  202. #define LE_BITS_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
  203. ( \
  204. ( LE_P2BYTE_TO_HOST_2BYTE(__pStart) >> (__BitOffset) ) \
  205. & \
  206. BIT_LEN_MASK_16(__BitLen) \
  207. )
  208. #define LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
  209. ( \
  210. LE_P2BYTE_TO_HOST_2BYTE(__pStart) \
  211. & \
  212. ( ~BIT_OFFSET_LEN_MASK_16(__BitOffset, __BitLen) ) \
  213. )
  214. #define SET_BITS_TO_LE_2BYTE(__pStart, __BitOffset, __BitLen, __Value) \
  215. *((u16 *)(__pStart)) = \
  216. EF2Byte( \
  217. LE_BITS_CLEARED_TO_2BYTE(__pStart, __BitOffset, __BitLen) \
  218. | \
  219. ( (((u16)__Value) & BIT_LEN_MASK_16(__BitLen)) << (__BitOffset) ) \
  220. );
  221. #define BIT_LEN_MASK_8(__BitLen) \
  222. (0xFF >> (8 - (__BitLen)))
  223. #define BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) \
  224. (BIT_LEN_MASK_8(__BitLen) << (__BitOffset))
  225. #define LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
  226. (EF1Byte(*((u8 *)(__pStart))))
  227. #define LE_BITS_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
  228. ( \
  229. ( LE_P1BYTE_TO_HOST_1BYTE(__pStart) >> (__BitOffset) ) \
  230. & \
  231. BIT_LEN_MASK_8(__BitLen) \
  232. )
  233. #define LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
  234. ( \
  235. LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
  236. & \
  237. ( ~BIT_OFFSET_LEN_MASK_8(__BitOffset, __BitLen) ) \
  238. )
  239. #define SET_BITS_TO_LE_1BYTE(__pStart, __BitOffset, __BitLen, __Value) \
  240. *((u8 *)(__pStart)) = \
  241. EF1Byte( \
  242. LE_BITS_CLEARED_TO_1BYTE(__pStart, __BitOffset, __BitLen) \
  243. | \
  244. ( (((u8)__Value) & BIT_LEN_MASK_8(__BitLen)) << (__BitOffset) ) \
  245. );
  246. //pclint
  247. #define LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
  248. ( \
  249. LE_P1BYTE_TO_HOST_1BYTE(__pStart) \
  250. )
  251. //pclint
  252. #define SET_BITS_TO_LE_1BYTE_8BIT(__pStart, __BitOffset, __BitLen, __Value) \
  253. { \
  254. *((pu1Byte)(__pStart)) = \
  255. EF1Byte( \
  256. LE_BITS_CLEARED_TO_1BYTE_8BIT(__pStart, __BitOffset, __BitLen) \
  257. | \
  258. ((u1Byte)__Value) \
  259. ); \
  260. }
  261. // Get the N-bytes aligment offset from the current length
  262. #define N_BYTE_ALIGMENT(__Value, __Aligment) ((__Aligment == 1) ? (__Value) : (((__Value + __Aligment - 1) / __Aligment) * __Aligment))
  263. typedef unsigned char BOOLEAN,*PBOOLEAN;
  264. #endif //__BASIC_TYPES_H__