serial.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit serial;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$PACKRECORDS 2}
  17. {$IFDEF FPC_DOTTEDUNITS}
  18. uses
  19. Amiga.Core.Exec;
  20. {$ELSE FPC_DOTTEDUNITS}
  21. uses
  22. exec;
  23. {$ENDIF FPC_DOTTEDUNITS}
  24. type
  25. // array of termination AnsiChar's to use,see serial.doc setparams
  26. PIOTArray = ^TIOTArray;
  27. TIOTArray = record
  28. TermArray0: LongWord;
  29. TermArray1: LongWord;
  30. end;
  31. const
  32. SER_DEFAULT_CTLCHAR = $11130000; // default chars for xON,xOFF
  33. { You may change these via SETPARAMS. At this time, parity is not
  34. calculated for xON/xOFF characters. You must supply them with the
  35. desired parity. }
  36. {****************************************************************}
  37. { CAUTION !! IF YOU ACCESS the serial.device, you MUST (!!!!) use an
  38. IOExtSer-sized structure or you may overlay innocent memory !! }
  39. {****************************************************************}
  40. type
  41. TIOExtSer = record
  42. IOSer: TIOStdReq;
  43. io_CtlChar: LongWord; // control characters
  44. io_RBufLen: LongWord; // length in bytes of serial read buffer
  45. io_ExtFlags: LongWord; // additional serial flags (SEXTB_*)
  46. io_Baud: LongWord; // baud rate
  47. io_BrkTime: LongWord; // duration of break in microseconds
  48. io_TermArray: TIOTArray; // termination character array
  49. io_ReadLen: Byte; // number of bits per read character
  50. io_WriteLen: Byte; // number of bits per write character
  51. io_StopBits: Byte; // number of stopbits for read
  52. io_SerFlags: Byte; // serial device flags (SERB_*)
  53. io_Status: Word; // status of serial port and lines (IO_STATF_*, IOSTF_*)
  54. end;
  55. PIOExtSer = ^TIOExtSer;
  56. { status of serial port, as follows:
  57. BIT ACTIVE FUNCTION
  58. 0 --- reserved
  59. 1 --- reserved
  60. 2 high Connected to parallel "select" on the A1000.
  61. Connected to both the parallel "select" and
  62. serial "ring indicator" pins on the A500 &
  63. A2000. Take care when making cables.
  64. 3 low Data Set Ready
  65. 4 low Clear To Send
  66. 5 low Carrier Detect
  67. 6 low Ready To Send
  68. 7 low Data Terminal Ready
  69. 8 high read overrun
  70. 9 high break sent
  71. 10 high break received
  72. 11 high transmit x-OFFed
  73. 12 high receive x-OFFed
  74. 13-15 reserved}
  75. const
  76. SDCMD_QUERY = CMD_NONSTD;
  77. SDCMD_BREAK = CMD_NONSTD + 1;
  78. SDCMD_SETPARAMS = CMD_NONSTD + 2;
  79. // flags of TIOExtSer.io_SerFlags
  80. SERB_XDISABLED = 7; // xOn-xOff feature disabled
  81. SERF_XDISABLED = 1 shl SERB_XDISABLED;
  82. SERB_EOFMODE = 6; // EOF mode enabled
  83. SERF_EOFMODE = 1 shl SERB_EOFMODE;
  84. SERB_SHARED = 5; // non-exclusive access
  85. SERF_SHARED = 1 shl SERB_SHARED;
  86. SERB_RAD_BOOGIE = 4; // high-speed mode active
  87. SERF_RAD_BOOGIE = 1 shl SERB_RAD_BOOGIE;
  88. SERB_QUEUEDBRK = 3; // queue this Break ioRqst
  89. SERF_QUEUEDBRK = 1 shl SERB_QUEUEDBRK;
  90. SERB_7WIRE = 2; // RS232 7-wire protocol
  91. SERF_7WIRE = 1 shl SERB_7WIRE;
  92. SERB_PARTY_ODD = 1; // parity feature enabled
  93. SERF_PARTY_ODD = 1 shl SERB_PARTY_ODD;
  94. SERB_PARTY_ON = 0; // parity-enabled
  95. SERF_PARTY_ON = 1 shl SERB_PARTY_ON;
  96. // These now refect the actual bit positions in the TIOExtSer.io_Status LongWord
  97. IO_STATB_XOFFREAD = 12; // receive currently xOFF'ed
  98. IO_STATF_XOFFREAD = 1 shl IO_STATB_XOFFREAD;
  99. IO_STATB_XOFFWRITE = 11; // transmit currently xOFF'ed
  100. IO_STATF_XOFFWRITE = 1 shl IO_STATB_XOFFWRITE;
  101. IO_STATB_READBREAK = 10; // break was latest input
  102. IO_STATF_READBREAK = 1 shl IO_STATB_READBREAK;
  103. IO_STATB_WROTEBREAK = 9; // break was latest output
  104. IO_STATF_WROTEBREAK = 1 shl IO_STATB_WROTEBREAK;
  105. IO_STATB_OVERRUN = 8; // status word RBF overrun
  106. IO_STATF_OVERRUN = 1 shl IO_STATB_OVERRUN;
  107. // TIOExtSer.io_ExtFlags
  108. SEXTB_MSPON = 1; // Use mark-space parity, instead of odd-even.
  109. SEXTF_MSPON = 1 shl SEXTB_MSPON;
  110. SEXTB_MARK = 0; // if mark-space, use mark
  111. SEXTF_MARK = 1 shl SEXTB_MARK;
  112. SerErr_DevBusy = 1;
  113. SerErr_BaudMismatch = 2; // baud rate not supported by hardware
  114. SerErr_BufErr = 4; // Failed to allocate new read buffer
  115. SerErr_InvParam = 5;
  116. SerErr_LineErr = 6;
  117. SerErr_ParityErr = 9;
  118. SerErr_TimerErr = 11; // (See the serial/OpenDevice autodoc)
  119. SerErr_BufOverflow = 12;
  120. SerErr_NoDSR = 13;
  121. SerErr_DetectedBreak = 15;
  122. { These defines refer to the HIGH ORDER byte of io_Status. They have
  123. been replaced by the new, corrected ones above }
  124. IOSTB_XOFFREAD = 4; // receive currently xOFF'ed
  125. IOSTF_XOFFREAD = 1 shl IOSTB_XOFFREAD;
  126. IOSTB_XOFFWRITE = 3; // transmit currently xOFF'ed
  127. IOSTF_XOFFWRITE = 1 shl IOSTB_XOFFWRITE;
  128. IOSTB_READBREAK = 2; // break was latest input
  129. IOSTF_READBREAK = 1 shl IOSTB_READBREAK;
  130. IOSTB_WROTEBREAK= 1; // break was latest output
  131. IOSTF_WROTEBREAK= 1 shl IOSTB_WROTEBREAK;
  132. IOSTB_OVERRUN = 0; // status word RBF overrun
  133. IOSTF_OVERRUN = 1 shl IOSTB_OVERRUN;
  134. // TIOExtSer.io_Flags
  135. IOSERB_BUFRREAD = 7; // from read buffer
  136. IOSERF_BUFRREAD = 1 shl IOSERB_BUFRREAD;
  137. IOSERB_QUEUED = 6; // rqst-queued
  138. IOSERF_QUEUED = 1 shl IOSERB_QUEUED;
  139. IOSERB_ABORT = 5; // rqst-aborted
  140. IOSERF_ABORT = 1 shl IOSERB_ABORT;
  141. IOSERB_ACTIVE = 4; // rqst-qued-OR-current
  142. IOSERF_ACTIVE = 1 shl IOSERB_ACTIVE;
  143. SERIALNAME: PAnsiChar = 'serial.device';
  144. implementation
  145. end.