summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/palmunits/src/serialmgrold.pp
blob: 5933048476ffe99653bab0a53cf17b30d6dd7730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
{$MACRO ON}

(******************************************************************************
 *
 * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
 * All rights reserved.
 *
 * File: SerialMgrOld.h
 *
 * Release: Palm OS SDK 4.0 (63220)
 *
 * Description:
 *    Include file for Serial manager
 *
 * History:
 *    2/7/95 Created by Ron Marianetti
 *    7/6/95   vmk   added serDefaultSettings
 *    1/28/98  scl   added Serial Port Definitions
 *
 *****************************************************************************)

unit serialmgrold;

interface

uses palmos, coretraps, libtraps, errorbase, systemmgr;

(********************************************************************
 * Serial Manager Errors
 * the constant serErrorClass is defined in SystemMgr.h
 ********************************************************************)

const
  serErrBadParam     = serErrorClass or 1;
  serErrBadPort      = serErrorClass or 2;
  serErrNoMem        = serErrorClass or 3;
  serErrBadConnID    = serErrorClass or 4;
  serErrTimeOut      = serErrorClass or 5;
  serErrLineErr      = serErrorClass or 6;
  serErrAlreadyOpen  = serErrorClass or 7;
  serErrStillOpen    = serErrorClass or 8;
  serErrNotOpen      = serErrorClass or 9;
  serErrNotSupported = serErrorClass or 10; // functionality not supported

(********************************************************************
 * Serial Port Definitions
 ********************************************************************)

const
  serPortDefault      = $0000; // Use prefDefSerialPlugIn
  serPortLocalHotSync = $8000; // Use physical HotSync port
  serPortMaskLocal    = $7FFF; // Mask off HotSync "hint" (for SerialMgr)

(********************************************************************
 * Serial Settings Descriptor
 ********************************************************************)

type
  SerSettingsType = record
   baudRate: UInt32;  // baud rate
   flags: UInt32;     // miscellaneous settings
   ctsTimeout: Int32; // max # of ticks to wait for CTS to become asserted
                      // before transmitting; used only when
                      // configured with serSettingsFlagCTSAutoM.
  end;
  SerSettingsPtr = ^SerSettingsType;

const
  serSettingsFlagStopBitsM    = $00000001; // mask for stop bits field
  serSettingsFlagStopBits1    = $00000000; //  1 stop bits
  serSettingsFlagStopBits2    = $00000001; //  2 stop bits
  serSettingsFlagParityOnM    = $00000002; // mask for parity on
  serSettingsFlagParityEvenM  = $00000004; // mask for parity even
  serSettingsFlagXonXoffM     = $00000008; // (NOT IMPLEMENTED) mask for Xon/Xoff flow control
  serSettingsFlagRTSAutoM     = $00000010; // mask for RTS rcv flow control
  serSettingsFlagCTSAutoM     = $00000020; // mask for CTS xmit flow control
  serSettingsFlagBitsPerCharM = $000000C0; // mask for bits/char
  serSettingsFlagBitsPerChar5 = $00000000; //  5 bits/char
  serSettingsFlagBitsPerChar6 = $00000040; //  6 bits/char
  serSettingsFlagBitsPerChar7 = $00000080; //  7 bits/char
  serSettingsFlagBitsPerChar8 = $000000C0; //  8 bits/char

// Default settings
  serDefaultSettings = serSettingsFlagBitsPerChar8 or
                       serSettingsFlagStopBits1 or
                       serSettingsFlagRTSAutoM;

//!!!  serDefaultCTSTimeout = 5 * sysTicksPerSecond;

//
// mask values for the lineErrors  from SerGetStatus
//

const
  serLineErrorParity      = $0001; // parity error
  serLineErrorHWOverrun   = $0002; // HW overrun
  serLineErrorFraming     = $0004; // framing error
  serLineErrorBreak       = $0008; // break signal asserted
  serLineErrorHShake      = $0010; // line hand-shake error
  serLineErrorSWOverrun   = $0020; // HW overrun
  serLineErrorCarrierLost = $0040; // CD dropped

(********************************************************************
 * Type of a wakeup handler procedure which can be installed through the
 *   SerSetWakeupHandler() call.
 ********************************************************************)

type
  SerWakeupHandler = procedure (refCon: UInt32);

