home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / DEV / PCMCIA / CLDFM / COMPORT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-14  |  6.1 KB  |  251 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 = COMPORT.C
  15.  *
  16.  * DESCRIPTIVE NAME =
  17.  *
  18.  *
  19.  * VERSION =
  20.  *
  21.  * DATE
  22.  *
  23.  * DESCRIPTION
  24.  *
  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.    /*
  44.    ** include files
  45.    */
  46. #include "types.h"
  47. #include "comport.h"
  48. #include "config.h"
  49.  
  50.  
  51. #define BIOS_PORT_DATA_AREA  0x00400000
  52. #define BIOS_INSTALLED_HDWR_AREA 0x00400010
  53.  
  54.    /*
  55.    ** external global variables
  56.    */
  57. extern CONFIG_INFO Config_info;
  58.  
  59.    /*
  60.    ** private global variables
  61.    */
  62. static USHORT Com_data[MAX_NUM_IO_ADDRESSES] = {0, 0, 0, 0};
  63.  
  64.  
  65. /****************************************************************************
  66.  *
  67.  * FUNCTION NAME = acquire_com_port
  68.  *
  69.  * DESCRIPTION   = This function checks for the availability of an io
  70.  *                 address associated with a com port.  If the address
  71.  *                 is available then the function reserves it.
  72.  *                 The parameter 'io_address' contains the address to
  73.  *                 check and reserve.
  74.  *
  75.  * INPUT         =
  76.  *
  77.  * OUTPUT        = The function returns the value -1 if the address is not
  78.  *                 available. Otherwise, the value 0 is returned.
  79.  *
  80.  * RETURN-NORMAL =
  81.  *
  82.  * RETURN-ERROR  =
  83.  *
  84.  ****************************************************************************/
  85.  
  86. short acquire_com_port(USHORT io_address)
  87.  
  88.  
  89. {
  90.     USHORT *memP, count;
  91.     USHORT far *bios_memP;
  92.     USHORT i;
  93.  
  94.         /* search local data area  for i/o address
  95.         **  - return failure if the address is taken or the data area is full
  96.         */
  97.     memP = Com_data;
  98.     i = 0;
  99.     while (1)
  100.     {
  101.         if (i >  Config_info.num_of_io_addresses - 1)
  102.             return(-1);
  103.         if (*memP == io_address)
  104.             return(-1);
  105.         if (*memP == 0)
  106.             break;
  107.         memP++;
  108.         i++;
  109.     }
  110.  
  111.         /* search bios data area  for i/o address
  112.         ** - return failure if the address is taken or if the data area is full
  113.         */
  114.     bios_memP = (USHORT far *) BIOS_PORT_DATA_AREA;
  115.     i = 0;
  116.     while (1)
  117.     {
  118.         if (i > Config_info.num_of_io_addresses - 1)
  119.             return(-1);
  120.         if (*bios_memP == io_address)
  121.             return(-1);
  122.         if (*bios_memP == 0)
  123.             break;
  124.         bios_memP++;
  125.         i++;
  126.     }
  127.  
  128.         /* address is available - store it
  129.         */
  130.     *memP = io_address;
  131.     *bios_memP = io_address;
  132.  
  133.         /* increment the number of rs232c adapters
  134.         */
  135.     bios_memP = (USHORT far *)  BIOS_INSTALLED_HDWR_AREA;
  136.     count = (*bios_memP >> 9) & 0x07;
  137.     count++;
  138.     count <<= 9;
  139.     *bios_memP &= 0xf1ff;
  140.     *bios_memP |= count;
  141.  
  142.         /* return success
  143.         */
  144.     return(0);
  145. }
  146.  
  147. /****************************************************************************
  148.  *
  149.  * FUNCTION NAME = release_com_port
  150.  *
  151.  * DESCRIPTION   = This function releases the io address associated with
  152.  *                 a com port.
  153.  *                 The parameter 'io_address' is the io address to release.
  154.  *
  155.  * INPUT         = NONE
  156.  *
  157.  * OUTPUT        = NONE
  158.  *
  159.  * RETURN-NORMAL = NONE
  160.  *
  161.  * RETURN-ERROR  = NONE
  162.  *
  163.  ****************************************************************************/
  164.  
  165. void release_com_port(USHORT io_address)
  166.  
  167. {
  168.     USHORT *memP;
  169.     USHORT far *bios_memP;
  170.     USHORT i, count;
  171.  
  172.         /* search local data area  for i/o address
  173.         **     - return if  the address is not found
  174.         */
  175.     memP = Com_data;
  176.     i = 0;
  177.     while (1)
  178.     {
  179.         if (i > Config_info.num_of_io_addresses - 1)
  180.             return;
  181.         if (*memP == io_address)
  182.         {
  183.             *memP = 0;
  184.             break;
  185.         }
  186.         if (*memP == 0)
  187.             return;
  188.         memP++;
  189.         i++;
  190.     }
  191.  
  192.         /* move the entries down
  193.         */
  194.     memP = Com_data;
  195.     for (i = 0; i <= Config_info.num_of_io_addresses - 2; i++)
  196.     {
  197.         if (*memP == 0)
  198.         {
  199.             *memP = *(memP + 1);
  200.             *(memP + 1) = 0;
  201.         }
  202.         memP++;
  203.     }
  204.  
  205.         /* search bios data area for i/o address
  206.         **     -  return if the address is not found
  207.         */
  208.     bios_memP = (USHORT far *) BIOS_PORT_DATA_AREA;
  209.     i = 0;
  210.     while (1)
  211.     {
  212.         if (i > Config_info.num_of_io_addresses - 1)
  213.             return;
  214.         if (*bios_memP == io_address)
  215.         {
  216.             *bios_memP = 0;
  217.             break;
  218.         }
  219.         if (*bios_memP == 0)
  220.             return;
  221.         bios_memP++;
  222.         i++;
  223.     }
  224.  
  225.         /* move the entries down
  226.         */
  227.     bios_memP = (USHORT far *) BIOS_PORT_DATA_AREA;
  228.     for (i = 0; i <= Config_info.num_of_io_addresses - 2; i++)
  229.     {
  230.         if (*bios_memP == 0)
  231.         {
  232.             *bios_memP = *(bios_memP + 1);
  233.             *(bios_memP + 1) = 0;
  234.         }
  235.         bios_memP++;
  236.     }
  237.  
  238.         /* decrement the number of rs232c adapters
  239.         */
  240.     bios_memP = (USHORT far *)  BIOS_INSTALLED_HDWR_AREA;
  241.     count = (*bios_memP >> 9) & 0x07;
  242.     count--;
  243.     count <<= 9;
  244.     *bios_memP &= 0xf1ff;
  245.     *bios_memP |= count;
  246.  
  247.         /* done
  248.         */
  249.     return;
  250. }
  251.