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 / ASIGETPA.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-14  |  3.0 KB  |  100 lines

  1. /* asigetpa.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  int asigetparms(port, baud, wordlen, parity, stopbits, dtr, rts)
  8. *  int port;            - Port 0..MAX_PORT-1
  9. *  long *baud;          - Put baud rate here (decoded integer value)
  10. *  int *wordlen;        - Put word length here (5,6,7,8)
  11. *  int *parity;         - Put parity here
  12. *  int *stopbits;       - Stopbits (1 or 2) go here
  13. *  int *dtr;            - DTR state (ON or OFF)
  14. *  int *rts;            - RTS state (ON or OFF)
  15. *
  16. * DESCRIPTION
  17. *
  18. *  Read the current state of the port initialization from the 8250 and place
  19. *  it in user variables.  If any arg (except port) is NULL, that means don't
  20. *  transfer that variable.
  21. *
  22. * SIDE EFFECTS
  23. *  none.
  24. *
  25. * RETURNS
  26. *
  27. *       Value           Meaning
  28. *     -------          --------
  29. *       ASSUCCESS       port initialized (no error)
  30. *       ASINVPORT       Requested port is out of range
  31. *       ASNOTSETUP      Requested port not setup with asifirst()
  32. *
  33. * MODIFICATIONS
  34. *
  35. *  03-12-86       wordlen,parity,stopbits values were receiving
  36. *                 values internal to 8250.  This was changed
  37. *                 to return values consistent with asiinit()'s
  38. *                 parameters.
  39. *
  40. *   Mon 05-Jun-1989 13:48:35
  41. *       Modified to return BAUD38K, BAUD56K and BAUD115K
  42. *
  43. */
  44. #include <stdio.h>
  45. #include "gf.h"
  46. #include "asiports.h"
  47.  
  48. int GF_CONV asigetparms(port,baud,wordlen,parity,stopbits,dtr,rts)
  49. int port;
  50. long *baud;
  51. int *wordlen,*parity,*stopbits,*dtr,*rts;
  52. {
  53.  
  54.         struct PORT_TABLE *p;
  55.         int creg;
  56.         unsigned int divisor;
  57.  
  58.         if((p=_aschkcnl(port))==NULL)
  59.                 return(_aserror);
  60.         if (baud) {
  61.             divisor = _asgetdivisor( p->base_8250 );
  62.             creg=_asinb( p->base_8250 + 3 );
  63.             if ( divisor > 0 )
  64.                 *baud = 115200L / divisor;
  65.             else
  66.                 *baud = -1L;
  67.         }
  68.         if(wordlen)
  69.                 *wordlen=(creg&3)+5;
  70.         if(stopbits)
  71.                 *stopbits=((creg>>2)&1)+1;
  72.         if(parity) {
  73.                 creg&=0x38;
  74.                 switch(creg) {
  75.                         case  0:
  76.                                 *parity = P_NONE;
  77.                                 break;
  78.                         case  8:
  79.                                 *parity = P_ODD;
  80.                                 break;
  81.                         case 0x18:
  82.                                 *parity = P_EVEN;
  83.                                 break;
  84.                         case 0x28:
  85.                                 *parity = P_S_STICK;
  86.                                 break;
  87.                         case 0x38:
  88.                                 *parity = P_M_STICK;
  89.                                 break;
  90.                 }
  91.         }
  92.         creg=_asinb(p->base_8250+4);
  93.         if(dtr)
  94.                 *dtr=creg&1;
  95.         if(rts)
  96.                 *rts=(creg>>1)&1;
  97.         return(ASSUCCESS);
  98.  
  99. }
  100.