serialmgrold.pp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. {$MACRO ON}
  2. (******************************************************************************
  3. *
  4. * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
  5. * All rights reserved.
  6. *
  7. * File: SerialMgrOld.h
  8. *
  9. * Release: Palm OS SDK 4.0 (63220)
  10. *
  11. * Description:
  12. * Include file for Serial manager
  13. *
  14. * History:
  15. * 2/7/95 Created by Ron Marianetti
  16. * 7/6/95 vmk added serDefaultSettings
  17. * 1/28/98 scl added Serial Port Definitions
  18. *
  19. *****************************************************************************)
  20. unit serialmgrold;
  21. interface
  22. uses palmos, coretraps, libtraps, errorbase, systemmgr;
  23. (********************************************************************
  24. * Serial Manager Errors
  25. * the constant serErrorClass is defined in SystemMgr.h
  26. ********************************************************************)
  27. const
  28. serErrBadParam = serErrorClass or 1;
  29. serErrBadPort = serErrorClass or 2;
  30. serErrNoMem = serErrorClass or 3;
  31. serErrBadConnID = serErrorClass or 4;
  32. serErrTimeOut = serErrorClass or 5;
  33. serErrLineErr = serErrorClass or 6;
  34. serErrAlreadyOpen = serErrorClass or 7;
  35. serErrStillOpen = serErrorClass or 8;
  36. serErrNotOpen = serErrorClass or 9;
  37. serErrNotSupported = serErrorClass or 10; // functionality not supported
  38. (********************************************************************
  39. * Serial Port Definitions
  40. ********************************************************************)
  41. const
  42. serPortDefault = $0000; // Use prefDefSerialPlugIn
  43. serPortLocalHotSync = $8000; // Use physical HotSync port
  44. serPortMaskLocal = $7FFF; // Mask off HotSync "hint" (for SerialMgr)
  45. (********************************************************************
  46. * Serial Settings Descriptor
  47. ********************************************************************)
  48. type
  49. SerSettingsType = record
  50. baudRate: UInt32; // baud rate
  51. flags: UInt32; // miscellaneous settings
  52. ctsTimeout: Int32; // max # of ticks to wait for CTS to become asserted
  53. // before transmitting; used only when
  54. // configured with serSettingsFlagCTSAutoM.
  55. end;
  56. SerSettingsPtr = ^SerSettingsType;
  57. const
  58. serSettingsFlagStopBitsM = $00000001; // mask for stop bits field
  59. serSettingsFlagStopBits1 = $00000000; // 1 stop bits
  60. serSettingsFlagStopBits2 = $00000001; // 2 stop bits
  61. serSettingsFlagParityOnM = $00000002; // mask for parity on
  62. serSettingsFlagParityEvenM = $00000004; // mask for parity even
  63. serSettingsFlagXonXoffM = $00000008; // (NOT IMPLEMENTED) mask for Xon/Xoff flow control
  64. serSettingsFlagRTSAutoM = $00000010; // mask for RTS rcv flow control
  65. serSettingsFlagCTSAutoM = $00000020; // mask for CTS xmit flow control
  66. serSettingsFlagBitsPerCharM = $000000C0; // mask for bits/char
  67. serSettingsFlagBitsPerChar5 = $00000000; // 5 bits/char
  68. serSettingsFlagBitsPerChar6 = $00000040; // 6 bits/char
  69. serSettingsFlagBitsPerChar7 = $00000080; // 7 bits/char
  70. serSettingsFlagBitsPerChar8 = $000000C0; // 8 bits/char
  71. // Default settings
  72. serDefaultSettings = serSettingsFlagBitsPerChar8 or
  73. serSettingsFlagStopBits1 or
  74. serSettingsFlagRTSAutoM;
  75. //!!! serDefaultCTSTimeout = 5 * sysTicksPerSecond;
  76. //
  77. // mask values for the lineErrors from SerGetStatus
  78. //
  79. const
  80. serLineErrorParity = $0001; // parity error
  81. serLineErrorHWOverrun = $0002; // HW overrun
  82. serLineErrorFraming = $0004; // framing error
  83. serLineErrorBreak = $0008; // break signal asserted
  84. serLineErrorHShake = $0010; // line hand-shake error
  85. serLineErrorSWOverrun = $0020; // HW overrun
  86. serLineErrorCarrierLost = $0040; // CD dropped
  87. (********************************************************************
  88. * Type of a wakeup handler procedure which can be installed through the
  89. * SerSetWakeupHandler() call.
  90. ********************************************************************)
  91. type
  92. SerWakeupHandler = procedure (refCon: UInt32);
  93. (********************************************************************
  94. * Type of an emulator-mode only blocking hook routine installed via
  95. * SerControl function serCtlEmuSetBlockingHook. This is supported only
  96. * under emulation mode. The argument to the function is the value
  97. * specified in the SerCallbackEntryType structure. The intention of the
  98. * return value is to return false if serial manager should abort the
  99. * current blocking action, such as when an app quit event has been received;
  100. * otherwise, it should return true. However, in the current implementation,
  101. * this return value is ignored. The callback can additionally process
  102. * events to enable user interaction with the UI, such as interacting with the
  103. * debugger.
  104. ********************************************************************)
  105. type
  106. SerBlockingHookHandler = function (userRef: UInt32): Boolean;
  107. (********************************************************************
  108. * Serial Library Control Enumerations (Pilot 2.0)
  109. ********************************************************************)
  110. (********************************************************************
  111. * Structure for specifying callback routines.
  112. ********************************************************************)
  113. type
  114. SerCallbackEntryType = record
  115. funcP: MemPtr; // function pointer
  116. userRef: UInt32; // ref value to pass to callback
  117. end;
  118. SerCallbackEntryPtr = ^SerCallbackEntryType;
  119. // v2.0 extension
  120. type
  121. SerCtlEnum = Enum;
  122. const
  123. serCtlFirstReserved = 0; // RESERVE 0
  124. serCtlStartBreak = Succ(serCtlFirstReserved); // turn RS232 break signal on:
  125. // users are responsible for ensuring that the break is set
  126. // long enough to genearate a valie BREAK!
  127. // valueP = 0, valueLenP = 0
  128. serCtlStopBreak = Succ(serCtlStartBreak); // turn RS232 break signal off:
  129. // valueP = 0, valueLenP = 0
  130. serCtlBreakStatus = Succ(serCtlStopBreak); // Get RS232 break signal status(on or off):
  131. // valueP = pointer to UInt16 for returning status(0 = off, !0 = on)
  132. // *valueLenP = sizeof(UInt16)
  133. serCtlStartLocalLoopback = Succ(serCtlBreakStatus); // Start local loopback test
  134. // valueP = 0, valueLenP = 0
  135. serCtlStopLocalLoopback = Succ(serCtlStartLocalLoopback); // Stop local loopback test
  136. // valueP = 0, valueLenP = 0
  137. serCtlMaxBaud = Succ(serCtlStopLocalLoopback); // Get maximum supported baud rate:
  138. // valueP = pointer to UInt32 for returned baud
  139. // *valueLenP = sizeof(UInt32)
  140. serCtlHandshakeThreshold = Succ(serCtlMaxBaud); // retrieve HW handshake threshold; this is the maximum baud rate
  141. // which does not require hardware handshaking
  142. // valueP = pointer to UInt32 for returned baud
  143. // *valueLenP = sizeof(UInt32)
  144. serCtlEmuSetBlockingHook = Succ(serCtlHandshakeThreshold); // Set a blocking hook routine FOR EMULATION
  145. // MODE ONLY - NOT SUPPORTED ON THE PILOT
  146. //PASS:
  147. // valueP = pointer to SerCallbackEntryType
  148. // *valueLenP = sizeof(SerCallbackEntryType)
  149. //RETURNS:
  150. // the old settings in the first argument
  151. serCtlIrDAEnable = Succ(serCtlEmuSetBlockingHook); // Enable IrDA connection on this serial port
  152. // valueP = 0, valueLenP = 0
  153. serCtlIrDADisable = Succ(serCtlIrDAEnable); // Disable IrDA connection on this serial port
  154. // valueP = 0, valueLenP = 0
  155. serCtlIrScanningOn = Succ(serCtlIrDADisable); // Start Ir Scanning mode
  156. serCtlIrScanningOff = Succ(serCtlIrScanningOn); // Stop Ir Scanning mode
  157. serCtlRxEnable = Succ(serCtlIrScanningOff); // enable receiver ( for IrDA )
  158. serCtlRxDisable = Succ(serCtlRxEnable); // disable receiver ( for IrDA )
  159. serCtlLAST = Succ(serCtlRxDisable); // ADD NEW ENTRIES BEFORE THIS ONE
  160. // Start of a custom op code range for licensees that wrote old serial
  161. // manager replacements. Note that the serial compatiblity library
  162. // does not pass these op codes to new serial manager plugins.
  163. const
  164. serCtlFirstCustomEntry = $A800;
  165. (********************************************************************
  166. * Serial Library Routines
  167. * These are define as syscall calls only under emulation mode or
  168. * under native mode from the module that actually installs the trap
  169. * vectors
  170. ********************************************************************)
  171. // Used by mac applications to map the pilot serial port to a particular
  172. // macintosh port.
  173. //!!!function SerSetMapPort(pilotPort, macPort: UInt16): UInt16;
  174. // Acquires and opens a serial port with given baud and default settings.
  175. function SerOpen(refNum: UInt16; port: UInt16; baud: UInt32): Err; syscall sysLibTrapOpen;
  176. // Used by debugger to re-initialize serial port if necessary
  177. //!!!function SerDbgAssureOpen(refNum: UInt16; port: UInt16; baud: UInt32): Err;
  178. // Closes the serial connection previously opened with SerOpen.
  179. function SerClose(refNum: UInt16): Err; syscall sysLibTrapClose;
  180. // Puts serial library to sleep
  181. function SerSleep(refNum: UInt16): Err; syscall sysLibTrapSleep;
  182. // Wake Serial library
  183. function SerWake(refNum: UInt16): Err; syscall sysLibTrapWake;
  184. // Get attributes of the serial connection
  185. function SerGetSettings(refNum: UInt16; settingsP: SerSettingsPtr): Err; syscall sysLibTrapCustom;
  186. // Set attributes of the serial connection
  187. function SerSetSettings(refNum: UInt16; settingsP: SerSettingsPtr): Err; syscall sysLibTrapCustom + 1;
  188. // Return status of serial connection
  189. function SerGetStatus(refNum: UInt16; var ctsOnP, dsrOnP: Boolean): UInt16; syscall sysLibTrapCustom + 2;
  190. // Reset error condition of serial connection
  191. function SerClearErr(refNum: UInt16): Err; syscall sysLibTrapCustom + 3;
  192. // Sends a buffer of data (may queue it up and return).
  193. function SerSend10(refNum: UInt16; const bufP: Pointer; size: UInt32): Err; syscall sysLibTrapCustom + 4;
  194. // Waits until the serial transmit buffer empties.
  195. // The timeout arg is ignored; CTS timeout is used
  196. function SerSendWait(refNum: UInt16; timeout: Int32): Err; syscall sysLibTrapCustom + 5;
  197. // Returns how many characters are left in the send queue waiting
  198. // for transmission
  199. function SerSendCheck(refNum: UInt16; var numBytesP: UInt32): Err; syscall sysLibTrapCustom + 6;
  200. // Flushes the data out of the transmit buffer
  201. function SerSendFlush(refNum: UInt16): Err; syscall sysLibTrapCustom + 7;
  202. // Receives a buffer of data of the given size.
  203. function SerReceive10(refNum: UInt16; bufP: Pointer; bytes, timeout: UInt32): Err; syscall sysLibTrapCustom + 8;
  204. // Waits for at least 'bytes' bytes of data to arrive at the serial input.
  205. // but does not read them in
  206. function SerReceiveWait(refNum: UInt16; bytes, timeout: UInt32): Err; syscall sysLibTrapCustom + 9;
  207. // Returns how many characters are in the receive queue
  208. function SerReceiveCheck(refNum: UInt16; var numBytesP: UInt32): Err; syscall sysLibTrapCustom + 10;
  209. // Flushes any data coming into the serial port, discarding the data.
  210. procedure SerReceiveFlush(refNum: UInt16; timeout: Int32); syscall sysLibTrapCustom + 11;
  211. // Specify a new input buffer. To restore the original buffer, pass
  212. // bufSize = 0.
  213. function SerSetReceiveBuffer(refNum: UInt16; bufP: Pointer; bufSize: UInt16): Err; syscall sysLibTrapCustom + 12;
  214. // The receive character interrupt service routine, called by kernel when
  215. // a UART interrupt is detected.
  216. function SerReceiveISP: Boolean; syscall sysTrapSerReceiveISP;
  217. // "Back Door" into the serial receive queue. Used by applications (like TCP Media layers)
  218. // that need faster access to received characters
  219. function SerReceiveWindowOpen(refNum: UInt16; var bufPP: UInt8Ptr; var sizeP: UInt32): Err; syscall sysLibTrapCustom + 13;
  220. function SerReceiveWindowClose(refNum: UInt16; bytesPulled: UInt32): Err; syscall sysLibTrapCustom + 14;
  221. // Can be called by applications that need an alternate wakeup mechanism
  222. // when characters get enqueued by the interrupt routine.
  223. function SerSetWakeupHandler(refNum: UInt16; procP: SerWakeupHandler; refCon: UInt32): Err; syscall sysLibTrapCustom + 15;
  224. // Called to prime wakeup handler
  225. function SerPrimeWakeupHandler(refNum: UInt16; minBytes: UInt16): Err; syscall sysLibTrapCustom + 16;
  226. // Called to perform a serial manager control operation
  227. // (v2.0 extension)
  228. function SerControl(refNum: UInt16; op: UInt16; valueP: Pointer; var valueLenP: UInt16): Err; syscall sysLibTrapCustom + 17;
  229. // Sends a buffer of data (may queue it up and return).
  230. function SerSend(refNum: UInt16; const bufP: Pointer; count: UInt32; var errP: Err): UInt32; syscall sysLibTrapCustom + 18;
  231. // Receives a buffer of data of the given size.
  232. function SerReceive(refNum: UInt16; bufP: Pointer; count: UInt32; timeout: Int32; var errP: Err): UInt32; syscall sysLibTrapCustom + 19;
  233. implementation
  234. end.