parport.c

Go to the documentation of this file.
00001 //
00002 // PARPORT.C
00003 //
00004 // Handles all access to the parallel port
00005 //
00006 // Copyright (c) 2002, Jason Riffel - TotalEmbedded LLC.
00007 // All rights reserved.
00008 //
00009 // Redistribution and use in source and binary forms, with or without 
00010 // modification, are permitted provided that the following conditions 
00011 // are met:
00012 //
00013 // Redistributions of source code must retain the above copyright 
00014 // notice, this list of conditions and the following disclaimer. 
00015 //
00016 // Redistributions in binary form must reproduce the above copyright
00017 // notice, this list of conditions and the following disclaimer in 
00018 // the documentation and/or other materials provided with the
00019 // distribution. 
00020 //
00021 // Neither the name of TotalEmbedded nor the names of its 
00022 // contributors may be used to endorse or promote products derived 
00023 // from this software without specific prior written permission.
00024 // 
00025 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00026 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00027 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
00028 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
00029 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00030 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
00031 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00032 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00033 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00034 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
00035 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00036 // POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 
00039 //
00040 // INCLUDES
00041 //
00042 #include <errno.h>
00043 #include <signal.h>
00044 #include <stdio.h>
00045 #include <unistd.h>
00046 #include <sys/time.h>
00047 #include <sys/types.h>
00048 #include <sys/socket.h>
00049 #include <sys/wait.h>
00050 #include <netinet/in.h>
00051 #include <netdb.h>
00052 #include <err.h>
00053 //#include <machine/pio.h>
00054 //#include <machine/sysarch.h>
00055 #include <sys/io.h>
00056 #include "parport.h"
00057 
00058 //
00059 // DEFINES
00060 //
00061 // Port addresses
00062 #define dPARPORT_DATA    0x378
00063 #define dPARPORT_STATUS  0x379
00064 #define dPARPORT_CONTROL 0x37A
00065 
00066 //
00067 // PROTOTYPES
00068 //
00069 static inline void fPARPORT_SetAccess(u_long * map, u_int bit, int allow);
00070 
00071 //
00072 // fPARPORT_SetAccess
00073 //
00074 // Sets the direct access permissions for the parallel port
00075 //
00076 static inline void fPARPORT_SetAccess(u_long * map, u_int bit, int allow)
00077 {
00078   unsigned int  word;
00079   unsigned int  shift;
00080   unsigned long mask;
00081 
00082   word = bit / 32;
00083   shift = bit - (word * 32);
00084 
00085   mask = 0x000000001 << shift;
00086   if (allow)
00087     map[word] &= ~mask;
00088   else
00089     map[word] |= mask;
00090 }
00091 
00092 //
00093 // fPARPORT_Init
00094 //
00095 // Initializes the parallel port
00096 //
00097 void fPARPORT_Init(void)
00098 {
00099   unsigned long iomap[32];
00100         
00101         iopl(3);
00102         return;
00103 }
00104 
00105 //
00106 // fPARPORT_Write
00107 //
00108 // Writes a byte to the parallel port data register
00109 //
00110 void inline fPARPORT_Write(unsigned char uc_byte)
00111 {
00112   outb(uc_byte,dPARPORT_DATA);
00113   
00114   return;
00115 }
00116 
00117 //
00118 // fPARPORT_Read
00119 //
00120 // Read a byte from the parallel port status register
00121 //
00122 unsigned char inline fPARPORT_Read(void)
00123 {
00124   return(inb(dPARPORT_STATUS));
00125 }
00126 
00127 #include <cmdparser.h>
00128 
00129 static int ppcmd(int argc,char **argv)
00130 {
00131         int i;
00132 if (!strcmp(argv[0],"ppinit")) fPARPORT_Init();
00133 else if (!strcmp(argv[0],"ppread")) printf("0x%02x\n",fPARPORT_Read());
00134 else if (!strcmp(argv[0],"ppwrite")) {
00135         if (argc != 2) return -1;
00136         fPARPORT_Write(strtoul(argv[1],0,0));
00137  }
00138 return 0;       
00139 }
00140 
00141 mycmd_init(ppinit,ppcmd,"","init parport");
00142 mycmd_init(ppread,ppcmd,"","read parport");
00143 mycmd_init(ppwrite,ppcmd,"data","write parport");
00144 

Generated on Fri Nov 5 07:24:46 2010 for ejtag debug tools for loongson 232 cpu by  doxygen 1.5.6