Source code of Windows XP (NT5)
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.

273 lines
12 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1993 - 1999
  3. Module Name:
  4. util.h
  5. Abstract:
  6. This module contains utility code used by other 1284 modules.
  7. Author:
  8. Robbie Harris (Hewlett-Packard) 20-May-1998
  9. Environment:
  10. Kernel mode
  11. Revision History :
  12. --*/
  13. #ifndef _UTIL_
  14. #define _UTIL_
  15. // Standard Maximum Timing values
  16. #define IEEE_MAXTIME_TL 35 // Max time Tl from the IEEE spec
  17. #define DEFAULT_RECEIVE_TIMEOUT 330
  18. #define ParEnterCriticalSection(Xtension) xTension->bCriticalSection = TRUE
  19. #define ParExitCriticalSection(Xtension) xTension->bCriticalSection = FALSE
  20. // The following macros may be used to test the contents of the Device
  21. // Status Regisger (DSR). These macros account for the hardware
  22. // inversion of the nBusy (aka PtrBusy, PeriphAck) signal.
  23. //////////////////////////////////////////////////////////////////////////////
  24. #if (1 == DVRH_USE_FAST_MACROS)
  25. #define DSR_TEST_MASK(b7,b6,b5,b4,b3) \
  26. ((UCHAR)(b7==DONT_CARE? 0: BIT_7_SET) | \
  27. (b6==DONT_CARE? 0: BIT_6_SET) | \
  28. (b5==DONT_CARE? 0: BIT_5_SET) | \
  29. (b4==DONT_CARE? 0: BIT_4_SET) | \
  30. (b3==DONT_CARE? 0: BIT_3_SET) )
  31. #else
  32. #define DSR_TEST_MASK(b7,b6,b5,b4,b3) \
  33. ((UCHAR)((b7==DONT_CARE?0:1)<<BIT_7) | \
  34. ((b6==DONT_CARE?0:1)<<BIT_6) | \
  35. ((b5==DONT_CARE?0:1)<<BIT_5) | \
  36. ((b4==DONT_CARE?0:1)<<BIT_4) | \
  37. ((b3==DONT_CARE?0:1)<<BIT_3) )
  38. #endif
  39. #if (1 == DVRH_USE_FAST_MACROS)
  40. #define DSR_TEST_VALUE(b7,b6,b5,b4,b3) \
  41. ((UCHAR) ((b7==DONT_CARE?0:(b7==ACTIVE?0 : BIT_7_SET)) | \
  42. (b6==DONT_CARE?0:(b6==ACTIVE? BIT_6_SET: 0)) | \
  43. (b5==DONT_CARE?0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  44. (b4==DONT_CARE?0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  45. (b3==DONT_CARE?0:(b3==ACTIVE? BIT_3_SET: 0)) ) )
  46. #else
  47. #define DSR_TEST_VALUE(b7,b6,b5,b4,b3) \
  48. ((UCHAR) (((b7==DONT_CARE?0:(b7==ACTIVE?0:1))<<BIT_7) | \
  49. ((b6==DONT_CARE?0:(b6==ACTIVE?1:0))<<BIT_6) | \
  50. ((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  51. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  52. ((b3==DONT_CARE?0:(b3==ACTIVE?1:0))<<BIT_3) ) )
  53. #endif
  54. #define TEST_DSR(registerValue,b7,b6,b5,b4,b3) \
  55. (((registerValue) & DSR_TEST_MASK(b7,b6,b5,b4,b3)) == DSR_TEST_VALUE(b7,b6,b5,b4,b3))
  56. #define CHECK_DSR( addr, b7, b6, b5, b4, b3, msTime ) \
  57. (TEST_DSR(READ_PORT_UCHAR(addr + OFFSET_DSR), b7, b6, b5, b4, b3 ) ? TRUE : \
  58. CheckPort( addr + OFFSET_DSR, \
  59. DSR_TEST_MASK( b7, b6, b5, b4, b3 ), \
  60. DSR_TEST_VALUE( b7, b6, b5, b4, b3 ), \
  61. msTime ) )
  62. ////////////////////////////////////////////////////////////////////////////////
  63. // The CHECK_DSR_AND_FIFO macro may be used to invoke the CheckPort2 function,
  64. // without having to specify the mask and value components twice.
  65. // CHECK_DSR_AND_FIFO does quick tests of the DSR and ECR ports first.
  66. // If the peripheral has already responded with either of the
  67. // desired values, CheckPort2 need not be called.
  68. ////////////////////////////////////////////////////////////////////////////////
  69. #define CHECK_DSR_WITH_FIFO( addr, b7, b6, b5, b4, b3, ecr_mask, ecr_value, msTime ) \
  70. ( TEST_DSR( READ_PORT_UCHAR( addr + OFFSET_DSR ), b7, b6, b5, b4, b3 ) ? TRUE : \
  71. CheckTwoPorts( addr + OFFSET_DSR, \
  72. DSR_TEST_MASK( b7, b6, b5, b4, b3 ), \
  73. DSR_TEST_VALUE( b7, b6, b5, b4, b3 ), \
  74. addr + ECR_OFFSET, \
  75. ecr_mask, \
  76. ecr_value, \
  77. msTime) )
  78. //////////////////////////////////////////////////////////////////////////////
  79. // The following defines and macros may be used to set, test, and
  80. // update the Device Control Register (DCR).
  81. //////////////////////////////////////////////////////////////////////////////
  82. // The DCR_AND_MASK macro generates a byte constant that is used by
  83. // the UPDATE_DCR macro.
  84. #if (1 == DVRH_USE_FAST_MACROS)
  85. #define DCR_AND_MASK(b5,b4,b3,b2,b1,b0) \
  86. ((UCHAR)((b5==DONT_CARE? BIT_5_SET:(b5==ACTIVE? BIT_5_SET: 0)) | \
  87. (b4==DONT_CARE? BIT_4_SET:(b4==ACTIVE? BIT_4_SET: 0)) | \
  88. (b3==DONT_CARE? BIT_3_SET:(b3==ACTIVE? 0: BIT_3_SET)) | \
  89. (b2==DONT_CARE? BIT_2_SET:(b2==ACTIVE? BIT_2_SET: 0)) | \
  90. (b1==DONT_CARE? BIT_1_SET:(b1==ACTIVE? 0: BIT_1_SET)) | \
  91. (b0==DONT_CARE? BIT_0_SET:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  92. #else
  93. #define DCR_AND_MASK(b5,b4,b3,b2,b1,b0) \
  94. ((UCHAR)(((b5==DONT_CARE?1:(b5==ACTIVE?1:0))<<BIT_5) | \
  95. ((b4==DONT_CARE?1:(b4==ACTIVE?1:0))<<BIT_4) | \
  96. ((b3==DONT_CARE?1:(b3==ACTIVE?0:1))<<BIT_3) | \
  97. ((b2==DONT_CARE?1:(b2==ACTIVE?1:0))<<BIT_2) | \
  98. ((b1==DONT_CARE?1:(b1==ACTIVE?0:1))<<BIT_1) | \
  99. ((b0==DONT_CARE?1:(b0==ACTIVE?0:1))<<BIT_0) ) )
  100. #endif
  101. // The DCR_OR_MASK macro generates a byte constant that is used by
  102. // the UPDATE_DCR macro.
  103. #if (1 == DVRH_USE_FAST_MACROS)
  104. #define DCR_OR_MASK(b5,b4,b3,b2,b1,b0) \
  105. ((UCHAR)((b5==DONT_CARE? 0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  106. (b4==DONT_CARE? 0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  107. (b3==DONT_CARE? 0:(b3==ACTIVE? 0: BIT_3_SET)) | \
  108. (b2==DONT_CARE? 0:(b2==ACTIVE? BIT_2_SET: 0)) | \
  109. (b1==DONT_CARE? 0:(b1==ACTIVE? 0: BIT_1_SET)) | \
  110. (b0==DONT_CARE? 0:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  111. #else
  112. #define DCR_OR_MASK(b5,b4,b3,b2,b1,b0) \
  113. ((UCHAR)(((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  114. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  115. ((b3==DONT_CARE?0:(b3==ACTIVE?0:1))<<BIT_3) | \
  116. ((b2==DONT_CARE?0:(b2==ACTIVE?1:0))<<BIT_2) | \
  117. ((b1==DONT_CARE?0:(b1==ACTIVE?0:1))<<BIT_1) | \
  118. ((b0==DONT_CARE?0:(b0==ACTIVE?0:1))<<BIT_0) ) )
  119. #endif
  120. // The UPDATE_DCR macro generates provides a selective update of specific bits
  121. // in the DCR. Any bit positions specified as DONT_CARE will be left
  122. // unchanged. The macro accounts for the hardware inversion of
  123. // certain signals.
  124. #define UPDATE_DCR(registerValue,b5,b4,b3,b2,b1,b0) \
  125. ((UCHAR)(((registerValue) & DCR_AND_MASK(b5,b4,b3,b2,b1,b0)) | DCR_OR_MASK(b5,b4,b3,b2,b1,b0)))
  126. // The DCR_TEST_MASK macro generates a byte constant which may be used
  127. // to mask of DCR bits that we don't care about
  128. #if (1 == DVRH_USE_FAST_MACROS)
  129. #define DCR_TEST_MASK(b5,b4,b3,b2,b1,b0) \
  130. ((UCHAR)((b5==DONT_CARE?0:BIT_5_SET) | \
  131. (b4==DONT_CARE?0:BIT_4_SET) | \
  132. (b3==DONT_CARE?0:BIT_3_SET) | \
  133. (b2==DONT_CARE?0:BIT_2_SET) | \
  134. (b1==DONT_CARE?0:BIT_1_SET) | \
  135. (b0==DONT_CARE?0:BIT_0_SET) ) )
  136. #else
  137. #define DCR_TEST_MASK(b5,b4,b3,b2,b1,b0) \
  138. ((UCHAR)( ((b5==DONT_CARE?0:1)<<BIT_5) | \
  139. ((b4==DONT_CARE?0:1)<<BIT_4) | \
  140. ((b3==DONT_CARE?0:1)<<BIT_3) | \
  141. ((b2==DONT_CARE?0:1)<<BIT_2) | \
  142. ((b1==DONT_CARE?0:1)<<BIT_1) | \
  143. ((b0==DONT_CARE?0:1)<<BIT_0) ) )
  144. #endif
  145. // The DCR_TEST_VALUE macro generates a byte constant that may be used
  146. // to compare against a masked DCR value. This macro takes into
  147. // account which signals are inverted by hardware before driving the
  148. // signal line.
  149. #if (1 == DVRH_USE_FAST_MACROS)
  150. #define DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0) \
  151. ((UCHAR)((b5==DONT_CARE?0:(b5==ACTIVE? BIT_5_SET: 0)) | \
  152. (b4==DONT_CARE?0:(b4==ACTIVE? BIT_4_SET: 0)) | \
  153. (b3==DONT_CARE?0:(b3==ACTIVE? 0: BIT_3_SET)) | \
  154. (b2==DONT_CARE?0:(b2==ACTIVE? BIT_2_SET: 0)) | \
  155. (b1==DONT_CARE?0:(b1==ACTIVE? 0: BIT_1_SET)) | \
  156. (b0==DONT_CARE?0:(b0==ACTIVE? 0: BIT_0_SET)) ) )
  157. #else
  158. #define DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0) \
  159. ((UCHAR)(((b5==DONT_CARE?0:(b5==ACTIVE?1:0))<<BIT_5) | \
  160. ((b4==DONT_CARE?0:(b4==ACTIVE?1:0))<<BIT_4) | \
  161. ((b3==DONT_CARE?0:(b3==ACTIVE?0:1))<<BIT_3) | \
  162. ((b2==DONT_CARE?0:(b2==ACTIVE?1:0))<<BIT_2) | \
  163. ((b1==DONT_CARE?0:(b1==ACTIVE?0:1))<<BIT_1) | \
  164. ((b0==DONT_CARE?0:(b0==ACTIVE?0:1))<<BIT_0) ) )
  165. #endif
  166. // The TEST_DCR macro may be used to generate a boolean result that is
  167. // TRUE if the DCR value matches the specified signal levels and FALSE
  168. // otherwise.
  169. #define TEST_DCR(registerValue,b5,b4,b3,b2,b1,b0) \
  170. (((registerValue) & DCR_TEST_MASK(b5,b4,b3,b2,b1,b0)) == DCR_TEST_VALUE(b5,b4,b3,b2,b1,b0))
  171. // mask all but AckDataReq, XFlag, and nDataAvail to validate if it is still NIBBLE mode
  172. // 00111000b
  173. //#define DSR_NIBBLE_VALIDATION (0x38)
  174. #define DSR_NIBBLE_VALIDATION (0x30)
  175. // AckDataReq high, XFlag low, nDataAvail high
  176. // 00101000b
  177. //#define DSR_NIBBLE_TEST_RESULT (0x28)
  178. #define DSR_NIBBLE_TEST_RESULT (0x20)
  179. // mask all but AckDataReq, XFlag, and nDataAvail to validate if it is still BYTE mode
  180. // 00111000b
  181. #define DSR_BYTE_VALIDATION (0x38)
  182. // AckDataReq high, XFlag high, nDataAvail high
  183. // 00111000b
  184. #define DSR_BYTE_TEST_RESULT (0x38)
  185. #define DVRH_LOGIC_ANALYZER_START(CNT) \
  186. int DVRH_temp; \
  187. int DVRH_max = CNT; \
  188. int DVRH_cnt = 0; \
  189. UCHAR DVRH_dsr; \
  190. UCHAR DVRH_Statedsr[CNT]; \
  191. LARGE_INTEGER DVRH_Statetime[CNT];
  192. #define DVRH_LOGIC_ANALYZER_READ_TIMER(DSR) \
  193. DVRH_dsr = READ_PORT_UCHAR(DSR); \
  194. KeQuerySystemTime(&DVRH_Statetime[DVRH_cnt]); \
  195. DVRH_Statedsr[DVRH_cnt++] = DVRH_dsr;
  196. #define DVRH_LOGIC_ANALYZER_READ_STATE(DSR) \
  197. DVRH_dsr = READ_PORT_UCHAR(DSR); \
  198. KeQuerySystemTime(&DVRH_Statetime[DVRH_cnt]); \
  199. DVRH_Statedsr[DVRH_cnt ? ((DVRH_dsr != DVRH_Statedsr[DVRH_cnt-1]) ? DVRH_cnt++ : DVRH_cnt) : 0] = DVRH_dsr;
  200. #define DVRH_LOGIC_ANALYZER_END \
  201. KdPrint("0. %10u-%10u dsr [%x]\n", \
  202. DVRH_Statetime[0].HighPart, \
  203. DVRH_Statetime[0].LowPart/10, \
  204. DVRH_Statedsr[0]); \
  205. for (DVRH_temp=1; DVRH_temp<DVRH_cnt; DVRH_temp++) \
  206. { \
  207. KdPrint("%d. %10u-%10u diff [%10u]us dsr [%x]\n", \
  208. DVRH_temp, \
  209. DVRH_Statetime[DVRH_temp].HighPart, \
  210. DVRH_Statetime[DVRH_temp].LowPart/10, \
  211. ((DVRH_Statetime[DVRH_temp].LowPart/10) - (DVRH_Statetime[DVRH_temp-1].LowPart/10)), \
  212. DVRH_Statedsr[DVRH_temp]); \
  213. }
  214. void BusReset(
  215. IN PUCHAR DCRController
  216. );
  217. BOOLEAN CheckPort(IN PUCHAR offset_Controller,
  218. IN UCHAR dsrMask,
  219. IN UCHAR dsrValue,
  220. IN USHORT msTimeDelay);
  221. BOOLEAN
  222. CheckTwoPorts(
  223. PUCHAR pPortAddr1,
  224. UCHAR bMask1,
  225. UCHAR bValue1,
  226. PUCHAR pPortAddr2,
  227. UCHAR bMask2,
  228. UCHAR bValue2,
  229. USHORT msTimeDelay
  230. );
  231. #if (1 == DVRH_DELAY_THEORY)
  232. void DVRH_Diagnostic_Delay();
  233. #endif
  234. #endif