/* parad.c: A very simple linux user space program for the simple one bit ADC via the Parallel Port and 8 330 Ohm resitors between every data pin and the input. See also parda.c. Parameter: I/O-Address (usually 888 for standard parallel port). Measured frequency with Linux version 2.6.8-24.11-smp (SuSE 9.2) and the onboard port: delay with usleep frequency/Hz (onboard port) 10000000 0.05 1000000 0.4988 248000 2.00 100000 4.9 10000 41,6 1000 166 1 ... 100 249,9 0 499,9 0 without udelay approx. 200 kHz The same was measured with a parallel port PCI card. Rolf Freitag Feb. 2005, nobodyo@web.de */ #include #include // or asm/io.h; for inb, ioperm, iopl ... #include // atoi #include // getuid(), usleep #include // EPERM int main (int argc, char *argv[]) /* Caution: A wrong parameter value can cause serious damage! */ { int base; // base address of the parallel port int value = 0; // bit pattern of the data pins (0 = off, 255 = all high) if (2 != argc) { printf ("Usage: %s \n", argv[0]); exit (-1); } base = strtol (argv[1], (char **)NULL, 0); if (geteuid () != 0) { printf ("\a\n\nError: $EUID==%d!=0 (you are not a superuser, port access would be denied from the kernel), exiting.\n\n", getuid ()); exit (-EPERM); } iopl (3); // unlimited I/O access permission, nessesary above the 0x3ff limit e. g. at 0x9800=38912 outb (0x2b, base + 2); // read mode for (;;) { value = inb (base); printf ("Parallel port data: %d\n", value); sleep (1); } iopl (0); // no I/O permission exit (0); };