home *** CD-ROM | disk | FTP | other *** search
/ nisttime.carsoncity.k12.mi.us / nisttime.carsoncity.k12.mi.us.tar / nisttime.carsoncity.k12.mi.us / pub / lockclock / inilin_l.c < prev    next >
C/C++ Source or Header  |  1996-11-18  |  5KB  |  163 lines

  1. void inilin_l()
  2. {
  3. /*
  4.         the IBM_PC version of this subroutine initializes the com 
  5.     port defined by global cmport (0=com1, 1=com2, ... etc).
  6.         the initialization parameters are set using param
  7.  
  8.         if BIOS is not defined, do not use bios calls but access the
  9.         hardware directly.  this is done by determining the hardware
  10.         address of the comport by looking in low core locations.
  11.  
  12.     the SUN version of this subroutine initializes the comport
  13.     based on the device string dv which is defined in getdif.h
  14. */
  15. #include <stdio.h>
  16. #include "getdif.h"
  17. #ifdef IBMPC
  18. #include <dos.h>
  19. char param;
  20. void wait1s();        /*wait for DSR to come true */
  21. void lockerr();        /*prints message to file and exits*/
  22. #endif
  23. int j;
  24. #ifdef SUN
  25. #include <sys/file.h>
  26. #include <fcntl.h>
  27. #include <sgtty.h>
  28. struct sgttyb blah,*arg;     /* parameters used for ioctl calls */
  29.     arg= &blah;           /* blah is structure */
  30.     if( (cmport=open(dv,O_RDWR | O_NDELAY)) <0)
  31.        lockerr(" inilin -- cannot open serial port.");
  32.     if(hs == 1)
  33.        {
  34.         arg->sg_ispeed=B1200;
  35.         arg->sg_ospeed=B1200;
  36.        }
  37.     else
  38.        {
  39.        arg->sg_ispeed=B300;
  40.        arg->sg_ospeed=B300;
  41.        }
  42.     arg->sg_erase='\177';
  43.     arg->sg_kill='\025';
  44.     arg->sg_flags=RAW;
  45.     j=ioctl(cmport,TIOCSETP,arg);
  46.     if(j != 0) lockerr("inilin --  ioctl status error");
  47. #endif
  48. #ifdef IBMPC
  49. unsigned char stat;
  50. #endif
  51. /*
  52.     operation of the IBMPC version:
  53.  
  54.         if this is the direct access version of the program, then the
  55.         hardware address of the comport must be either specified in the
  56.         configuration file or determined by looking in low memory.  if
  57.         it was specified in the configuration file, then cmport was set
  58.         to -1 there and cmadr was read from line 6.  in that case we
  59.         don't have to do anything here.  if cmadr is positive, then
  60.         the value must be determined here by looking at the table starting
  61.         at address 400 (hex).
  62.         following variables and code are used to look in low memory
  63.         to get the address of the comport requested in the config. file
  64.         if the address in low memory is zero, then exit with an error.
  65.         since the line printer addresses are stored just after the tty
  66.         port addresses, these variables are also used for getting the
  67.         hardware address of lpt1 (see below)
  68. */
  69. #ifdef IBMPC
  70. unsigned int ttyseg = 0x40;
  71. unsigned int ttyoff =    0;
  72. int far *cmptr;
  73. #ifndef BIOS
  74. /*
  75.         first get hardware address of requested comport if necessary
  76.         these address are stored starting at 400.  if cmport is -1,
  77.         then the address was already gotten by setcfg from the configuration
  78.         file and we don't have to do that here.
  79. */
  80.         if(cmport >= 0)
  81.         {
  82.         ttyoff=2*cmport;
  83.         cmptr=MK_FP(ttyseg,ttyoff);
  84.         cmadr=*cmptr;
  85.         if(cmadr == 0)
  86.        lockerr("inilin -- comport not in configuration.");  
  87.     }
  88. /*
  89.         disable interrupts, turn on DTR and RTS, then
  90.         set 8 bits, no parity, 1 stop bit, Div. Latch Acc Bits on
  91. */
  92.         param=0;
  93.         outportb(cmadr+intena,param);
  94.         param=3;
  95.         outportb(cmadr+modreg,param);
  96.         param='\x83';
  97.         outportb(cmadr+lcreg,param);
  98. /*
  99.         now set requested speed using two halves of divisor
  100.         from tables in interface manual
  101. */
  102.         if(hs == 1)
  103.            {
  104.            param=96;
  105.            outportb(cmadr+divlsb,param);
  106.            param=0;
  107.            outportb(cmadr+divmsb,param);
  108.            }
  109.         else
  110.            {
  111.            param='\x80';
  112.            outportb(cmadr+divlsb,param);
  113.            param=1;
  114.            outportb(cmadr+divmsb,param);
  115.            }
  116. /*
  117.         now turn off divisor latch access bits
  118. */
  119.         param=3;
  120.         outportb(cmadr+lcreg,param);
  121.         wait1s();
  122.         wait1s();
  123.         wait1s();        /*wait for ROLM system to wake up*/
  124. /*
  125.         get modem status
  126. */
  127.         stat=inportb(cmadr+msreg);
  128. #endif
  129. #ifdef BIOS
  130. /*
  131.         if we get here then we are going to do the same stuff using
  132.         BIOS calls. the parameters are:
  133.  
  134.         300 baud        no parity       1 stop bit      8 bits
  135.         0 1 0           0 0             0               1 1
  136.  
  137.         1200 baud       no parity       1 stop bit      8 bits
  138.         1 0 0           0 0             0               1 1
  139.  
  140.         9600 baud       no parity       1 stop bit      8 bits
  141.         1 1 1           0 0             0               1 1
  142. */
  143.         if(hs == 1)param='\x83';
  144.         else       param='\x43';
  145.         _AL=param;
  146.         _AH=0;
  147.         _DX=cmport;
  148.         geninterrupt(0x14);
  149.         stat=_AL;           /* return with modem status  */
  150. #endif
  151. /*
  152.         if this is automatic dialing using either manual or pulse mode
  153.         then be sure that the modem is ready to go.  check DSR
  154. */
  155.         if( (number[3] == 't') || (number[3] == 'T') ||
  156.             (number[3] == 'p') || (number[3] == 'P') )
  157.         {
  158.         if( (stat & 0x20) == 0)
  159.            lockerr("inilin --  modem does not show DSR");
  160.         }
  161. #endif
  162. }
  163.