home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / PCMCIA / CLDFM / CONFIG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  7.1 KB  |  215 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /**************************************************************************
  13.  *
  14.  * SOURCE FILE NAME = CONFIG.C
  15.  *
  16.  * DESCRIPTIVE NAME =
  17.  *
  18.  *
  19.  * VERSION =
  20.  *
  21.  * DATE
  22.  *
  23.  * DESCRIPTION This file contains routines that process and store configuration
  24.  *             info for the system.
  25.  *
  26.  * FUNCTIONS
  27.  *
  28.  * ENTRY POINTS:
  29.  *
  30.  * DEPENDENCIES:
  31.  *
  32.  * NOTES
  33.  *
  34.  *
  35.  * STRUCTURES
  36.  *
  37.  * EXTERNAL REFERENCES
  38.  *
  39.  * EXTERNAL FUNCTIONS
  40.  *
  41. */
  42.  
  43. #include "types.h"
  44. #include "config.h"
  45.  
  46.     /*
  47.     ** private function prototypes
  48.     */
  49. short store_socket_assignments(char far *, USHORT far *,
  50.                                USHORT far *, USHORT, USHORT);
  51.  
  52.     /*
  53.     ** external global variables
  54.     */
  55. CONFIG_INFO Config_info;
  56.  
  57.  
  58. /****************************************************************************
  59.  *
  60.  * FUNCTION NAME = store_config_info
  61.  *
  62.  * DESCRIPTION   = This function checks the syntax of the command line
  63.  *                 arguments and stores configuration information.
  64.  *                 The parameter 'argc' contains the number of arguments
  65.  *                 on the command line and the parameter 'argv' contains a
  66.  *                 pointer to an array of pointers to null terminated ascii
  67.  *                 strings containing the arguments.
  68.  *                 The function returns 0 if successful. Otherwise, a value
  69.  *                 less than 0 is returned indicating the error condition.
  70.  *
  71.  * INPUT         =
  72.  *
  73.  * OUTPUT        =
  74.  *
  75.  * RETURN-NORMAL =
  76.  *
  77.  * RETURN-ERROR  =
  78.  *
  79.  ****************************************************************************/
  80.  
  81. short store_config_info(short argc, char **argv,  USHORT num_of_sockets)
  82. {
  83.     USHORT i;
  84.     USHORT io_address[MAX_NUM_IO_ADDRESSES];
  85.     USHORT irq_num[MAX_NUM_IO_ADDRESSES];
  86.  
  87.         /* set up default modem type - intel compatable - isa bus - no
  88.         ** socket assignments
  89.         */
  90.     for (i = 0; i <= MAX_NUM_IO_ADDRESSES - 1; i++)
  91.     {
  92.         Config_info.com_port_num[i] = 0;
  93.         Config_info.io_address[i] = 0;
  94.         Config_info.irq_num[i] = 0;
  95.     }
  96.  
  97.         /* get io addresses and irq numbers based on bus type
  98.         */
  99.     io_address[0] = 0x3f8;
  100.     irq_num[0] = 4;
  101.     io_address[1] = 0x2f8;
  102.     irq_num[1] = 3;
  103.     io_address[2] = 0x3e8;
  104.     irq_num[2] = 4;
  105.     io_address[3] = 0x2e8;
  106.     irq_num[3] = 3;
  107.     Config_info.num_of_io_addresses = 4;
  108.  
  109.         /* get io addresses and irq numbers based on bus type
  110.         */
  111.     io_address[0] = 0x3f8;
  112.     irq_num[0] = 4;
  113.     io_address[1] = 0x2f8;
  114.     irq_num[1] = 3;
  115.     io_address[2] = 0x3e8;
  116.     irq_num[2] = 4;
  117.     io_address[3] = 0x2e8;
  118.     irq_num[3] = 3;
  119.     Config_info.num_of_io_addresses = 4;
  120.  
  121.         /* return failure if too many or too few arguments
  122.         */
  123.     if ((argc != 2))
  124.         return(-1);
  125.  
  126.         /* store socket assignment info
  127.         */
  128.     return(store_socket_assignments((char far *) argv[1],
  129.                                     (USHORT far *) io_address,
  130.                                     (USHORT far *) irq_num,
  131.                                     Config_info.num_of_io_addresses,
  132.                                     num_of_sockets));
  133. }
  134.  
  135. /****************************************************************************
  136.  *
  137.  * FUNCTION NAME = short store_socket_assignments
  138.  *
  139.  * DESCRIPTION   = This function stores io address, irq number, and com port
  140.  *                 number information based on the information in the socket
  141.  *                 socket assignment string.
  142.  *                 The parameter 'strP' contains a pointer to a null terminated
  143.  *                 string containing the socket assignment information. The
  144.  *                 parameter 'io_addressP' is the address of an array containing
  145.  *                 i/o addresses for the present configuration. The parameter
  146.  *                 'irq_numP' is the address of an array containing the irq
  147.  *                 numbers for the present configuratuion. The parameter
  148.  *                 'num_of_io_addresses' contains the number of io addresses
  149.  *                 for the present configuration.
  150.  *                 The function returns 0 if successful. Otherwise, a value
  151.  *                 less than 0 is returned indicating the error condition.
  152.  *
  153.  * INPUT         =
  154.  *
  155.  * OUTPUT        =
  156.  *
  157.  * RETURN-NORMAL =
  158.  *
  159.  * RETURN-ERROR  =
  160.  *
  161.  ****************************************************************************/
  162.  
  163. static short store_socket_assignments(char far *strP,
  164.                                       USHORT far *io_addressP,
  165.                                       USHORT far *irq_numP,
  166.                                       USHORT num_of_io_addresses,
  167.                                       USHORT num_of_sockets)
  168.  
  169. {
  170.     USHORT i, socket_num, com_port_num;
  171.  
  172.     while (1)
  173.     {
  174.         for (i = 1; i <= 4; i++)
  175.         {
  176.             switch (i)
  177.             {
  178.                 case 1:
  179.                     if ((*strP != 'S') && (*strP != 's'))
  180.                         return(-1);
  181.                     strP++;
  182.                     break;
  183.                 case 2:
  184.                     socket_num = *strP - '0';
  185.                     if ((socket_num < 1) || (socket_num > num_of_sockets))
  186.                         return(-1);
  187.                     strP++;
  188.                     break;
  189.                 case 3:
  190.                     if ((*strP != 'C') && (*strP != 'c'))
  191.                         return(-1);
  192.                     strP++;
  193.                     break;
  194.                 case 4:
  195.                     com_port_num = *strP - '0';
  196.                     if ((com_port_num < 1) ||
  197.                                 (com_port_num > num_of_io_addresses))
  198.                         return(-1);
  199.                     Config_info.com_port_num[socket_num - 1] = com_port_num;
  200.                     Config_info.io_address[socket_num - 1] =
  201.                                           *(io_addressP + com_port_num - 1);
  202.                     Config_info.irq_num[socket_num - 1] =
  203.                                           *(irq_numP + com_port_num - 1);
  204.                     strP++;
  205.                     break;
  206.             }
  207.         }
  208.         if (*strP == '\0')
  209.             return(0);
  210.         if (*strP != ',')
  211.             return(-1);
  212.         strP++;
  213.     }
  214. }
  215.