Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 lines
21 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: util.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _UTIL_
  11. #define _UTIL_
  12. #define GetStatus(RegisterBase) \
  13. (P5ReadPortUchar((RegisterBase)+DSR_OFFSET))
  14. #define GetControl(RegisterBase) \
  15. (P5ReadPortUchar((RegisterBase)+DCR_OFFSET))
  16. #define StoreControl(RegisterBase,ControlByte) \
  17. { \
  18. P5WritePortUchar((RegisterBase)+DCR_OFFSET, \
  19. (UCHAR)ControlByte ); \
  20. }
  21. // The following macros may be used to test the contents of the Device
  22. // Status Regisger (DSR). These macros account for the hardware
  23. // inversion of the nBusy (aka PtrBusy, PeriphAck) signal.
  24. //////////////////////////////////////////////////////////////////////////////
  25. #if (1 == DVRH_USE_FAST_MACROS)
  26. #define DSR_TEST_MASK(b7,b6,b5,b4,b3) \
  27. ((UCHAR)(b7==DONT_CARE? 0: BIT_7_SET) | \
  28. (b6==DONT_CARE? 0: BIT_6_SET) | \
  29. (b5==DONT_CARE? 0: BIT_5_SET) | \
  30. (b4==DONT_CARE? 0: BIT_4_SET) | \
  31. (b3==DONT_CARE? 0: BIT_3_SET) )
  32. #else
  33. #define DSR_TEST_MASK(b7,b6,b5,b4,b3) \
  34. ((UCHAR)((b7==DONT_CARE?0:1)<<BIT_7) | \
  35. ((b6==DONT_CARE?0:1)<<BIT_6) | \
  36. ((b5==DONT_CARE?0:1)<<BIT_5) | \
  37. ((b4==DONT_CARE?0:1)<<BIT_4) | \
  38. ((b3==DONT_CARE?0:1)<<BIT_3) )
  39. #endif
  40. #if (1 == DVRH_USE_FAST_MACROS)
  41. #define DSR_TEST_VALUE(b7,b6,b5,b4,b3) \
  42. ((UCHAR) ((b7==DONT_CARE?0:(b7==ACTIVE?0 : BIT_7_SET)) | \
  43. (b6==DONT_CARE?0:(b6==ACTIVE? BIT_6_SET: 0)) | \
  44. (b5==DONT_CARE?0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  45. (b4==DONT_CARE?0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  46. (b3==DONT_CARE?0:(b3==ACTIVE? BIT_3_SET: 0)) ) )
  47. #else
  48. #define DSR_TEST_VALUE(b7,b6,b5,b4,b3) \
  49. ((UCHAR) (((b7==DONT_CARE?0:(b7==ACTIVE?0:1))<<BIT_7) | \
  50. ((b6==DONT_CARE?0:(b6==ACTIVE?1:0))<<BIT_6) | \
  51. ((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  52. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  53. ((b3==DONT_CARE?0:(b3==ACTIVE?1:0))<<BIT_3) ) )
  54. #endif
  55. #define TEST_DSR(registerValue,b7,b6,b5,b4,b3) \
  56. (((registerValue) & DSR_TEST_MASK(b7,b6,b5,b4,b3)) == DSR_TEST_VALUE(b7,b6,b5,b4,b3))
  57. #define CHECK_DSR( addr, b7, b6, b5, b4, b3, usTime ) \
  58. (TEST_DSR(P5ReadPortUchar(addr + DSR_OFFSET), b7, b6, b5, b4, b3 ) ? TRUE : \
  59. CheckPort( addr + DSR_OFFSET, \
  60. DSR_TEST_MASK( b7, b6, b5, b4, b3 ), \
  61. DSR_TEST_VALUE( b7, b6, b5, b4, b3 ), \
  62. usTime ) )
  63. ////////////////////////////////////////////////////////////////////////////////
  64. // The CHECK_DSR_AND_FIFO macro may be used to invoke the CheckPort2 function,
  65. // without having to specify the mask and value components twice.
  66. // CHECK_DSR_AND_FIFO does quick tests of the DSR and ECR ports first.
  67. // If the peripheral has already responded with either of the
  68. // desired values, CheckPort2 need not be called.
  69. ////////////////////////////////////////////////////////////////////////////////
  70. #define CHECK_DSR_WITH_FIFO( addr, b7, b6, b5, b4, b3, ecr_mask, ecr_value, msTime ) \
  71. ( TEST_DSR( P5ReadPortUchar( addr + OFFSET_DSR ), b7, b6, b5, b4, b3 ) ? TRUE : \
  72. CheckTwoPorts( addr + OFFSET_DSR, \
  73. DSR_TEST_MASK( b7, b6, b5, b4, b3 ), \
  74. DSR_TEST_VALUE( b7, b6, b5, b4, b3 ), \
  75. addr + ECR_OFFSET, \
  76. ecr_mask, \
  77. ecr_value, \
  78. msTime) )
  79. //////////////////////////////////////////////////////////////////////////////
  80. // The following defines and macros may be used to set, test, and
  81. // update the Device Control Register (DCR).
  82. //////////////////////////////////////////////////////////////////////////////
  83. // The DCR_AND_MASK macro generates a byte constant that is used by
  84. // the UPDATE_DCR macro.
  85. #if (1 == DVRH_USE_FAST_MACROS)
  86. #define DCR_AND_MASK(b5,b4,b3,b2,b1,b0) \
  87. ((UCHAR)((b5==DONT_CARE? BIT_5_SET:(b5==ACTIVE? BIT_5_SET: 0)) | \
  88. (b4==DONT_CARE? BIT_4_SET:(b4==ACTIVE? BIT_4_SET: 0)) | \
  89. (b3==DONT_CARE? BIT_3_SET:(b3==ACTIVE? 0: BIT_3_SET)) | \
  90. (b2==DONT_CARE? BIT_2_SET:(b2==ACTIVE? BIT_2_SET: 0)) | \
  91. (b1==DONT_CARE? BIT_1_SET:(b1==ACTIVE? 0: BIT_1_SET)) | \
  92. (b0==DONT_CARE? BIT_0_SET:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  93. #else
  94. #define DCR_AND_MASK(b5,b4,b3,b2,b1,b0) \
  95. ((UCHAR)(((b5==DONT_CARE?1:(b5==ACTIVE?1:0))<<BIT_5) | \
  96. ((b4==DONT_CARE?1:(b4==ACTIVE?1:0))<<BIT_4) | \
  97. ((b3==DONT_CARE?1:(b3==ACTIVE?0:1))<<BIT_3) | \
  98. ((b2==DONT_CARE?1:(b2==ACTIVE?1:0))<<BIT_2) | \
  99. ((b1==DONT_CARE?1:(b1==ACTIVE?0:1))<<BIT_1) | \
  100. ((b0==DONT_CARE?1:(b0==ACTIVE?0:1))<<BIT_0) ) )
  101. #endif
  102. // The DCR_OR_MASK macro generates a byte constant that is used by
  103. // the UPDATE_DCR macro.
  104. #if (1 == DVRH_USE_FAST_MACROS)
  105. #define DCR_OR_MASK(b5,b4,b3,b2,b1,b0) \
  106. ((UCHAR)((b5==DONT_CARE? 0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  107. (b4==DONT_CARE? 0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  108. (b3==DONT_CARE? 0:(b3==ACTIVE? 0: BIT_3_SET)) | \
  109. (b2==DONT_CARE? 0:(b2==ACTIVE? BIT_2_SET: 0)) | \
  110. (b1==DONT_CARE? 0:(b1==ACTIVE? 0: BIT_1_SET)) | \
  111. (b0==DONT_CARE? 0:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  112. #else
  113. #define DCR_OR_MASK(b5,b4,b3,b2,b1,b0) \
  114. ((UCHAR)(((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  115. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  116. ((b3==DONT_CARE?0:(b3==ACTIVE?0:1))<<BIT_3) | \
  117. ((b2==DONT_CARE?0:(b2==ACTIVE?1:0))<<BIT_2) | \
  118. ((b1==DONT_CARE?0:(b1==ACTIVE?0:1))<<BIT_1) | \
  119. ((b0==DONT_CARE?0:(b0==ACTIVE?0:1))<<BIT_0) ) )
  120. #endif
  121. // The UPDATE_DCR macro generates provides a selective update of specific bits
  122. // in the DCR. Any bit positions specified as DONT_CARE will be left
  123. // unchanged. The macro accounts for the hardware inversion of
  124. // certain signals.
  125. #define UPDATE_DCR(registerValue,b5,b4,b3,b2,b1,b0) \
  126. ((UCHAR)(((registerValue) & DCR_AND_MASK(b5,b4,b3,b2,b1,b0)) | DCR_OR_MASK(b5,b4,b3,b2,b1,b0)))
  127. // The DCR_TEST_MASK macro generates a byte constant which may be used
  128. // to mask of DCR bits that we don't care about
  129. #if (1 == DVRH_USE_FAST_MACROS)
  130. #define DCR_TEST_MASK(b5,b4,b3,b2,b1,b0) \
  131. ((UCHAR)((b5==DONT_CARE?0:BIT_5_SET) | \
  132. (b4==DONT_CARE?0:BIT_4_SET) | \
  133. (b3==DONT_CARE?0:BIT_3_SET) | \
  134. (b2==DONT_CARE?0:BIT_2_SET) | \
  135. (b1==DONT_CARE?0:BIT_1_SET) | \
  136. (b0==DONT_CARE?0:BIT_0_SET) ) )
  137. #else
  138. #define DCR_TEST_MASK(b5,b4,b3,b2,b1,b0) \
  139. ((UCHAR)( ((b5==DONT_CARE?0:1)<<BIT_5) | \
  140. ((b4==DONT_CARE?0:1)<<BIT_4) | \
  141. ((b3==DONT_CARE?0:1)<<BIT_3) | \
  142. ((b2==DONT_CARE?0:1)<<BIT_2) | \
  143. ((b1==DONT_CARE?0:1)<<BIT_1) | \
  144. ((b0==DONT_CARE?0:1)<<BIT_0) ) )
  145. #endif
  146. // The DCR_TEST_VALUE macro generates a byte constant that may be used
  147. // to compare against a masked DCR value. This macro takes into
  148. // account which signals are inverted by hardware before driving the
  149. // signal line.
  150. #if (1 == DVRH_USE_FAST_MACROS)
  151. #define DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0) \
  152. ((UCHAR)((b5==DONT_CARE?0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  153. (b4==DONT_CARE?0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  154. (b3==DONT_CARE?0:(b3==ACTIVE? 0: BIT_3_SET)) | \
  155. (b2==DONT_CARE?0:(b2==ACTIVE? BIT_2_SET: 0)) | \
  156. (b1==DONT_CARE?0:(b1==ACTIVE? 0: BIT_1_SET)) | \
  157. (b0==DONT_CARE?0:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  158. #else
  159. #define DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0) \
  160. ((UCHAR)(((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  161. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  162. ((b3==DONT_CARE?0:(b3==ACTIVE?0:1))<<BIT_3) | \
  163. ((b2==DONT_CARE?0:(b2==ACTIVE?1:0))<<BIT_2) | \
  164. ((b1==DONT_CARE?0:(b1==ACTIVE?0:1))<<BIT_1) | \
  165. ((b0==DONT_CARE?0:(b0==ACTIVE?0:1))<<BIT_0) ) )
  166. #endif
  167. // The TEST_DCR macro may be used to generate a boolean result that is
  168. // TRUE if the DCR value matches the specified signal levels and FALSE
  169. // otherwise.
  170. #define TEST_DCR(registerValue,b5,b4,b3,b2,b1,b0) \
  171. (((registerValue) & DCR_TEST_MASK(b5,b4,b3,b2,b1,b0)) == DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0))
  172. BOOLEAN CheckPort(IN PUCHAR offset_Controller,
  173. IN UCHAR dsrMask,
  174. IN UCHAR dsrValue,
  175. IN USHORT msTimeDelay);
  176. // *** original parclass util.h follows ***
  177. // Standard Maximum Timing values
  178. #define IEEE_MAXTIME_TL 35 // Max time Tl from the IEEE spec
  179. #define DEFAULT_RECEIVE_TIMEOUT 330
  180. #define ParEnterCriticalSection(Xtension) xTension->bCriticalSection = TRUE
  181. #define ParExitCriticalSection(Xtension) xTension->bCriticalSection = FALSE
  182. // The following macros may be used to test the contents of the Device
  183. // Status Regisger (DSR). These macros account for the hardware
  184. // inversion of the nBusy (aka PtrBusy, PeriphAck) signal.
  185. //////////////////////////////////////////////////////////////////////////////
  186. #if (1 == DVRH_USE_FAST_MACROS)
  187. #define DSR_TEST_MASK(b7,b6,b5,b4,b3) \
  188. ((UCHAR)(b7==DONT_CARE? 0: BIT_7_SET) | \
  189. (b6==DONT_CARE? 0: BIT_6_SET) | \
  190. (b5==DONT_CARE? 0: BIT_5_SET) | \
  191. (b4==DONT_CARE? 0: BIT_4_SET) | \
  192. (b3==DONT_CARE? 0: BIT_3_SET) )
  193. #else
  194. #define DSR_TEST_MASK(b7,b6,b5,b4,b3) \
  195. ((UCHAR)((b7==DONT_CARE?0:1)<<BIT_7) | \
  196. ((b6==DONT_CARE?0:1)<<BIT_6) | \
  197. ((b5==DONT_CARE?0:1)<<BIT_5) | \
  198. ((b4==DONT_CARE?0:1)<<BIT_4) | \
  199. ((b3==DONT_CARE?0:1)<<BIT_3) )
  200. #endif
  201. #if (1 == DVRH_USE_FAST_MACROS)
  202. #define DSR_TEST_VALUE(b7,b6,b5,b4,b3) \
  203. ((UCHAR) ((b7==DONT_CARE?0:(b7==ACTIVE?0 : BIT_7_SET)) | \
  204. (b6==DONT_CARE?0:(b6==ACTIVE? BIT_6_SET: 0)) | \
  205. (b5==DONT_CARE?0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  206. (b4==DONT_CARE?0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  207. (b3==DONT_CARE?0:(b3==ACTIVE? BIT_3_SET: 0)) ) )
  208. #else
  209. #define DSR_TEST_VALUE(b7,b6,b5,b4,b3) \
  210. ((UCHAR) (((b7==DONT_CARE?0:(b7==ACTIVE?0:1))<<BIT_7) | \
  211. ((b6==DONT_CARE?0:(b6==ACTIVE?1:0))<<BIT_6) | \
  212. ((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  213. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  214. ((b3==DONT_CARE?0:(b3==ACTIVE?1:0))<<BIT_3) ) )
  215. #endif
  216. #define TEST_DSR(registerValue,b7,b6,b5,b4,b3) \
  217. (((registerValue) & DSR_TEST_MASK(b7,b6,b5,b4,b3)) == DSR_TEST_VALUE(b7,b6,b5,b4,b3))
  218. #if 0 // use parport's util.h versions
  219. #define CHECK_DSR( addr, b7, b6, b5, b4, b3, msTime ) \
  220. (TEST_DSR(P5ReadPortUchar(addr + OFFSET_DSR), b7, b6, b5, b4, b3 ) ? TRUE : \
  221. CheckPort( addr + OFFSET_DSR, \
  222. DSR_TEST_MASK( b7, b6, b5, b4, b3 ), \
  223. DSR_TEST_VALUE( b7, b6, b5, b4, b3 ), \
  224. msTime ) )
  225. ////////////////////////////////////////////////////////////////////////////////
  226. // The CHECK_DSR_AND_FIFO macro may be used to invoke the CheckPort2 function,
  227. // without having to specify the mask and value components twice.
  228. // CHECK_DSR_AND_FIFO does quick tests of the DSR and ECR ports first.
  229. // If the peripheral has already responded with either of the
  230. // desired values, CheckPort2 need not be called.
  231. ////////////////////////////////////////////////////////////////////////////////
  232. #endif // 0
  233. #if 0 // use parport's util.h versions
  234. #define CHECK_DSR_WITH_FIFO( addr, b7, b6, b5, b4, b3, ecr_mask, ecr_value, msTime ) \
  235. ( TEST_DSR( P5ReadPortUchar( addr + OFFSET_DSR ), b7, b6, b5, b4, b3 ) ? TRUE : \
  236. CheckTwoPorts( addr + OFFSET_DSR, \
  237. DSR_TEST_MASK( b7, b6, b5, b4, b3 ), \
  238. DSR_TEST_VALUE( b7, b6, b5, b4, b3 ), \
  239. addr + ECR_OFFSET, \
  240. ecr_mask, \
  241. ecr_value, \
  242. msTime) )
  243. #endif // 0
  244. //////////////////////////////////////////////////////////////////////////////
  245. // The following defines and macros may be used to set, test, and
  246. // update the Device Control Register (DCR).
  247. //////////////////////////////////////////////////////////////////////////////
  248. // The DCR_AND_MASK macro generates a byte constant that is used by
  249. // the UPDATE_DCR macro.
  250. #if (1 == DVRH_USE_FAST_MACROS)
  251. #define DCR_AND_MASK(b5,b4,b3,b2,b1,b0) \
  252. ((UCHAR)((b5==DONT_CARE? BIT_5_SET:(b5==ACTIVE? BIT_5_SET: 0)) | \
  253. (b4==DONT_CARE? BIT_4_SET:(b4==ACTIVE? BIT_4_SET: 0)) | \
  254. (b3==DONT_CARE? BIT_3_SET:(b3==ACTIVE? 0: BIT_3_SET)) | \
  255. (b2==DONT_CARE? BIT_2_SET:(b2==ACTIVE? BIT_2_SET: 0)) | \
  256. (b1==DONT_CARE? BIT_1_SET:(b1==ACTIVE? 0: BIT_1_SET)) | \
  257. (b0==DONT_CARE? BIT_0_SET:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  258. #else
  259. #define DCR_AND_MASK(b5,b4,b3,b2,b1,b0) \
  260. ((UCHAR)(((b5==DONT_CARE?1:(b5==ACTIVE?1:0))<<BIT_5) | \
  261. ((b4==DONT_CARE?1:(b4==ACTIVE?1:0))<<BIT_4) | \
  262. ((b3==DONT_CARE?1:(b3==ACTIVE?0:1))<<BIT_3) | \
  263. ((b2==DONT_CARE?1:(b2==ACTIVE?1:0))<<BIT_2) | \
  264. ((b1==DONT_CARE?1:(b1==ACTIVE?0:1))<<BIT_1) | \
  265. ((b0==DONT_CARE?1:(b0==ACTIVE?0:1))<<BIT_0) ) )
  266. #endif
  267. // The DCR_OR_MASK macro generates a byte constant that is used by
  268. // the UPDATE_DCR macro.
  269. #if (1 == DVRH_USE_FAST_MACROS)
  270. #define DCR_OR_MASK(b5,b4,b3,b2,b1,b0) \
  271. ((UCHAR)((b5==DONT_CARE? 0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  272. (b4==DONT_CARE? 0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  273. (b3==DONT_CARE? 0:(b3==ACTIVE? 0: BIT_3_SET)) | \
  274. (b2==DONT_CARE? 0:(b2==ACTIVE? BIT_2_SET: 0)) | \
  275. (b1==DONT_CARE? 0:(b1==ACTIVE? 0: BIT_1_SET)) | \
  276. (b0==DONT_CARE? 0:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  277. #else
  278. #define DCR_OR_MASK(b5,b4,b3,b2,b1,b0) \
  279. ((UCHAR)(((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  280. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  281. ((b3==DONT_CARE?0:(b3==ACTIVE?0:1))<<BIT_3) | \
  282. ((b2==DONT_CARE?0:(b2==ACTIVE?1:0))<<BIT_2) | \
  283. ((b1==DONT_CARE?0:(b1==ACTIVE?0:1))<<BIT_1) | \
  284. ((b0==DONT_CARE?0:(b0==ACTIVE?0:1))<<BIT_0) ) )
  285. #endif
  286. // The UPDATE_DCR macro generates provides a selective update of specific bits
  287. // in the DCR. Any bit positions specified as DONT_CARE will be left
  288. // unchanged. The macro accounts for the hardware inversion of
  289. // certain signals.
  290. #define UPDATE_DCR(registerValue,b5,b4,b3,b2,b1,b0) \
  291. ((UCHAR)(((registerValue) & DCR_AND_MASK(b5,b4,b3,b2,b1,b0)) | DCR_OR_MASK(b5,b4,b3,b2,b1,b0)))
  292. // The DCR_TEST_MASK macro generates a byte constant which may be used
  293. // to mask of DCR bits that we don't care about
  294. #if (1 == DVRH_USE_FAST_MACROS)
  295. #define DCR_TEST_MASK(b5,b4,b3,b2,b1,b0) \
  296. ((UCHAR)((b5==DONT_CARE?0:BIT_5_SET) | \
  297. (b4==DONT_CARE?0:BIT_4_SET) | \
  298. (b3==DONT_CARE?0:BIT_3_SET) | \
  299. (b2==DONT_CARE?0:BIT_2_SET) | \
  300. (b1==DONT_CARE?0:BIT_1_SET) | \
  301. (b0==DONT_CARE?0:BIT_0_SET) ) )
  302. #else
  303. #define DCR_TEST_MASK(b5,b4,b3,b2,b1,b0) \
  304. ((UCHAR)( ((b5==DONT_CARE?0:1)<<BIT_5) | \
  305. ((b4==DONT_CARE?0:1)<<BIT_4) | \
  306. ((b3==DONT_CARE?0:1)<<BIT_3) | \
  307. ((b2==DONT_CARE?0:1)<<BIT_2) | \
  308. ((b1==DONT_CARE?0:1)<<BIT_1) | \
  309. ((b0==DONT_CARE?0:1)<<BIT_0) ) )
  310. #endif
  311. // The DCR_TEST_VALUE macro generates a byte constant that may be used
  312. // to compare against a masked DCR value. This macro takes into
  313. // account which signals are inverted by hardware before driving the
  314. // signal line.
  315. #if (1 == DVRH_USE_FAST_MACROS)
  316. #define DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0) \
  317. ((UCHAR)((b5==DONT_CARE?0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  318. (b4==DONT_CARE?0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  319. (b3==DONT_CARE?0:(b3==ACTIVE? 0: BIT_3_SET)) | \
  320. (b2==DONT_CARE?0:(b2==ACTIVE? BIT_2_SET: 0)) | \
  321. (b1==DONT_CARE?0:(b1==ACTIVE? 0: BIT_1_SET)) | \
  322. (b0==DONT_CARE?0:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  323. #else
  324. #define DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0) \
  325. ((UCHAR)(((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  326. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  327. ((b3==DONT_CARE?0:(b3==ACTIVE?0:1))<<BIT_3) | \
  328. ((b2==DONT_CARE?0:(b2==ACTIVE?1:0))<<BIT_2) | \
  329. ((b1==DONT_CARE?0:(b1==ACTIVE?0:1))<<BIT_1) | \
  330. ((b0==DONT_CARE?0:(b0==ACTIVE?0:1))<<BIT_0) ) )
  331. #endif
  332. // The TEST_DCR macro may be used to generate a boolean result that is
  333. // TRUE if the DCR value matches the specified signal levels and FALSE
  334. // otherwise.
  335. #define TEST_DCR(registerValue,b5,b4,b3,b2,b1,b0) \
  336. (((registerValue) & DCR_TEST_MASK(b5,b4,b3,b2,b1,b0)) == DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0))
  337. // mask all but AckDataReq, XFlag, and nDataAvail to validate if it is still NIBBLE mode
  338. // 00111000b
  339. //#define DSR_NIBBLE_VALIDATION (0x38)
  340. #define DSR_NIBBLE_VALIDATION (0x30)
  341. // AckDataReq high, XFlag low, nDataAvail high
  342. // 00101000b
  343. //#define DSR_NIBBLE_TEST_RESULT (0x28)
  344. #define DSR_NIBBLE_TEST_RESULT (0x20)
  345. // mask all but AckDataReq, XFlag, and nDataAvail to validate if it is still BYTE mode
  346. // 00111000b
  347. #define DSR_BYTE_VALIDATION (0x38)
  348. // AckDataReq high, XFlag high, nDataAvail high
  349. // 00111000b
  350. #define DSR_BYTE_TEST_RESULT (0x38)
  351. #define DVRH_LOGIC_ANALYZER_START(CNT) \
  352. int DVRH_temp; \
  353. int DVRH_max = CNT; \
  354. int DVRH_cnt = 0; \
  355. UCHAR DVRH_dsr; \
  356. UCHAR DVRH_Statedsr[CNT]; \
  357. LARGE_INTEGER DVRH_Statetime[CNT];
  358. #define DVRH_LOGIC_ANALYZER_READ_TIMER(DSR) \
  359. DVRH_dsr = P5ReadPortUchar(DSR); \
  360. KeQuerySystemTime(&DVRH_Statetime[DVRH_cnt]); \
  361. DVRH_Statedsr[DVRH_cnt++] = DVRH_dsr;
  362. #define DVRH_LOGIC_ANALYZER_READ_STATE(DSR) \
  363. DVRH_dsr = P5ReadPortUchar(DSR); \
  364. KeQuerySystemTime(&DVRH_Statetime[DVRH_cnt]); \
  365. DVRH_Statedsr[DVRH_cnt ? ((DVRH_dsr != DVRH_Statedsr[DVRH_cnt-1]) ? DVRH_cnt++ : DVRH_cnt) : 0] = DVRH_dsr;
  366. #define DVRH_LOGIC_ANALYZER_END \
  367. KdPrint("0. %10u-%10u dsr [%x]\n", \
  368. DVRH_Statetime[0].HighPart, \
  369. DVRH_Statetime[0].LowPart/10, \
  370. DVRH_Statedsr[0]); \
  371. for (DVRH_temp=1; DVRH_temp<DVRH_cnt; DVRH_temp++) \
  372. { \
  373. KdPrint("%d. %10u-%10u diff [%10u]us dsr [%x]\n", \
  374. DVRH_temp, \
  375. DVRH_Statetime[DVRH_temp].HighPart, \
  376. DVRH_Statetime[DVRH_temp].LowPart/10, \
  377. ((DVRH_Statetime[DVRH_temp].LowPart/10) - (DVRH_Statetime[DVRH_temp-1].LowPart/10)), \
  378. DVRH_Statedsr[DVRH_temp]); \
  379. }
  380. void BusReset(
  381. IN PUCHAR DCRController
  382. );
  383. BOOLEAN CheckPort(IN PUCHAR offset_Controller,
  384. IN UCHAR dsrMask,
  385. IN UCHAR dsrValue,
  386. IN USHORT msTimeDelay);
  387. BOOLEAN
  388. CheckTwoPorts(
  389. PUCHAR pPortAddr1,
  390. UCHAR bMask1,
  391. UCHAR bValue1,
  392. PUCHAR pPortAddr2,
  393. UCHAR bMask2,
  394. UCHAR bValue2,
  395. USHORT msTimeDelay
  396. );
  397. #endif // _PC_UTIL_