Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

pcioDrv.c

Go to the documentation of this file.
00001 /************************************************************
00002   File: pcioDrv.c
00003 
00004   Author: Steven Legowik
00005 
00006   Description:
00007   Provides an easy to use interface to the pcio device
00008   driver.
00009 
00010   For improved compatability with the old io access functions
00011   (declared in pcio.h) and ease of use, I have rewritten the input and
00012   output operations to make use of the pcio device driver.  If you use
00013   this interface you will only have to change the include file to
00014   pcioDrv.h (from pcio.h).  All the rest of the code should remain
00015   unchanged.  The input and output routines make use of a global file
00016   descriptor initialize by pcioInit() in ioctl() calls to the driver.
00017   To used this interface to the driver pcioDrv.o must be linked into the
00018   application and pcioDrv.h must be included wherever the driver is
00019   accessed.
00020 
00021   Modification history:
00022 
00023   19-Apr-1995  Fred Proctor reported error when driver not installed
00024   7-Mar-1995  Fred Proctor removed #include <oscalls.h>, since this
00025   is obsolete in 2.2.2 .
00026   21-Dec-1994  Fred Proctor added check for 0 file descriptor
00027   in read, write calls, and called pcioInit() implicitly. This
00028   removes the need for users to call pcioInit() directly.
00029   ??? Steve Legowik created
00030 
00031 ************************************************************/
00032 
00033 #include <stdio.h>              /* fprintf(), stderr */
00034 #include "pcioDrv.h"
00035 #include "iodev.h"
00036 
00037 static int pcioDrvId = 0;       /* global pcio device descriptor */
00038 
00039 /* initialize global pcio device descriptor */
00040 void
00041   pcioInit()
00042 {
00043   if ((pcioDrvId = open("/dev/pcio", 0)) < 0)
00044   {
00045     fprintf(stderr, "pcioInit: can't open /dev/pcio");
00046   }
00047 }
00048 
00049 unsigned char
00050   inputb( unsigned short port )
00051 {
00052   struct _ioValStruct arg;
00053   arg.address = port;
00054   if (0 == pcioDrvId)
00055     pcioInit();
00056   ioctl( pcioDrvId, READ_8, &arg );
00057   return arg.value;
00058 }
00059 
00060 void
00061   outputb( unsigned short port, unsigned char data )
00062 {
00063   struct _ioValStruct arg;
00064   arg.address = port;
00065   arg.value = data;
00066   if (0 == pcioDrvId)
00067     pcioInit();
00068   ioctl( pcioDrvId, WRITE_8, &arg );
00069 }
00070 
00071 unsigned short
00072   inputw( unsigned short port )
00073 {
00074   struct _ioValStruct arg;
00075   arg.address = port;
00076   if (0 == pcioDrvId)
00077     pcioInit();
00078   ioctl( pcioDrvId, READ_16, &arg );
00079   return arg.value;
00080 }
00081 
00082 void
00083   outputw( unsigned short port, unsigned short data )
00084 {
00085   struct _ioValStruct arg;
00086   arg.address = port;
00087   arg.value = data;
00088   if (0 == pcioDrvId)
00089     pcioInit();
00090   ioctl( pcioDrvId, WRITE_16, &arg );
00091 }
00092 
00093 unsigned long
00094   inputl( unsigned short port )
00095 {
00096   struct _ioValStruct arg;
00097   arg.address = port;
00098   if (0 == pcioDrvId)
00099     pcioInit();
00100   ioctl( pcioDrvId, READ_32, &arg );
00101   return arg.value;
00102 }
00103 
00104 void
00105   outputl( unsigned short port, unsigned long data )
00106 {
00107   struct _ioValStruct arg;
00108   arg.address = port;
00109   arg.value = data;
00110   if (0 == pcioDrvId)
00111     pcioInit();
00112   ioctl( pcioDrvId, WRITE_32, &arg );
00113 }

Generated on Sun Dec 2 15:56:51 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001