home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PCL4C43.ZIP / SELFTEST.C (.txt) < prev    next >
Text File  |  1995-04-17  |  6KB  |  204 lines

  1. /*
  2. **                ---  selftest.c ---
  3. **
  4. **  SELFTEST requires two serial ports on the same computer. The
  5. **  program transmits a test string on one port (FirstCOM) and
  6. **  receives on a second port (SecondCOM), where the two ports are
  7. **  connected via a null modem adapter. The received string is tested
  8. **  against the transmit string (they should be idenical).
  9. **
  10. **  Connect the two serial ports (on a single computer) together
  11. **  using a null modem cable. Be sure to modify the configuration
  12. **  section for non-standard PC ports or to setup your multiport
  13. **  board. Note that many multiport boards are either Digiboard or
  14. **  BOCA board compatible.
  15. **
  16. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <malloc.h>
  21. #include <dos.h>
  22. #include <string.h>
  23. #include "pcl4c.h"
  24.  
  25. #define FALSE 0
  26. #define TRUE !FALSE
  27. #define ESC 0x1b
  28.  
  29. /*** Global Variables ***/
  30.  
  31. int BaudCode = Baud9600;  /* Code for 9600 baud  */
  32. char *TestString = "This is a test string";
  33. int TestLength;
  34. int FirstCOM;
  35. int SecondCOM;
  36.  
  37. int ErrorCheck(int);
  38. int AllocSeg(int);
  39.  
  40. char *Ptr[4] = {"SMALL","COMPACT","MEDIUM","LARGE"};
  41. /*** Main ***/
  42.  
  43. #define PC 1
  44. #define DB 2
  45. #define BB 3
  46.  
  47. void main(int argc, char *argv[])
  48. {int Port;
  49.  char *P;
  50.  int ComLimit = 0;
  51.  char c;
  52.  int TheSwitch = 0;
  53.  int Version;
  54.  int Model;
  55.  int i, rc;
  56.  if(argc!=4)
  57.   {printf("Usage: selftest {pc|db|bb} 1stCom 2ndCom\n");
  58.    exit(1);
  59.   }
  60.  puts("*** SELFTEST 3.0");
  61.  Version = SioInfo('V');
  62.  Model = SioInfo('M');
  63.  printf("*** Lib Ver : %d.%d\n",Version/16,Version%16);
  64.  printf("***   Model : %s \n", Ptr[Model&3] );
  65.  printf("*** TX Intr : ");
  66.  if(SioInfo('I')) puts("enabled.");
  67.  else puts("not enabled.");
  68.  P = argv[1];
  69.  if((strcmp(P,"pc")==0)||(strcmp(P,"PC")==0)) TheSwitch = PC;
  70.  if((strcmp(P,"db")==0)||(strcmp(P,"DB")==0)) TheSwitch = DB;
  71.  if((strcmp(P,"bb")==0)||(strcmp(P,"BB")==0)) TheSwitch = BB;
  72.  if(TheSwitch==0)
  73.    {puts("Must specify 'PC', 'DB' or 'BB' as 1st argument");
  74.     puts("EG:  SELFTEST PC 1 4");
  75.     exit(1);
  76.    }
  77.  if(TheSwitch==PC) ComLimit = COM4;
  78.  if(TheSwitch==DB) ComLimit = COM8;
  79.  if(TheSwitch==BB) ComLimit = COM16;
  80.  FirstCOM = atoi(argv[2]) -1;
  81.  SecondCOM = atoi(argv[3]) -1;
  82.  printf("FirstCOM  = COM%d\n",1+FirstCOM);
  83.  printf("SecondCOM = COM%d\n",1+SecondCOM);
  84.  if(FirstCOM<COM1)
  85.    {puts("1stCom must be >= COM1");
  86.     exit(1);
  87.    }
  88.  if(SecondCOM>ComLimit)
  89.    {printf("2ndCom must be <= COM%d\n",1+ComLimit);
  90.     exit(1);
  91.    }
  92.  if(FirstCOM>=SecondCOM)
  93.    {puts("1stCom must be < 2ndCom");
  94.     exit(1);
  95.    }
  96.  if(TheSwitch==DB)
  97.    {/*** Custom Configuration: DigiBoard PC/8 ***/
  98.     puts("[ Configuring for DigiBoard PC/8 (IRQ5) ]");
  99.     SioPorts(8,COM1,0x140,DIGIBOARD);
  100.     for(Port=COM1;Port<=COM8;Port++)
  101.       {/* set DigiBoard UART addresses */
  102.        ErrorCheck( SioUART(Port,0x100+8*Port) );
  103.        /* set DigiBoard IRQ */
  104.        ErrorCheck( SioIRQ(Port,IRQ5) );
  105.       }
  106.    }
  107.  if(TheSwitch==BB)
  108.    {/*** Custom Configuration: BOCA BB2016 ***/
  109.     puts("[ Configuring for BOCA Board BB2016 (IRQ15) ]");
  110.     SioPorts(16,COM1,0x107,BOCABOARD);
  111.     for(Port=COM1;Port<=COM16;Port++)
  112.       {/* set BOCA Board UART addresses */
  113.        ErrorCheck( SioUART(Port,0x100+8*Port) );
  114.        /* set BOCA Board IRQ */
  115.        ErrorCheck( SioIRQ(Port,IRQ15) );
  116.       }
  117.    }
  118.  if(TheSwitch==PC)
  119.    {/*** Custom Configuration: 4 port card ***/
  120.     puts("[ Configuring for PC ]");
  121.     SioIRQ(COM1,IRQ4);
  122.     SioIRQ(COM2,IRQ3);
  123.     SioIRQ(COM3,IRQ4);
  124.     SioIRQ(COM4,IRQ3);
  125.    }
  126.  /* setup transmit & receive buffer */
  127.  ErrorCheck( SioRxBuf(FirstCOM,AllocSeg(128),Size128) );
  128.  ErrorCheck( SioRxBuf(SecondCOM,AllocSeg(128),Size128) );
  129.  if(SioInfo('I'))
  130.    {ErrorCheck( SioTxBuf(FirstCOM,AllocSeg(128),Size128) );
  131.     ErrorCheck( SioTxBuf(SecondCOM,AllocSeg(128),Size128) );
  132.     printf("Transmit buffers created\n");
  133.    }
  134.  /* set port parmameters */
  135.  ErrorCheck( SioParms(FirstCOM,NoParity,OneStopBit,WordLength8) );
  136.  ErrorCheck( SioParms(SecondCOM,NoParity,OneStopBit,WordLength8) );
  137.  /* use 16650 FIFO if present */
  138.  printf("***   COM%d : ",1+FirstCOM);
  139.  if( SioFIFO(FirstCOM,LEVEL_8) ) printf("16550\n");
  140.  else printf("8250/16450\n");
  141.  printf("***   COM%d : ",1+SecondCOM);
  142.  if( SioFIFO(SecondCOM,LEVEL_8) ) printf("16550\n");
  143.  else printf("8250/16450\n");
  144.  /* reset the ports */
  145.  ErrorCheck( SioReset(FirstCOM,BaudCode) );
  146.  ErrorCheck( SioReset(SecondCOM,BaudCode) );
  147.  
  148.  printf("Start selftest @ 9600 baud\n");
  149.  
  150.  TestLength = strlen(TestString);
  151.  /* send string */
  152.  printf("  Sending: ");
  153.  for(i=0;i<TestLength;i++)
  154.    {c = TestString[i];
  155.     SioPutc(FirstCOM,c);
  156.     SioCrtWrite(c);
  157.    }
  158.  /* receive string */
  159.  printf("\nReceiving: ");
  160.  for(i=0;i<TestLength;i++)
  161.    {rc = SioGetc(SecondCOM,18);
  162.     if(rc<0)
  163.       {printf("\nERROR: ");
  164.        SioError(rc);
  165.        SioDone(FirstCOM);
  166.        SioDone(SecondCOM);
  167.        exit(1);
  168.       }
  169.     /* echo just received char */
  170.     SioCrtWrite((char)rc);
  171.     /* compare character */
  172.     if((char)rc!=TestString[i])
  173.       {printf("\nERROR: Expecting '%c', received '%c'\n");
  174.        SioDone(FirstCOM);
  175.        SioDone(SecondCOM);
  176.        exit(2);
  177.       }
  178.    } /* end for */
  179.  puts("\nSUCCESS: Test AOK !");
  180.  SioDone(FirstCOM);
  181.  SioDone(SecondCOM);
  182. } /* end main */
  183.  
  184. int ErrorCheck(int Code)
  185. {/* trap PCL error codes */
  186.  if(Code<0)
  187.      {SioError(Code);
  188.       SioDone(FirstCOM);
  189.       SioDone(SecondCOM);
  190.       exit(1);
  191.      }
  192.  return(0);
  193. } /* end ErrorCheck */
  194.  
  195. int AllocSeg(int Size)
  196. {int Seg;
  197.  char far *Ptr;
  198.  /* allocate far heap */
  199.  Ptr = (char far *) _fmalloc(Size+16);
  200.  if(Ptr==NULL) return 0;
  201.  /* SEG:0 points to buffer */
  202.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  203.  return Seg;
  204. }