home *** CD-ROM | disk | FTP | other *** search
- /* asiquit.c
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1985-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * int asiquit( port )
- * int port; - Port 0..MAX_PORT
- *
- * DESCRIPTION
- * this function is called to terminate an rs-232 port. It restores
- * the previous state of the 8250, 8259 and interrupt vector for the
- * port. In addition all dynamic memory allocated for the port
- * is released. This function MUST be executed before a program terminates
- * through the normal dos terminate gate. (Not necessary if program is
- * terminates and stays resident)
- *
- * SIDE EFFECTS
- * If not executed interrupts remain "hot", if application using interrupts
- * exits releasing it's memory space to dos and another program is later
- * loaded followed by activity on the serial port serious "hurricanes" can
- * occur.
- *
- * RETURNS
- *
- * Value Meaning
- * ------- --------
- * ASSUCCESS port shut down successfully
- * ASINVPORT Requested port is out of range
- * ASNOTSETUP Requested port not setup with asifirst()
- *
- * MODIFICATIONS
- * 03-FEB-1987 11:27:24.68
- * Added code to de-allocate as_chnl 's memory and reset it to a
- * NULL pointer when the last port has been shut down. It is
- * not necessary to do another _asregister() at this point because
- * all I/O activity with all ports has been disabled.
- * 09-MAR-1987 10:07:51.66
- * changed static int _asidown() to int _asidown() for HIGH-C
- *
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "gf.h"
- #include "asiports.h"
-
-
- int GF_CONV asiquit(port)
- int port;
- {
-
- if(port==-1)
- for(port=0;port<MAX_PORT;++port)
- _asidown(port);
- else
- return(_asidown(port));
- return(ASSUCCESS);
- }
-
-
-
- int GF_CONV _asidown(port)
- int port;
- {
- extern int _aserror;
- int latch,i;
- struct PORT_TABLE *p;
-
- if((p=_aschkcnl(port))==NULL)
- return(_aserror);
-
- /****************************************************************
- * Look to see if any other ports using the same interrupt *
- * number are still not quit. If so, pass a 0 as the first *
- * arg to _asiquit() to tell it to avoid hitting the 8259A and *
- * to avoid restoring the interrupt vector as yet. *
- ****************************************************************/
- latch = 1;
- for(i=0;i<=(MAX_PORT-1);i++) {
- if((i!=port)&&(as_chnl->tblport[i].ptb!=NULL)) {
- if(as_chnl->tblport[i].ptb->intrpt_num==
- as_chnl->tblport[port].ptb->intrpt_num)
- latch = 0;
- }
- }
-
- /****************************************************************
- * If latch = 1 than no other port uses same intr number, so *
- * the 8259A and vector will be restored. *
- * Otherwise, one or more other ports that have not yet been *
- * "quit" use the same vector number, so don't mess with it. *
- ****************************************************************/
- _asiquit(latch,p);
- free(p->rx_buffer);
- free(p->tx_buffer);
- free((char *) p);
- as_chnl->tblport[port].ptb=NULL;
- if(_asoprt) {
- --_asoprt;
- if(!_asoprt) {
- free((char *)as_chnl);
- as_chnl=(struct TABLEPORT *)0;
- }
- }
- return(ASSUCCESS);
- }
-
- void GF_CDECL _asiexit_routine(void)
- {
- asiquit(-1);
- }
-
-
-