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.

150 lines
5.8 KiB

  1. //==========================================================================;
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. // PURPOSE.
  7. //
  8. // Copyright (c) 1992 - 1996 Microsoft Corporation. All Rights Reserved.
  9. //
  10. // I2CSCRPT.H
  11. // I2CScript class definitions.
  12. // Main Include Module.
  13. //==========================================================================;
  14. #ifndef _I2CSCRPT_H_
  15. #define _I2CSCRPT_H_
  16. //#include "i2c.h"
  17. #include "i2cgpio.h"
  18. #define I2CSCRIPT_LENGTH_MAXIMUM 100
  19. #define I2C_FIXED_CLOCK_RATE 10000
  20. // The I2CScript is build from the following primitives
  21. typedef struct tagI2CScriptPrimitive
  22. {
  23. BYTE byData; // Data to be used in the I2C operation
  24. BYTE byORData; // Data to be used for a logical OR operation
  25. BYTE byANDData; // Data to be used for a logical AND operation
  26. BYTE byFlags; // implementation specific internal Script flags for I2C operation
  27. ULONG ulProviderFlags; // I2CProvider specific flags
  28. ULONG ulCommand; // I2CProvider specific command
  29. } I2CScriptPrimitive, * PI2CScriptPrimitive;
  30. typedef struct
  31. {
  32. UCHAR uchModifyORValue;
  33. UCHAR uchModifyANDValue;
  34. } I2C_MODIFY_VALUES, * PI2C_MODIFY_VALUES;
  35. // New I2CScript control structure - extension to the old I2C access structure
  36. typedef struct tagI2CPacket
  37. {
  38. UCHAR uchChipAddress; // I2C Address
  39. UCHAR uchI2CResult; // valid in synchronous operation only
  40. USHORT cbWriteCount; // bytes to write ( included SubAddress, if exist)
  41. USHORT cbReadCount; // bytes to read ( usually one)
  42. USHORT usFlags; // describes the desired operation
  43. PUCHAR puchWriteBuffer; // buffer to write
  44. PUCHAR puchReadBuffer; // buffer to read
  45. UCHAR uchORValue; // applied only in Read-Modify-Write cycle
  46. UCHAR uchANDValue; // applied only in Read-Modify-Write cycle
  47. USHORT usReserved; //
  48. } I2CPacket, * PI2CPacket;
  49. // possible flags applied to usFlags
  50. #define I2COPERATION_READ 0x0001 // might not be needed - use bcReadCount
  51. #define I2COPERATION_WRITE 0x0002 // might be not needed - use bcReadCount
  52. #define I2COPERATION_READWRITE 0x0004
  53. #define I2COPERATION_RANDOMACCESS 0x0100 // to indicate 16 bits emulation to provide
  54. // built-in support for ITT decoder and ST24 series
  55. // of I2C driven EEPROM
  56. extern "C"
  57. {
  58. typedef VOID (__stdcall * PHWCompletionRoutine)( IN PIRP pIrp);
  59. }
  60. class CI2CScript
  61. {
  62. public:
  63. CI2CScript ( PDEVICE_OBJECT pDeviceObject, NTSTATUS * pStatus);
  64. // PVOID operator new ( UINT size_t, PVOID pAllocation);
  65. // Attributes
  66. public:
  67. private:
  68. // I2C Provider related
  69. I2CINTERFACE m_i2cProviderInterface;
  70. PDEVICE_OBJECT m_pdoDriver;
  71. ULONG m_ulI2CAccessClockRate;
  72. DWORD m_dwI2CAccessKey;
  73. LARGE_INTEGER m_liOperationStartTime;
  74. // I2CScript management related
  75. BOOL m_bExecutionInProcess;
  76. UINT m_nExecutionIndex;
  77. UINT m_nCompletionIndex;
  78. UINT m_nScriptLength;
  79. PHWCompletionRoutine m_pfnReturnWhenDone;
  80. I2CScriptPrimitive m_i2cScript[I2CSCRIPT_LENGTH_MAXIMUM];
  81. // Implementation
  82. public:
  83. BOOL LockI2CProviderEx ( void);
  84. BOOL ReleaseI2CProvider ( void);
  85. BOOL ExecuteI2CPacket ( IN OUT PI2CPacket);
  86. BOOL PerformI2CPacketOperation ( IN OUT PI2CPacket pI2CPacket);
  87. BOOL AppendToScript ( IN PI2CPacket);
  88. void ClearScript ( void);
  89. BOOL ExecuteScript ( IN PIRP pIrp,
  90. IN PHWCompletionRoutine pfnScriptCompletion);
  91. void InterpreterScript ( void);
  92. UINT GetScriptResults ( PUINT puiReadCount, PUCHAR puchReadBuffer);
  93. BOOL CombinedSeq(UCHAR addr, UCHAR seqWr[], USHORT lenWr, UCHAR seqRd[], USHORT lenRd);
  94. BOOL ReadSeq(UCHAR addr, UCHAR *p_seq, USHORT len) ;
  95. BOOL WriteSeq(UCHAR addr, UCHAR *p_seq, USHORT len) ;
  96. private:
  97. BOOL LockI2CProvider ( void);
  98. UINT AccessI2CProvider ( PDEVICE_OBJECT pdoClient, PI2CControl pi2cAccessBlock);
  99. BOOL InitializeAttachI2CProvider ( I2CINTERFACE * pI2CInterface, PDEVICE_OBJECT pDeviceObject);
  100. BOOL LocateAttachI2CProvider ( I2CINTERFACE * pI2CInterface, PDEVICE_OBJECT pDeviceObject, int nIrpMajorFunction);
  101. UINT CheckI2CScriptPacket ( IN PI2CPacket pI2CPacket);
  102. BOOL GetI2CProviderLockStatus ( void);
  103. BOOL CheckInterface(UCHAR addr) ;
  104. };
  105. extern "C"
  106. NTSTATUS I2CScriptIoSynchCompletionRoutine ( IN PDEVICE_OBJECT pDeviceObject,
  107. IN PIRP pIrp,
  108. IN PVOID Event);
  109. // errors definition for internal use
  110. #define I2CSCRIPT_NOERROR 0x00
  111. #define I2CSCRIPT_ERROR_NOPROVIDER 0x01
  112. #define I2CSCRIPT_ERROR_NODATA 0x02
  113. #define I2CSCRIPT_ERROR_NOBUFFER 0x03
  114. #define I2CSCRIPT_ERROR_READWRITE 0x04
  115. #define I2CSCRIPT_ERROR_OVERFLOW 0x05
  116. // time definitions
  117. #define I2CSCRIPT_DELAY_OPENPROVIDER -2000
  118. #define I2CSCRIPT_DELAY_GETPROVIDERSTATUS -2000
  119. // time limits
  120. #define I2CSCRIPT_TIMELIMIT_OPENPROVIDER 50000000 // 5 seconds in 100 nsec.
  121. #endif // _I2CSCRPT_H_