/* pario.c * Dient zum Auslesen der Standard-Parallelport-Register und kann z. B. * verwendet werden um zu sehen, welche Werte in das Status-Register * geschrieben wurden. * * This Program won't work on the sparc, where there's no concept of I/O space * Tested with Linux 2.2 on the x86. * * important: this program won't work without the compiler-option -O or -02 ... * and this program can only be run by a superuser (or another user after * "chown root.root pario; chmod 4755 pario"). * * It takes approx. 1,5us for one Parallel Port I/O (with an onboard Parallel Port). * * dd if=/dev/port bs=1 count=1 skip=889 Rolf Freitag Lizenz: GPL */ #include #include /* error codes */ #include /* or */ #include // exit, atoi #include // getuid(), usleep #ifndef BIT0 /* ifdef to avoid redefinition; existing definitions should be ok */ # define BIT0 (0x1) // 2^0 #endif #ifndef BIT1 # define BIT1 (0x2) #endif #ifndef BIT2 # define BIT2 (0x4) #endif #ifndef BIT3 # define BIT3 (0x8) #endif #ifndef BIT4 # define BIT4 (0x10) // 16 #endif #ifndef BIT5 # define BIT5 (0x20) // 32 #endif #ifndef BIT6 # define BIT6 (0x40) // 64 #endif #ifndef BIT7 # define BIT7 (0x80) // 128 #endif int main (int argc, char *argv[]) { unsigned int b; /* parallel port base (e. g. 0x3bc, 0x378=888 or 0x278=632), a wrong value may cause serious damage */ unsigned char b0; if (2 != argc) { printf ("Usage: %s \n", argv[0]); exit (-1); } b = strtol (argv[1], (char **)NULL, 0); if (geteuid () != 0) { printf ("\a\n\nError: $EUID==%d!=0 (you are not a superuser).\n\n", getuid ()); exit (-EPERM); } iopl (3); /* allows access to all I/O-Ports, ioperm doesen't work above the 0x3ff-Limit e. g. at PCI-Cards */ b0 = inb (b + 2); printf ("Der Wert, der von Port 0x%hx (Kontroll-Register des Parallelports) soeben gelesen wurde ist: 0x%hx\n", b + 2, b0); printf ("BIT0: /STROBE (out, Pin 1), BIT1: /AUTOFD (out, Pin 14), BIT2: /INIT (not inverting, out, Pin 16), BIT3: /SELECT (out, Pin 17), BIT4: Interrupt enable, Bit5: data read /write\n"); b0 |= BIT5; // read mode outb (b0, b + 2); // outb (0xff, b); b0 = inb (b + 1); printf ("Der Wert, der von Port 0x%hx (Status-Register des Parallelports) soeben gelesen wurde ist: 0x%hx\n", b + 1, b0); printf ("BIT3: /ERROR (in, Pin 15), BIT4: SELECTING (in, Pin 13), BIT5: PAPEREND (in, Pin 12), BIT6: /ACK (in, l->h irq, Pin 10), BIT7: BUSY (in, Pin 11)\n"); b0 = inb (b); printf ("Der Wert, der von Port 0x%hx (Daten-Register des Parallelports) soeben gelesen wurde ist: 0x%hx\n", b, b0); printf ("BIT0 - BIT7: Data0 - Data7 (out (mayby in), Pin 2 - 9)\n"); iopl (0); /* release region */ exit (0); }