#include "parport.h"#include <stdio.h>Include dependency graph for parport.c:

Go to the source code of this file.
Defines | |
| #define | __attribute__(x) |
| #define | PARPORT_IO_WIDTH 3 |
Functions | |
| char | __attribute__ ((unused)) ident[]="$Id |
| int | ioperm (unsigned int addr, int width, int on) |
| unsigned char | inb (unsigned int port) |
| void | outb (unsigned char byte, unsigned int port) |
| int | pptDioInit (const char *stuff) |
| int | pptDioQuit () |
| int | pptDioMaxInputs () |
| int | pptDioMaxOutputs () |
| int | pptDioRead (int index, int *value) |
| int | pptDioCheck (int index, int *value) |
| int | pptDioWrite (int index, int value) |
| int | pptDioByteRead (int index, unsigned char *byte) |
| int | pptDioShortRead (int index, unsigned short *sh) |
| int | pptDioWordRead (int index, unsigned int *word) |
| int | pptDioByteWrite (int index, unsigned char byte) |
| int | pptDioShortWrite (int index, unsigned short sh) |
| int | pptDioWordWrite (int index, unsigned int word) |
| int | pptDioByteCheck (int index, unsigned char *byte) |
| int | pptDioShortCheck (int index, unsigned short *sh) |
| int | pptDioWordCheck (int index, unsigned int *word) |
|
|
|
|
|
|
|
|
Definition at line 34 of file parport.c. 00034 : parport.c,v 1.14 2001/10/10 17:35:46 wshackle Exp $";
00035
00036 /* set DO_IT FLAG for really writing, else don't do inb(), outb() */
00037 #ifdef LINUX
00038 #define DO_IT
00039 #else
00040 #if defined(rtlinux) || defined(rtai)
00041 #define DO_IT
00042 #endif
00043 #endif
00044
00045 #ifdef MAIN
00046
00047 #ifndef UNDER_CE
00048 #include <stdio.h>
00049 #endif
00050
00051 #include <stdlib.h>
00052 #include <string.h>
00053
00054 #endif
00055
00056 #include "parport.h" /* these decls */
00057
00058 /* the IO address of the board; override by setting global before call
00059 to pptDioInit() */
00060 unsigned long int PARPORT_IO_ADDRESS = DEFAULT_PARPORT_IO_ADDRESS;
00061
00062 #define PARPORT_IO_WIDTH 3 /* number of bytes taken up */
00063
00064 #ifdef DO_IT
00065
00066 /* real parallel port IO */
00067
00068 #if !defined(rtlinux) && !defined(rtai)
00069 #include <unistd.h> /* ioperm() */
00070 #ifdef DEFINE_EXTERN_BEFORE_IO
00071 #define extern
00072 #endif
00073 #endif
00074
00075 #ifdef __KERNEL__
00076 #include <linux/kernel.h>
00077 #include <linux/fs.h>
00078 #endif
00079
00080 #ifndef LINUX_VERSION_CODE
00081 #include <linux/version.h>
00082 #endif
00083
00084 // Pre 2.2 kernels don't seem to have the KERNEL_VERSION macro.
00085 #ifndef KERNEL_VERSION
00086 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
00087 #endif
00088
00089 #include <sys/io.h> /* outb, inb */
00090
00091 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)
00092 #else
00093 #include <asm/io.h>
00094 #endif
00095
00096 #else
00097
00098 /* don't do it */
00099 #ifndef UNDER_CE
00100 #include <stdio.h>
00101 #endif
00102
00103 static unsigned char parport[PARPORT_IO_WIDTH] = {0xFF, 0xFF, 0xFF};
|
|
|
Definition at line 110 of file parport.c. Referenced by ClrTimeout(), ReadData(), SelRead(), SelWrt16(), emcmotController(), fInP(), pptDioByteCheck(), pptDioByteRead(), pptDioCheck(), pptDioRead(), pptDioShortCheck(), pptDioShortRead(), pptDioWordCheck(), pptDioWordRead(), and pptDioWrite().
00111 {
00112 int index;
00113
00114 index = port - PARPORT_IO_ADDRESS;
00115 if (index < 0 ||
00116 index >= PARPORT_IO_WIDTH)
00117 {
00118 printf("inb: address out of bounds: %X\n", port);
00119 return 0;
00120 }
00121
00122 return parport[index];
00123 }
|
|
||||||||||||||||
|
Definition at line 105 of file parport.c. Referenced by InitializeParPort(), pptDioInit(), and pptDioQuit().
00106 {
00107 return 0;
00108 }
|
|
||||||||||||
|
Definition at line 125 of file parport.c. Referenced by BusReset(), ClrTimeout(), ReadData(), SelAddr(), SelRead(), SelWrt(), SelWrt16(), WriteData(), WriteData16(), __attribute__(), emcmotController(), extMotDout(), pptDioByteWrite(), pptDioWrite(), and stgAdcWait().
00126 {
00127 int index;
00128
00129 index = port - PARPORT_IO_ADDRESS;
00130 if (index < 0 ||
00131 index >= PARPORT_IO_WIDTH)
00132 {
00133 printf("outb: address out of bounds: %X\n", port);
00134 return;
00135 }
00136
00137 printf("outb: writing %X to %X\n", (int) byte, port);
00138 parport[index] = byte;
00139 }
|
|
||||||||||||
|
Definition at line 370 of file parport.c. Referenced by extDioByteCheck().
|
|
||||||||||||
|
Definition at line 304 of file parport.c. Referenced by extDioByteRead().
00305 {
00306 if (index != 0)
00307 {
00308 *byte = 0;
00309 return -1;
00310 }
00311
00312 *byte = inb(PARPORT_IO_ADDRESS + 1);
00313 *byte >>= 3; /* shift down since S3 is bit 0, etc. */
00314 return 0;
00315 }
|
|
||||||||||||
|
Definition at line 343 of file parport.c. Referenced by emcmotController(), extDioByteWrite(), pptDioShortWrite(), and pptDioWordWrite().
|
|
||||||||||||
|
Definition at line 229 of file parport.c. Referenced by extDioCheck().
00230 {
00231 unsigned char inByte;
00232 unsigned char mask = 1; /* start at 00000001 for D0, C0 */
00233
00234 if (index < 0 ||
00235 index > 11)
00236 {
00237 return -1;
00238 }
00239
00240 if (index < 8)
00241 {
00242 inByte = inb(PARPORT_IO_ADDRESS);
00243 mask <<= index;
00244 *value = (inByte & mask) ? 1 : 0;
00245 return 0;
00246 }
00247
00248 /* else index is 8-11 */
00249 inByte = inb(PARPORT_IO_ADDRESS + 2);
00250 mask <<= index - 8;
00251 *value = (inByte & mask) ? 1 : 0;
00252 return 0;
00253 }
|
|
|
Definition at line 145 of file parport.c. Referenced by __attribute__(), and extDioInit().
00146 {
00147 int retval = 0;
00148
00149 #ifdef linux
00150 #if !defined(rtlinux) && !defined(rtai)
00151 /* turn on port access */
00152 retval = ioperm(PARPORT_IO_ADDRESS, PARPORT_IO_WIDTH, 1);
00153 if(retval) retval=iopl(3);
00154 #endif
00155 #endif
00156
00157 return retval;
00158 }
|
|
|
Definition at line 182 of file parport.c. Referenced by extDioMaxInputs().
00183 {
00184 return 5;
00185 }
|
|
|
Definition at line 187 of file parport.c. Referenced by extDioMaxOutputs().
00188 {
00189 return 12;
00190 }
|
|
|
Definition at line 160 of file parport.c. Referenced by extDioQuit(), and extMotQuit().
00161 {
00162 int retval = 0;
00163
00164 #if !defined(rtlinux) && !defined(rtai)
00165 /* turn off port access */
00166 retval = ioperm(PARPORT_IO_ADDRESS, PARPORT_IO_WIDTH, 0);
00167 #endif
00168
00169 return retval;
00170 }
|
|
||||||||||||
|
Definition at line 199 of file parport.c. Referenced by extDioRead(), extHomeSwitchRead(), extMaxLimitSwitchRead(), and extMinLimitSwitchRead().
00200 {
00201 unsigned char inByte;
00202 unsigned char mask = 8; /* start at 00001000 for S3 */
00203
00204 if (index < 0 ||
00205 index > 4)
00206 {
00207 *value = 0;
00208 return -1;
00209 }
00210
00211 /* latch input */
00212 inByte = inb(PARPORT_IO_ADDRESS + 1);
00213 mask <<= index;
00214 *value = (inByte & mask) ? 1 : 0;
00215
00216 return 0;
00217 }
|
|
||||||||||||
|
Definition at line 388 of file parport.c. Referenced by extDioShortCheck().
|
|
||||||||||||
|
Definition at line 317 of file parport.c. Referenced by extDioShortRead().
00318 {
00319 if (index != 0)
00320 {
00321 *sh = 0;
00322 return -1;
00323 }
00324
00325 *sh = (unsigned short) inb(PARPORT_IO_ADDRESS + 1);
00326 *sh >>= 3; /* shift down since S3 is bit 0, etc. */
00327 return 0;
00328 }
|
|
||||||||||||
|
Definition at line 360 of file parport.c. Referenced by extDioShortWrite().
00361 {
00362 return pptDioByteWrite(index, (unsigned char) sh);
00363 }
|
|
||||||||||||
|
Definition at line 408 of file parport.c. Referenced by extDioWordCheck().
|
|
||||||||||||
|
Definition at line 330 of file parport.c. Referenced by extDioWordRead().
00331 {
00332 if (index != 0)
00333 {
00334 *word = 0;
00335 return -1;
00336 }
00337
00338 *word = (unsigned int) inb(PARPORT_IO_ADDRESS + 1);
00339 *word >>= 3; /* shift down since S3 is bit 0, etc. */
00340 return 0;
00341 }
|
|
||||||||||||
|
Definition at line 365 of file parport.c. Referenced by extDioWordWrite().
00366 {
00367 return pptDioByteWrite(index, (unsigned char) word);
00368 }
|
|
||||||||||||
|
Definition at line 261 of file parport.c. Referenced by extDioWrite().
00262 {
00263 unsigned char outByte;
00264 unsigned char mask = 1; /* start at 00000001 for D0, C0 */
00265
00266 if (index < 0 ||
00267 index > 11)
00268 {
00269 return -1;
00270 }
00271
00272 if (index < 8)
00273 {
00274 /* read current outputs */
00275 outByte = inb(PARPORT_IO_ADDRESS);
00276 mask <<= index;
00277 if (value)
00278 {
00279 outByte |= mask;
00280 }
00281 else
00282 {
00283 outByte &= ~mask;
00284 }
00285 outb(outByte, PARPORT_IO_ADDRESS);
00286 return 0;
00287 }
00288
00289 /* read current outputs */
00290 outByte = inb(PARPORT_IO_ADDRESS + 2);
00291 mask <<= index - 8;
00292 if (value)
00293 {
00294 outByte |= mask;
00295 }
00296 else
00297 {
00298 outByte &= ~mask;
00299 }
00300 outb(outByte, PARPORT_IO_ADDRESS + 2);
00301 return 0;
00302 }
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001