home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "global.h"
- #include "mbuf.h"
- #include "internet.h"
- #include "iface.h"
- #include "cmdparse.h"
- #include "misc.h"
- #include "arc.h"
- #include "os.h"
- #include "swis.h"
- #include "driver.h"
-
- struct asy asy[ASY_MAX];
- unsigned int nasy;
- struct interface *ifaces;
-
- /* Called just before exiting to restore console state */
- void iostop(void)
- {
- while(ifaces != NULLIF)
- {
- if (ifaces->stop != NULLFP)
- (*ifaces->stop)(ifaces); /*hf pass ifaces not ifaces->dev otherwise we can't do it */
- ifaces = ifaces->next;
- }
- }
-
- int asy_scan(void)
- {
- struct interface *ifp;
- int state = NULL;
-
- ifp = ifaces;
-
- while(ifp != NULLIF)
- {
- if (ifp->driver == NULL)
- state |= 0x100;
- else
- state |= ((*ifp->driver)(DRIVER_MODEMCONTROL, ifp->subdevice) & 8);
- ifp = ifp->next;
- }
- return(state);
- }
-
- /* Initialize asynch port "dev" */
- int asy_init(int dev, struct interface *iface, unsigned int bufsize)
- {
- bufsize = bufsize;
-
- asy[dev].iface = iface;
- asy[dev].speed = 0;
- asy[dev].rxchars = 0;
- asy[dev].rxserviced = 0;
- asy[dev].txchars = 0;
- asy[dev].txoverruns = 0;
- asy[dev].txserviced = 0;
-
- /* Initialise port to 9600 Baud, 8 Bits etc */
- (*iface->driver)(DRIVER_INITIALISE,iface->subdevice);
- (*iface->driver)(DRIVER_WORDFORMAT,iface->subdevice,0);
- (*iface->driver)(DRIVER_CONTROLLINES,iface->subdevice,3);
- /* (*iface->driver)(DRIVER_FLOWCONTROL,iface->subdevice,1); */
-
- return (0);
- }
-
- int asy_stop(struct interface *interface)
- {
- time_t when;
- when = clock();
- /* Drop RTS/DTR */
- (*interface->driver)(DRIVER_CONTROLLINES,interface->subdevice,0);
- while(clock() - when < 100);
- (*interface->driver)(DRIVER_CONTROLLINES, interface->subdevice, 3);
- /* Closedown */
- (*interface->driver)(DRIVER_CLOSEDOWN,interface->subdevice);
- return(0);
- }
-
- /* Set asynch line speed */
- int asy_speed(int dev, int speed)
- {
- if (speed==0)
- return 0;
-
- if (dev >= nasy)
- return(-1);
-
- asy[dev].speed = speed;
-
- /* Set speed */
- (*asy[dev].iface->driver) (DRIVER_TXSPEED,asy[dev].iface->subdevice, speed);
- (*asy[dev].iface->driver) (DRIVER_RXSPEED,asy[dev].iface->subdevice, speed);
-
- /* Check it's been set */
- if ((*asy[dev].iface->driver) (DRIVER_RXSPEED,asy[dev].iface->subdevice,-1) != speed)
- {
- cwprintf(NULL, "asy_speed: Unknown speed (%d)\r\n", speed);
- return(-1);
- }
-
- return(0);
- }
-
- int asy_flowctrl(int dev, int mode)
- {
- if (mode > 1 || dev >= nasy)
- return(-1);
-
- (*asy[dev].iface->driver) (DRIVER_CONTROLLINES,asy[dev].iface->subdevice,3);
- (*asy[dev].iface->driver) (DRIVER_FLOWCONTROL,asy[dev].iface->subdevice,mode);
- return 0;
- }
-
-
- /* Send a buffer to serial transmitter */
- int asy_output(int dev, char *buf, register int cnt)
- {
- register struct asy *asyp;
- register int i;
-
- if (dev >= nasy)
- {
- cwprintf(NULL, "asy_output: invalid parameters\r\n");
- return(0);
- }
-
- for (i = 0; i < cnt && (*asy[dev].iface->driver)(DRIVER_PUTBYTE, asy[dev].iface->subdevice, *buf)==0; i++, buf++);
-
- asyp = asy + dev;
- asyp->txserviced++;
- asyp->txchars += i;
- if (i < cnt) asyp->txoverruns++;
-
- return(i);
- }
-
- /* Receive characters from asynch line
- * Returns count of characters read */
-
- int asy_recv(int dev, char *buf)
- {
- register int c;
-
- if (dev >= nasy)
- {
- cwprintf(NULL, "asy_recv: invalid parameters\r\n");
- return(0);
- }
-
- asy[dev].rxserviced++;
- if ((c = (*asy[dev].iface->driver)(DRIVER_GETBYTE,
- asy[dev].iface->subdevice)) >= 0)
- {
- *buf = c;
- asy[dev].rxchars++;
- return(-1);
- }
-
- return(0);
- }
-
- int asy_ioctl(struct interface *interface, int argc, char *argv[])
- {
- int n;
- if (argc < 1)
- {
- cwprintf(NULL, "%d\n\n", asy[interface->dev].speed);
- return 0;
- }
- n = asy_speed(interface->dev, atoi(argv[0]));
- if (n>=0 && argc>1)
- n = asy_flowctrl(interface->dev, atoi(argv[1]));
- return n;
- }
-
- int doasystat(int argc, char **argv)
- {
- struct asy *asyp;
-
- argc = argc;
- argv = argv;
-
- for (asyp = asy; asyp < asy + nasy; asyp++)
- {
- cwprintf(NULL, "interface %s:\r\n", asyp->iface->name);
- cwprintf(NULL, "RX: serviced: %8u chars: %8u\r\n",
- asyp->rxserviced,
- asyp->rxchars);
- cwprintf(NULL, "TX: serviced: %8u chars: %8u overruns: %8u\r\n",
- asyp->txserviced,
- asyp->txchars,
- asyp->txoverruns);
- }
-
- return(0);
- }
-