home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-1.ZIP / GCOMM / ASIFLOW.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  3.6 KB  |  105 lines

  1. /*
  2.  * asiflow.c
  3.  * contains: asiflow()
  4.  *
  5.  * The Greenleaf Comm Library
  6.  *
  7.  *Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "gf.h"
  12. #include "asiports.h"
  13.  
  14. /*
  15.  *  int
  16.  * asiflow(port,low_water,hi_water,ctrl,ctsctrl)
  17.  *
  18.  * ARGUMENT
  19.  *  (int)  port      =  port 0..MAX_PORT-1
  20.  *  (int)  low_water =  Integer % of receive buffer at which RTS is asserted
  21.  *  (int)  hi_water  =  Integer % of receive buffer at which RTS is deasserted
  22.  *  (int)  ctrl      =  ON/OFF (1/0) to enable/disable RTS control
  23.  *  (int)  ctsctrl   =  Controls what to do with CTS. (see below)
  24.  *
  25.  * DESCRIPTION
  26.  *  This function enables/disables automatic control of the RTS signal on
  27.  *  the RS-232 interface.  When enabled and the number of characters in
  28.  *  the receive buffer is at or above the hi_water point the RTS signal will
  29.  *  be de-asserted.  When sufficient characters have been removed from
  30.  *  the receive buffer to bring the count at or below the low_water point
  31.  *  the RTS signal will again be asserted.
  32.  *
  33.  *              Truth table for ctrl && ctsctrl
  34.  *
  35.  *              ctrl    ctsctrl         action
  36.  *
  37.  *               0        0     disable RTS and CTS checking & control
  38.  *               0        1     does nothing (invalid parameter)
  39.  *               1        0     enable RTS control, disable CTS checking
  40.  *               1        1     enable RTS control and CTS checking
  41.  *
  42.  * SIDE EFFECTS
  43.  *  Offsets into buffer computed will not be exact due to integer math;
  44.  *  they are within 1% in any case, with a floor of 1 byte.
  45.  *
  46.  * RETURNS
  47.  *
  48.  *      Value           Meaning
  49.  *     -------          --------
  50.  *      ASSUCCESS       Successful
  51.  *      ASINVPORT       Requested port is out of range
  52.  *      ASNOTSETUP      Requested port not setup with asifirst()
  53.  *      ASINVPAR        hi or lo water <1 or >99
  54.  *
  55.  *
  56.  * AUTHOR
  57.  *  ""   19-FEB-1987  14:10:19.61
  58.  *
  59.  * MODIFICATIONS
  60.  *
  61.  *
  62.  */
  63.  
  64. int GF_CONV asiflow(port,low_water,hi_water,ctrl,ctsctrl)
  65. int port,low_water,hi_water;
  66. int ctrl,ctsctrl;
  67. {
  68.         struct PORT_TABLE *p;
  69.  
  70.         if(!ctrl&&ctsctrl)
  71.                 return(ASINVPAR);
  72.         if((p=_aschkcnl(port))==NULL)
  73.                 return(_aserror);
  74.         if(ctrl) {
  75.                 if((low_water<1)||(low_water>99)||(hi_water<1)||
  76.                    (hi_water>99))
  77.                         return (ASINVPAR);
  78.                 p->rts_lowater=(unsigned)(((long)p->rx_size * (long)low_water)/(long)100)&0x0000ffff;
  79.                 if(p->rts_lowater==0)
  80.                         ++p->rts_lowater;
  81.                 p->rts_hiwater=(unsigned)(((long)p->rx_size * (long)hi_water) / (long)100)&0x0000ffff;
  82.                 if(p->rts_hiwater==0)
  83.                         ++p->rts_hiwater;
  84.                 _asrts(p->base_8250,(p->rx_count<p->rts_hiwater)?1:0,p);
  85.                 p->chmode_bits.is_rtscontrol=1;
  86.                 if(ctsctrl)
  87.                         p->chmode_bits.cts_low_holds_tx_interrupts=1;
  88.                 else {
  89.                         p->chmode_bits.cts_low_holds_tx_interrupts=0;
  90.                         if(p->chst_bits.txwcts) {
  91.                                 p->chst_bits.txwcts=0;
  92.                                 _asiprime(p);
  93.                         }
  94.                 }
  95.         } else {
  96.                 p->chmode_bits.is_rtscontrol=p->chmode_bits.cts_low_holds_tx_interrupts=0;
  97.                 if(p->chst_bits.txwcts) {
  98.                         p->chst_bits.txwcts=0;
  99.                         _asiprime(p);
  100.                 }
  101.         }
  102.         return(ASSUCCESS);
  103. }
  104.  
  105.