(********************************************************************
 * Type of an emulator-mode only blocking hook routine installed via
 * SerControl function serCtlEmuSetBlockingHook.  This is supported only
 * under emulation mode.  The argument to the function is the value
 * specified in the SerCallbackEntryType structure.  The intention of the
 * return value is to return false if serial manager should abort the
 * current blocking action, such as when an app quit event has been received;
 * otherwise, it should return true.  However, in the current implementation,
 * this return value is ignored.  The callback can additionally process
 * events to enable user interaction with the UI, such as interacting with the
 * debugger.
 ********************************************************************)

type
  SerBlockingHookHandler = function (userRef: UInt32): Boolean;

(********************************************************************
 * Serial Library Control Enumerations (Pilot 2.0)
 ********************************************************************)

(********************************************************************
 * Structure for specifying callback routines.
 ********************************************************************)

type
  SerCallbackEntryType = record
    funcP: MemPtr;   // function pointer
    userRef: UInt32; // ref value to pass to callback
  end;
  SerCallbackEntryPtr = ^SerCallbackEntryType;

// v2.0 extension
type
  SerCtlEnum = Enum;

const
  serCtlFirstReserved = 0;                                   // RESERVE 0

  serCtlStartBreak = Succ(serCtlFirstReserved);              // turn RS232 break signal on:
                                                             // users are responsible for ensuring that the break is set
                                                             // long enough to genearate a valie BREAK!
                                                             // valueP = 0, valueLenP = 0

  serCtlStopBreak = Succ(serCtlStartBreak);                  // turn RS232 break signal off:
                                                             // valueP = 0, valueLenP = 0

  serCtlBreakStatus = Succ(serCtlStopBreak);                 // Get RS232 break signal status(on or off):
                                                             // valueP = pointer to UInt16 for returning status(0 = off, !0 = on)
                                                             // *valueLenP = sizeof(UInt16)

  serCtlStartLocalLoopback = Succ(serCtlBreakStatus);        // Start local loopback test
                                                             // valueP = 0, valueLenP = 0

  serCtlStopLocalLoopback = Succ(serCtlStartLocalLoopback);  // Stop local loopback test
                                                             // valueP = 0, valueLenP = 0

  serCtlMaxBaud = Succ(serCtlStopLocalLoopback);             // Get maximum supported baud rate:
                                                             // valueP = pointer to UInt32 for returned baud
                                                             // *valueLenP = sizeof(UInt32)

  serCtlHandshakeThreshold = Succ(serCtlMaxBaud);            // retrieve HW handshake threshold; this is the maximum baud rate
                                                             // which does not require hardware handshaking
                                                             // valueP = pointer to UInt32 for returned baud
                                                             // *valueLenP = sizeof(UInt32)

  serCtlEmuSetBlockingHook = Succ(serCtlHandshakeThreshold); // Set a blocking hook routine FOR EMULATION
                                                             // MODE ONLY - NOT SUPPORTED ON THE PILOT
                                                             //PASS:
                                                             // valueP = pointer to SerCallbackEntryType
                                                             // *valueLenP = sizeof(SerCallbackEntryType)
                                                             //RETURNS:
                                                             // the old settings in the first argument


  serCtlIrDAEnable = Succ(serCtlEmuSetBlockingHook);         // Enable  IrDA connection on this serial port
                                                             // valueP = 0, valueLenP = 0

  serCtlIrDADisable = Succ(serCtlIrDAEnable);                // Disable  IrDA connection on this serial port
                                                             // valueP = 0, valueLenP = 0

  serCtlIrScanningOn = Succ(serCtlIrDADisable);              // Start Ir Scanning mode

  serCtlIrScanningOff = Succ(serCtlIrScanningOn);            // Stop Ir Scanning mode

  serCtlRxEnable = Succ(serCtlIrScanningOff);                // enable receiver  ( for IrDA )

  serCtlRxDisable = Succ(serCtlRxEnable);                    // disable receiver ( for IrDA )

  serCtlLAST = Succ(serCtlRxDisable);                        // ADD NEW ENTRIES BEFORE THIS ONE


// Start of a custom op code range for licensees that wrote old serial
// manager replacements.  Note that the serial compatiblity library
// does not pass these op codes to new serial manager plugins.
const
  serCtlFirstCustomEntry = $A800;

(********************************************************************
 * Serial Library Routines
 * These are define as syscall calls only under emulation mode or
 *  under native mode from the module that actually installs the trap
 *  vectors
 ********************************************************************)

// Used by mac applications to map the pilot serial port to a particular
// macintosh port.
//!!!function SerSetMapPort(pilotPort, macPort: UInt16): UInt16;

// Acquires and opens a serial port with given baud and default settings.
function SerOpen(refNum: UInt16; port: UInt16; baud: UInt32): Err; syscall sysLibTrapOpen;

