serial.pas 6.3 KB

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