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

  1. /* asiquit.c
  2. *
  3. * The Greenleaf Comm Library
  4. *
  5. * Copyright (C) 1985-1990 Greenleaf Software Inc.  All Rights Reserved.
  6. *
  7. *  int asiquit( port )
  8. *  int port;            - Port 0..MAX_PORT
  9. *
  10. * DESCRIPTION
  11. *  this function is called to terminate an rs-232 port.  It restores
  12. *  the previous state of the 8250, 8259 and interrupt vector for the
  13. *  port.  In addition all dynamic memory allocated for the port
  14. *  is released.  This function MUST be executed before a program terminates
  15. *  through the normal dos terminate gate.  (Not necessary if program is
  16. *  terminates and stays resident)
  17. *
  18. * SIDE EFFECTS
  19. *  If not executed interrupts remain "hot", if application using interrupts
  20. *  exits releasing it's memory space to dos and another program is later
  21. *  loaded followed by activity on the serial port serious "hurricanes" can
  22. *  occur.
  23. *
  24. * RETURNS
  25. *
  26. *       Value           Meaning
  27. *     -------          --------
  28. *       ASSUCCESS       port shut down successfully
  29. *       ASINVPORT       Requested port is out of range
  30. *       ASNOTSETUP      Requested port not setup with asifirst()
  31. *
  32. * MODIFICATIONS
  33. *   03-FEB-1987  11:27:24.68
  34. *       Added code to de-allocate as_chnl 's memory and reset it to a
  35. *       NULL pointer when the last port has been shut down.  It is
  36. *       not necessary to do another _asregister() at this point because
  37. *       all I/O activity with all ports has been disabled.
  38. *   09-MAR-1987  10:07:51.66
  39. *       changed static int _asidown() to int _asidown() for HIGH-C
  40. *
  41. */
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include "gf.h"
  45. #include "asiports.h"
  46.  
  47.  
  48. int GF_CONV asiquit(port)
  49. int port;
  50. {
  51.  
  52.         if(port==-1)
  53.                 for(port=0;port<MAX_PORT;++port)
  54.                         _asidown(port);
  55.         else
  56.                 return(_asidown(port));
  57.         return(ASSUCCESS);
  58. }
  59.  
  60.  
  61.  
  62. int GF_CONV _asidown(port)
  63. int port;
  64. {
  65.         extern int _aserror;
  66.         int latch,i;
  67.         struct PORT_TABLE *p;
  68.  
  69.         if((p=_aschkcnl(port))==NULL)
  70.                 return(_aserror);
  71.  
  72.         /****************************************************************
  73.         * Look to see if any other ports using the same interrupt       *
  74.         *  number are still not quit.  If so, pass a 0 as the first     *
  75.         *  arg to _asiquit() to tell it to avoid hitting the 8259A and  *
  76.         *  to avoid restoring the interrupt vector as yet.              *
  77.         ****************************************************************/
  78.         latch = 1;
  79.         for(i=0;i<=(MAX_PORT-1);i++) {
  80.                 if((i!=port)&&(as_chnl->tblport[i].ptb!=NULL)) {
  81.                         if(as_chnl->tblport[i].ptb->intrpt_num==
  82.                            as_chnl->tblport[port].ptb->intrpt_num)
  83.                                 latch = 0;
  84.                 }
  85.         }
  86.  
  87.         /****************************************************************
  88.         *  If latch = 1 than no other port uses same intr number, so    *
  89.         *  the 8259A and vector will be restored.                       *
  90.         *  Otherwise, one or more other ports that have not yet been    *
  91.         * "quit" use the same vector number, so don't mess with it.     *
  92.         ****************************************************************/
  93.         _asiquit(latch,p);
  94.         free(p->rx_buffer);
  95.         free(p->tx_buffer);
  96.         free((char *) p);
  97.         as_chnl->tblport[port].ptb=NULL;
  98.         if(_asoprt) {
  99.                 --_asoprt;
  100.                 if(!_asoprt) {
  101.                         free((char *)as_chnl);
  102.                         as_chnl=(struct TABLEPORT *)0;
  103.                 }
  104.         }
  105.         return(ASSUCCESS);
  106. }
  107.  
  108. void GF_CDECL _asiexit_routine(void)
  109. {
  110.         asiquit(-1);
  111. }
  112.  
  113.  
  114.