// Used by debugger to re-initialize serial port if necessary
//!!!function SerDbgAssureOpen(refNum: UInt16; port: UInt16; baud: UInt32): Err;

// Closes the serial connection previously opened with SerOpen.
function SerClose(refNum: UInt16): Err; syscall sysLibTrapClose;

// Puts serial library to sleep
function SerSleep(refNum: UInt16): Err; syscall sysLibTrapSleep;

// Wake Serial library
function SerWake(refNum: UInt16): Err; syscall sysLibTrapWake;

// Get attributes of the serial connection
function SerGetSettings(refNum: UInt16; settingsP: SerSettingsPtr): Err; syscall sysLibTrapCustom;

// Set attributes of the serial connection
function SerSetSettings(refNum: UInt16; settingsP: SerSettingsPtr): Err; syscall sysLibTrapCustom + 1;

// Return status of serial connection
function SerGetStatus(refNum: UInt16; var ctsOnP, dsrOnP: Boolean): UInt16; syscall sysLibTrapCustom + 2;

// Reset error condition of serial connection
function SerClearErr(refNum: UInt16): Err; syscall sysLibTrapCustom + 3;

// Sends a buffer of data (may queue it up and return).
function SerSend10(refNum: UInt16; const bufP: Pointer; size: UInt32): Err; syscall sysLibTrapCustom + 4;

// Waits until the serial transmit buffer empties.
// The timeout arg is ignored; CTS timeout is used
function SerSendWait(refNum: UInt16; timeout: Int32): Err; syscall sysLibTrapCustom + 5;

// Returns how many characters are left in the send queue waiting
//  for transmission
function SerSendCheck(refNum: UInt16; var numBytesP: UInt32): Err; syscall sysLibTrapCustom + 6;

// Flushes the data out of the transmit buffer
function SerSendFlush(refNum: UInt16): Err; syscall sysLibTrapCustom + 7;

// Receives a buffer of data of the given size.
function SerReceive10(refNum: UInt16; bufP: Pointer; bytes, timeout: UInt32): Err; syscall sysLibTrapCustom + 8;

// Waits for at least 'bytes' bytes of data to arrive at the serial input.
//  but does not read them in
function SerReceiveWait(refNum: UInt16; bytes, timeout: UInt32): Err; syscall sysLibTrapCustom + 9;

// Returns how many characters are in the receive queue
function SerReceiveCheck(refNum: UInt16; var numBytesP: UInt32): Err; syscall sysLibTrapCustom + 10;

// Flushes any data coming into the serial port, discarding the data.
procedure SerReceiveFlush(refNum: UInt16; timeout: Int32); syscall sysLibTrapCustom + 11;

// Specify a new input buffer.  To restore the original buffer, pass
// bufSize = 0.
function SerSetReceiveBuffer(refNum: UInt16; bufP: Pointer; bufSize: UInt16): Err; syscall sysLibTrapCustom + 12;

// The receive character interrupt service routine, called by kernel when
//  a UART interrupt is detected.
function SerReceiveISP: Boolean; syscall sysTrapSerReceiveISP;

// "Back Door" into the serial receive queue. Used by applications (like TCP Media layers)
//  that need faster access to received characters
function SerReceiveWindowOpen(refNum: UInt16; var bufPP: UInt8Ptr; var sizeP: UInt32): Err; syscall sysLibTrapCustom + 13;

function SerReceiveWindowClose(refNum: UInt16; bytesPulled: UInt32): Err; syscall sysLibTrapCustom + 14;

// Can be called by applications that need an alternate wakeup mechanism
//  when characters get enqueued by the interrupt routine.
function SerSetWakeupHandler(refNum: UInt16; procP: SerWakeupHandler; refCon: UInt32): Err; syscall sysLibTrapCustom + 15;

// Called to prime wakeup handler
function SerPrimeWakeupHandler(refNum: UInt16; minBytes: UInt16): Err; syscall sysLibTrapCustom + 16;

// Called to perform a serial manager control operation
// (v2.0 extension)
function SerControl(refNum: UInt16; op: UInt16; valueP: Pointer; var valueLenP: UInt16): Err; syscall sysLibTrapCustom + 17;

// Sends a buffer of data (may queue it up and return).
function SerSend(refNum: UInt16; const bufP: Pointer; count: UInt32; var errP: Err): UInt32; syscall sysLibTrapCustom + 18;

// Receives a buffer of data of the given size.
function SerReceive(refNum: UInt16; bufP: Pointer; count: UInt32; timeout: Int32; var errP: Err): UInt32; syscall sysLibTrapCustom + 19;

implementation

end.