Standard Parallel Port Control with Port I/O

I/O port operations with Linux couldn't be simpler. There's one command for input—inb(address)—and one for output—outb(value, address). C macro expansion implements these two commands without involving any libraries. Use of inb and outb does require a couple extra lines of code, though. The ioperm command requests and relinquishes port access from the kernel.1 Writing a byte the parallel port could be as simple as these three lines of code

if (ioperm(0x378, 3, 1)) exit(1);
outb(argv[1][0], 0x378);
if (ioperm(0x378, 3, 0)) exit(1);

Likewise, reading a byte is simple. You can use the following code to read the parallel port's status lines:

 if (ioperm(0x378, 3, 1)) exit(1); putc(inb(0x379)); if (ioperm(0x378, ...

Get Embedded Linux®: Hardware, Software, and Interfacing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.