SapGio.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. #ifndef _SAPGIO_H_
  2. #define _SAPGIO_H_
  3. // SapGio.h : header file
  4. //
  5. #include "SapClassBasicDef.h"
  6. // Forward declarations
  7. class SAPCLASSBASIC_CLASS SapGioCallbackInfo;
  8. typedef void (*SapGioCallback)(SapGioCallbackInfo *);
  9. //
  10. // SapGio class declaration
  11. //
  12. class SAPCLASSBASIC_CLASS SapGio : public SapManager
  13. {
  14. public:
  15. // Pin configurations
  16. typedef int PinConfig;
  17. enum _PinConfig
  18. {
  19. PinInput = 1,
  20. PinOutput = 2,
  21. PinTristate = 4
  22. };
  23. // Pin states
  24. enum PinState
  25. {
  26. PinLow = 0,
  27. PinHigh = 1
  28. };
  29. // I/O event types
  30. typedef int EventType;
  31. enum _EventType
  32. {
  33. EventRisingEdge = CORGIO_VAL_EVENT_TYPE_RISING_EDGE,
  34. EventFallingEdge = CORGIO_VAL_EVENT_TYPE_FALLING_EDGE
  35. };
  36. // Various constants
  37. enum MiscValues
  38. {
  39. AllPins = -1,
  40. MaxCallbacks = 8
  41. };
  42. public:
  43. // Constructor/Destructor
  44. SapGio(SapLocation loc = SapLocation::ServerSystem, SapGioCallback pCallback = NULL, void *pContext = NULL);
  45. SapGio(const SapGio &gio);
  46. virtual ~SapGio();
  47. SapGio &operator=(const SapGio &gio);
  48. // Module create/destroy
  49. virtual BOOL Create();
  50. virtual BOOL Destroy();
  51. // Access to implementation
  52. CORHANDLE GetHandle() const { return m_hGio; }
  53. SapLocation GetLocation() const { return m_Location; }
  54. SapGioCallback GetCallback() const { return m_pCallback; }
  55. void *GetContext() const { return m_pContext; }
  56. int GetNumPins() const { return m_NumPins; }
  57. BOOL SetLocation(SapLocation location);
  58. virtual BOOL GetAvailPinConfig(int pinNumber, PinConfig *pAvailPinConfig);
  59. virtual BOOL GetAvailPinConfig(PinConfig *pAvailPinConfig);
  60. virtual BOOL GetPinConfig(int pinNumber, PinConfig *pPinConfig);
  61. virtual BOOL GetPinConfig(PinConfig *pPinConfig);
  62. virtual BOOL SetPinConfig(int pinNumber, PinConfig pinConfig);
  63. virtual BOOL SetPinConfig(PinConfig *pPinConfig);
  64. virtual BOOL GetPinState(int pinNumber, PinState *pPinState);
  65. virtual BOOL GetPinState(PinState *pPinState);
  66. virtual BOOL SetPinState(int pinNumber, PinState pinState);
  67. virtual BOOL SetPinState(int pinMask, PinState *pPinState);
  68. virtual BOOL SetCallbackInfo(SapGioCallback pCallback, void *pContext = NULL);
  69. //
  70. // Direct capability/parameter access
  71. //
  72. virtual BOOL IsCapabilityValid(int cap);
  73. virtual BOOL GetCapability(int cap, void *pValue);
  74. virtual BOOL IsParameterValid(int param);
  75. virtual BOOL GetParameter(int param, void *pValue);
  76. virtual BOOL SetParameter(int param, int value);
  77. virtual BOOL SetParameter(int param, void *pValue);
  78. // Callback management
  79. virtual BOOL EnableCallback(int pinNumber, EventType eventType);
  80. virtual BOOL EnableCallback(int pinMask, EventType *pEventType);
  81. virtual BOOL EnableCallback(EventType eventType);
  82. virtual BOOL DisableCallback(int pinNumber);
  83. virtual BOOL DisableCallback();
  84. // Obsolete methods
  85. #if COR_WIN32 && !COR_WIN64 && !SAPERA_DOT_NET && !defined(__clang__)
  86. virtual BOOL AutoTrigger(SapCounter *pCounter, int startCount, int stopCount, int pinMask, int pinState);
  87. #endif // COR_WIN32
  88. protected:
  89. // Utility methods
  90. void Construct(SapLocation loc, SapGioCallback pCallback, void *pContext);
  91. virtual BOOL SetPinConfig(int pinNumber, PinConfig *pPinConfig);
  92. // Callback management
  93. // Note that we have separate a function for each pin so that we can guarantee
  94. // that each callback will be called for no more than one pin at a time.
  95. static SAPSTATUS CCONV GioCallback0(void *context, UINT32 eventType, UINT32 eventCount)
  96. { return GioCallback(context, (EventType) eventType, eventCount, 0); }
  97. static SAPSTATUS CCONV GioCallback1(void *context, UINT32 eventType, UINT32 eventCount)
  98. { return GioCallback(context, (EventType) eventType, eventCount, 1); }
  99. static SAPSTATUS CCONV GioCallback2(void *context, UINT32 eventType, UINT32 eventCount)
  100. { return GioCallback(context, (EventType) eventType, eventCount, 2); }
  101. static SAPSTATUS CCONV GioCallback3(void *context, UINT32 eventType, UINT32 eventCount)
  102. { return GioCallback(context, (EventType) eventType, eventCount, 3); }
  103. static SAPSTATUS CCONV GioCallback4(void *context, UINT32 eventType, UINT32 eventCount)
  104. { return GioCallback(context, (EventType) eventType, eventCount, 4); }
  105. static SAPSTATUS CCONV GioCallback5(void *context, UINT32 eventType, UINT32 eventCount)
  106. { return GioCallback(context, (EventType) eventType, eventCount, 5); }
  107. static SAPSTATUS CCONV GioCallback6(void *context, UINT32 eventType, UINT32 eventCount)
  108. { return GioCallback(context, (EventType) eventType, eventCount, 6); }
  109. static SAPSTATUS CCONV GioCallback7(void *context, UINT32 eventType, UINT32 eventCount)
  110. { return GioCallback(context, (EventType) eventType, eventCount, 7); }
  111. static SAPSTATUS CCONV GioCallbackAll(void *context, UINT32 eventType, UINT32 eventCount)
  112. { return GioCallback(context, (EventType) eventType, eventCount, AllPins); }
  113. static SAPSTATUS GioCallback(void *context, EventType eventType, UINT32 eventCount, int pinNumber);
  114. //functions for the new callbacks
  115. static SAPSTATUS CCONV GioCallback0Ex(void *context, COREVENTINFO eventInfo)
  116. { return GioCallbackEx(context, eventInfo, 0); }
  117. static SAPSTATUS CCONV GioCallback1Ex(void *context, COREVENTINFO eventInfo)
  118. { return GioCallbackEx(context, eventInfo, 1); }
  119. static SAPSTATUS CCONV GioCallback2Ex(void *context, COREVENTINFO eventInfo)
  120. { return GioCallbackEx(context, eventInfo, 2); }
  121. static SAPSTATUS CCONV GioCallback3Ex(void *context, COREVENTINFO eventInfo)
  122. { return GioCallbackEx(context, eventInfo, 3); }
  123. static SAPSTATUS CCONV GioCallback4Ex(void *context, COREVENTINFO eventInfo)
  124. { return GioCallbackEx(context, eventInfo, 4); }
  125. static SAPSTATUS CCONV GioCallback5Ex(void *context, COREVENTINFO eventInfo)
  126. { return GioCallbackEx(context, eventInfo, 5); }
  127. static SAPSTATUS CCONV GioCallback6Ex(void *context, COREVENTINFO eventInfo)
  128. { return GioCallbackEx(context, eventInfo, 6); }
  129. static SAPSTATUS CCONV GioCallback7Ex(void *context, COREVENTINFO eventInfo)
  130. { return GioCallbackEx(context, eventInfo, 7); }
  131. static SAPSTATUS CCONV GioCallbackAllEx(void *context, COREVENTINFO eventInfo)
  132. { return GioCallbackEx(context, eventInfo, AllPins); }
  133. static SAPSTATUS GioCallbackEx(void *context, COREVENTINFO eventInfo, int pinNumber);
  134. protected:
  135. SapLocation m_Location;
  136. CORGIO m_hGio;
  137. // Parameters and capabilities
  138. int m_NumPins; // Number of I/O pins
  139. PinConfig *m_AvailPinConfig; // Possible configurations for each pin
  140. PinConfig *m_PinConfig; // Current configuration for each pin
  141. int m_DirOutputPrm; // Current CORGIO_PRM_DIR_OUTPUT value
  142. int m_DirTristatePrm; // Current CORGIO_PRM_DIR_TRISTATE value
  143. int m_ReadOnlyCap; // Current CORGIO_CAP_READ_ONLY value
  144. // Callback management
  145. SapGioCallback m_pCallback; // Application callback function
  146. void *m_pContext; // Application context
  147. BOOL m_IsNewCallback; // TRUE if we're using the new callback function
  148. BOOL m_IsCallbackAll; // TRUE if using GioCallbackAll() for all pins
  149. BOOL *m_IsCallbackActive; // Callback status for all pins
  150. static PCORCALLBACK m_CallbackList[MaxCallbacks]; // Callback function table
  151. static PCOREVENTINFOCALLBACK m_CallbackListEx[MaxCallbacks]; // New Callback function table
  152. };
  153. //
  154. // SapGioCallbackInfo class declaration
  155. //
  156. class SAPCLASSBASIC_CLASS SapGioCallbackInfo
  157. {
  158. public:
  159. SapGioCallbackInfo(SapGio *pGio, void *context, SapGio::EventType eventType, int eventCount, int pinNumber)
  160. { m_pGio = pGio; m_Context = context; m_EventType = eventType; m_EventCount = eventCount; m_PinNumber = pinNumber; m_NewCallback = FALSE; }
  161. SapGioCallbackInfo(SapGio *pGio, void *context, COREVENTINFO eventInfo, int pinNumber);
  162. ~SapGioCallbackInfo() {}
  163. SapGio *GetGio() const { return m_pGio; }
  164. void *GetContext() const { return m_Context; }
  165. int GetPinNumber() const { return m_PinNumber; }
  166. COREVENTINFO GetEventInfo() const { return m_EventInfo; }
  167. //Event Count
  168. int GetEventCount() const { return m_EventCount; }
  169. BOOL GetEventCount(int *eventCount);
  170. //Event Type
  171. SapGio::EventType GetEventType() const { return m_EventType; }
  172. BOOL GetEventType(SapGio::EventType *eventType);
  173. //Timestamp
  174. BOOL GetHostTimeStamp(UINT64 *hostTimeStamp);
  175. BOOL GetAuxiliaryTimeStamp(UINT64 *auxTimeStamp);
  176. // Custom Parameters
  177. BOOL GetCustomData(void **customData);
  178. BOOL GetCustomSize(int *customSize);
  179. // Unnamed Parameters
  180. BOOL GetGenericParam0(int *paramValue);
  181. BOOL GetGenericParam1(int *paramValue);
  182. BOOL GetGenericParam2(int *paramValue);
  183. BOOL GetGenericParam3(int *paramValue);
  184. protected:
  185. SapGio *m_pGio;
  186. void *m_Context;
  187. SapGio::EventType m_EventType;
  188. int m_EventCount;
  189. int m_PinNumber;
  190. COREVENTINFO m_EventInfo;
  191. BOOL m_NewCallback;
  192. };
  193. #endif // _SAPGIO_H_