home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ucsdwdme.zip / wdprocs.text < prev   
Text File  |  1984-12-03  |  7KB  |  194 lines

  1. (* These drivers were adapted from routines written by Tim Shimeall
  2.    for a PCNET implementation, based on information from Western
  3.    Digital.
  4.  
  5.    On the Microengine, there are two RS232C Serial Ports.  Port A is
  6.    reserved for the system terminal.  Port B is available for all other
  7.    devices which may be desired to hang off a Microengine.  In this code,
  8.    it is assumed that Port B holds the modem.
  9. *)
  10. (* All functions are duplicated on ports A and B for simplicity *)
  11.  
  12. PROCEDURE Init;
  13. BEGIN (* InitM *)
  14.    PortB.DevAdd:= Channel0;
  15.    PortA.DevAdd:= Channel1;
  16.    WITH PortB.Serial^ DO BEGIN
  17.      {The following two lines set the serial port to the following
  18.       commands:
  19.          Control1:
  20.            1 - Full Duplex Operation
  21.            0 - Break or Transmit NOT transparent
  22.            0 - Send 2 stop bits on Transmitted 8-bit data
  23.            0 - No echo of Recieved data
  24.            0 - Parity checking/generation OFF
  25.            1 - Reciever is enabled (chars in Rec. holding reg.)
  26.            1 - REQUEST TO SEND is enabled if CTS is low
  27.            1 - DTR is ON
  28.           Control2:
  29.            0 - 8 bits
  30.            0 - 8 bits
  31.            0 - Asynchronous character mode
  32.            0 - even parity
  33.            0 - select reciever rate 1
  34.            0 - +
  35.            0   | - Clock select to rate 1 (32X)
  36.            1 - +
  37.        }
  38.      Control1:=135; {87 hex}
  39.      Control2:=1;
  40.      END;
  41.    WITH PortA.Serial^ DO BEGIN
  42.      Control1:=135;
  43.      Control2:=1;
  44.      END;
  45. END; (*InitM*)
  46.  
  47. (*---------------------UART FLAG CHECKING-------------------------------*)
  48.  
  49. function ISTARR(*:boolean *);
  50. (* ARR -- IS True Port A Receive Ready?
  51.  
  52. This checks the UART status bit corresponding to Receive Data
  53. Available. If data is available a true result is returned.*)
  54. BEGIN
  55.   ISTARR:=PortA.Serial^.StatSynDle.status[DataReceived];
  56. END;
  57.  
  58. function ISTBRR(*:boolean*);
  59. (* BRR -- IS True Port B Receive Ready?*)
  60. BEGIN
  61.   ISTBRR:=PortB.Serial^.StatSynDle.status[DataReceived];
  62. END;
  63.  
  64. function ISTAOR(*:boolean*);
  65. (* AOR -- IS it True that data OverRun occurred?:0 istor<ditto>
  66.  
  67. Immediately after RCVBT is called, ISTOR may be called to check for
  68. data overrun. This function isn't necessary, but it helps diagnose
  69. software that is losing data because it is too slow to receive data
  70. before that data starts getting shifted out of the way to make way for
  71. later data that has already started to arrive.
  72. *)
  73. BEGIN
  74.   ISTAOR:=PortA.Serial^.StatSynDle.Status[OverError];
  75. END;
  76.  
  77. function ISTBOR(*:boolean*);
  78. BEGIN
  79.   ISTBOR:=PortB.Serial^.StatSynDle.Status[OverError];
  80. END;
  81.  
  82. function ISTAFE(*:boolean *);
  83. (* FE -- IS it True that Framing-Error occurred?:0 istfe<ditto>
  84.  
  85. Immediately after RCVBT is called, ISTFE may be called to check for
  86. framing error. This function isn't necessary, but it helps diagnose
  87. various errors such as phone-line-noise and wrong-speed-UART. Normally
  88. ISTOR will be called before ISTFE since data overrun is a more serious
  89. error than framing-error and thus pre-empts framing-error. The entire
  90. sequence is thus: ISTRR, RCVBT, ISTOR, ISTFE.
  91. *)
  92. BEGIN
  93.   ISTAFE:=PortA.Serial^.StatSynDle.Status[FrameError];
  94. END;
  95.  
  96. function ISTBFE(*:boolean*);
  97. BEGIN
  98.   ISTBFE:=PortB.Serial^.StatSynDle.Status[FrameError];
  99. END;
  100.  
  101. function ISTATR(*:boolean *);
  102. (* TR -- IS it True that Transmit is Ready?:0 isttr<used in FDX&SDWBT>
  103.  
  104. ISTTR is analagous to ISTRR, it tells whether it's safe to transmit
  105. (rather than to receive) a byte of data. Internally it tells whether
  106. the previous byte has cleared the device so that the buffer is empty
  107. to accept another byte. In the device descripion it's usually called
  108. Transmit Buffer Empty. For instantaneous devices such as memory-mapped
  109. CRTs, this function will always return TRUE. For most other devices
  110. such as UARTs and ACIAs (connected directly to terminals, or to
  111. modems), ISTTR will return TRUE initially, then return FALSE as soon
  112. as a byte is sent to the device, and then return TRUE when actual
  113. transmission is done. For double-buffered devices it may only go FALSE
  114. only after two characters are sent to it, one of which is actually en
  115. route and the other of which is merely occupying the extra buffer.
  116. *)
  117. BEGIN
  118.   ISTATR:=PortA.Serial^.StatSynDle.Status[RegEmpty];
  119. END;
  120.  
  121. function ISTBTR(*:boolean*);
  122. BEGIN
  123.   ISTBTR:=PortB.Serial^.StatSynDle.Status[RegEmpty];
  124. END;
  125.  
  126. (*------------------Primitive character sending and receiving---------------*)
  127.  
  128. function RCVABT(*:CHAR*) ;
  129. (* ReCeiVe ByTe of data from device:0 rcvbt<used in FDX and RCWBT>
  130.  
  131. This is the function that is called after ISTRR returns true, to
  132. actually fetch the waiting data from the UART or ACIA into the
  133. computer, freeing the device to accept the next byte of data. These
  134. two functions, testing for data ready and actually fetching the data,
  135. are kept separate for two reasons: (1) they are separate hardware
  136. functions in most existing devices, ISTRR being a read of the status
  137. port with testing for a bit and RCVBT being a read of the data
  138. port, and (2) often they must be separate in the software, such as
  139. when it's necessary to verify both that data is available and there's
  140. a place to put it before fetching the data, such as in a terminal emulator.
  141.  
  142. Note that calling RCVBT any time other than after getting a true
  143. result from ISTRR is invalid, yielding random garbage such as part of
  144. an incoming byte shifted. Note also that RCVBT fetches all 8 bits of
  145. the incoming byte of data, returning an 8-bit number with each bit in
  146. its normal position, for example the first-arrived bit is the 1 bit,
  147. then the 2 bit, etc., with the "parity" bit which is the last-arrived
  148. appearing simply as an 8th bit (hexadecimal value 80). No checking of
  149. parity is allowed, nor is stripping off of the parity bit. When only 7
  150. bits are desired, a higher-level function will strip off the parity bit.*)
  151. BEGIN
  152.   RCVABT:=CHR(PortA.Serial^.SerData);
  153. END;
  154.  
  155. function RCVBBT(*:CHAR*);
  156. BEGIN
  157.   RCVBBT:=CHR(PortB.Serial^.SerData);
  158. END;
  159.  
  160. procedure SNDABT(* (BT:CHAR)*);
  161. (* SeND ByTe of data:0 sndbt<used in FDX&SDWBT>
  162.  
  163. After getting back a TRUE result from isttr, this function SNDBT is
  164. used to actually send the byte of data from the CPU to the device, so
  165. as to effect sending it out the I/O port (modem or local CRT). Note
  166. that any attempt to call SNDBT without first getting TRUE from isttr
  167. can result in clobbering previous data that is still in transit from
  168. the UART or ACIA bit by bit, causing both that previous byte and this
  169. new byte to be lost/garbaged. *)
  170. BEGIN (* SNDABT*)
  171.   PortA.Serial^.SerData:=ORD(BT);
  172. END(*SNDABT*);
  173.  
  174. procedure SNDBBT(* (BT:CHAR)*);
  175. (* SeND ByTe of data:0 sndbt<used in FDX&SDWBT>
  176.  
  177. After getting back a TRUE result from isttr, this function SNDBT is
  178. used to actually send the byte of data from the CPU to the device, so
  179. as to effect sending it out the I/O port (modem or local CRT). Note
  180. that any attempt to call SNDBT without first getting TRUE from isttr
  181. can result in clobbering previous data that is still in transit from
  182. the UART or ACIA bit by bit, causing both that previous byte and this
  183. new byte to be lost/garbaged. *)
  184. BEGIN (* SNDBBT*)
  185.   PortB.Serial^.SerData:=ORD(BT);
  186. END(*SNDBBT*);
  187.  
  188. procedure finit;
  189. BEGIN
  190.   PortB.Serial^.Control1:=0; {Turn off DTR, which causes modem to hang up}
  191. END;
  192.  
  193.  
  194.