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.

104 lines
5.1 KiB

  1. /***************************************************************************
  2. Name : COMDEVI.H
  3. Comment : Controls Comm interface used by Fax Modem Driver. There are
  4. 4 choices.
  5. (a) If UCOM is defined, it uses the WIN16 Comm API as exported
  6. by USER.EXE (though eventually it gets to COMM.DRV)
  7. (b) If UCOM is not defined and VC is defined, it uses the
  8. COMM.DRV-like interface exported by DLLSCHED.DLL (which
  9. merely serves as a front for VCOMM.386)
  10. (c) If neither UCOM nor VC are defined, it uses Win3.1 COMM.DRV
  11. export directly.
  12. (d) If WIN32 is defined (neither UCOM or VC should be defined at
  13. the same time), it uses the WIN32 Comm API
  14. Functions: (see Prototypes just below)
  15. Revision Log
  16. Date Name Description
  17. -------- ----- ---------------------------------------------------------
  18. ***************************************************************************/
  19. #pragma optimize("e", off) // "e" is buggy
  20. // must be 8K or less, dues to DEADCOMMTIMEOUT. See fcom.c!!
  21. // maybe not...
  22. // #define COM_INBUFSIZE 16384
  23. // #define COM_OUTBUFSIZE 16384
  24. #define COM_INBUFSIZE 4096
  25. #define COM_OUTBUFSIZE 4096
  26. // #define COM_INBUFSIZE 256
  27. // #define COM_OUTBUFSIZE 256
  28. // #define COM_INBUFSIZE 1024
  29. // #define COM_OUTBUFSIZE 1024
  30. #define BETWEENCALL_THRESH 50
  31. #ifdef DEBUG
  32. # define CALLTHRESH_CONST 50
  33. # define CALLTHRESH_PERBYTE 1
  34. # define BEFORECALL static DWORD t1, t2; t1=GetTickCount();
  35. # define INTERCALL(sz)
  36. /*
  37. # define INTERCALL(sz) if((t1-t2) > BETWEENCALL_THRESH)\
  38. ERRMSG(("!!!Inter API %s delay %ld!!!\r\n", (LPSTR)(sz), (t1-t2)));
  39. */
  40. # define AFTERCALL(sz,n) \
  41. t2=GetTickCount();\
  42. if((t2-t1) > (CALLTHRESH_CONST+((DWORD)n)*CALLTHRESH_PERBYTE)) \
  43. ERRMSG(("!!!API %s took %ld!!!\r\n", (LPSTR)(sz), (t2-t1)));
  44. #else
  45. # define BEFORECALL
  46. # define AFTERCALL
  47. # define INTERCALL
  48. #endif
  49. #if INVALID_HANDLE_VALUE >= 0 // must be <= 0
  50. #error INVALID_HANDLE_VALUE is >=0. This won't work....
  51. #endif
  52. #define My2ndOpenComm(sz, ph) \
  53. { BEFORECALL; \
  54. if((*((LPHANDLE)(ph)) = CreateFile((LPCTSTR)(sz), GENERIC_READ|GENERIC_WRITE, \
  55. 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL)) != INVALID_HANDLE_VALUE) \
  56. { \
  57. if(!SetupComm(*((LPHANDLE)(ph)), COM_INBUFSIZE, COM_OUTBUFSIZE)) \
  58. { \
  59. CloseHandle(*((LPHANDLE)(ph))); \
  60. *((LPHANDLE)(ph)) = INVALID_HANDLE_VALUE; \
  61. } \
  62. } \
  63. AFTERCALL("Open", 0); \
  64. } \
  65. #define My2ndCloseComm(h, pn) { BEFORECALL; *(pn) = (!CloseHandle((HANDLE)h)); AFTERCALL("Close",0); }
  66. #define MySetCommState(h,pdcb) (!SetCommState((HANDLE)(h), (pdcb)))
  67. #define MyGetCommState(h,pdcb) (!GetCommState((HANDLE)(h), (pdcb)))
  68. #define OVL_CLEAR(lpovl) \
  69. { \
  70. if (lpovl) \
  71. { \
  72. (lpovl)->Internal = (lpovl)->InternalHigh=\
  73. (lpovl)->Offset = (lpovl)->OffsetHigh=0; \
  74. if ((lpovl)->hEvent) ResetEvent((lpovl)->hEvent); \
  75. } \
  76. }
  77. #define MySetCommMask(h,mask) (!SetCommMask((HANDLE)(h), (mask)))
  78. #define MyFlushComm(h,q) (!PurgeComm((HANDLE)h, ((q)==0 ? PURGE_TXCLEAR : PURGE_RXCLEAR)))
  79. #define MySetXON(h) (!EscapeCommFunction((HANDLE)(h), SETXON))