> I have a number of programs written in Borland C for Dos which I want to
> convert to Linux. Many of these programs address the hardware ports, using
> the
> Borland functions INP and OUTP. Are there equivalent functions available in
> the standard Linux C , or do I need to use some form of assembly code ? If
> anybody can answer this, a few example lines would be much appreciated.
Good luck.
Ludo, alias "Le Ludal"
_________________________________________________________________
Ludovic BOISSEAU Membre Elingsys
Elve ingenieur Esil / Es2i Promotion 2001
_________________________________________________________________
http://metalab.unc.edu/pub/linux/docs/HOWTO/mini/IO-Port-Programming
but in short, if you aren't using a driver, you need to do this:
#include <asm/io.h>
#include <stdio.h>
#define IOBASE 0x31C
int main ()
{
char C;
char data = 0xAB;
if (ioperm (IOBASE, 2, 1) == -1) /* gets i/o permissions for 2 ports starting at IOBASE */
fprintf (stderr, "Can't get permission\n");
return -1;
else {
outb (data, IOBASE); /* sends a byte */
C = inb (IOBASE + 1); /* reads a byte */
printf ("C = %i\n", (unsigned int) C);
return 0;
}
There are also inw and outw macros as well for 16-bit I/O.Quote:}
Compile with -O (must have optimisation turned on!) and either run it as
root or make it setuid root (thats why it is better to write a device
driver).
HTH,
- Daniel
--
***************************************************************************
* Daniel Franklin - Postgraduate student in Electrical Engineering
***************************************************************************
Or is it that I get crazy after reading ten lines of text? :-)
Gogosoftware - http://welcome.to/gogosoftware/
WinError 01F: Reserved for future mistakes of our developers.
1. Access to hardware ports for ISA cards?
: Hi all,
: Noticed a similar query was posted here not long ago.
: I need to perform the equivalent of
: inp(0x310)
: outp(0x312,1)
You need to include "asm/io.h" (I think) and use the
inb() and outb() calls.. When you go to compile it, compile it with
the -O2 flag for optimizing flag..
(Look in /usr/src/linux/drivers/char/lp.c for more info. That's where I
found the calls that I needed.. Although, they use inb_p and outb_p
which is a version that waits for some acknolegment from the port or
something like that.. My hardware didn't provide this, so it froze my
app.. the inb and outb doesn't wait so it'll work fine for a simple
address decode/data latch type hardware..)
: i.e. i have an PC ISA card with a base address set to 310 hex and need to
: write and retrieve bytes from this card in a C program under Linux.
I'm writing a program that does the exact same thing, but I've been
warned about this. The idea with unix is that the ONLY hardware io
is done at the kernel level, NOT the application level. So theoretically,
you should write a device driver that does this for you............
Now.. Reality.. I know that my application wouldn't be fit
for porting to another platform because of hardware limitations. (I'm
building my own hardware for this very specalized app, and I don't
ever expect to need a DEC Alpha or a Sun3 for a Drum-Pad type sample
player.. :) SO, I don't really have to worry about keeping it
platform independant.
I don't know about your application, but you really should
decide wether it's worth it to write a driver for the kernel, or wether
you should go directly to the hardware from the app...
--
Mark Smith
PolyCat Support
x1189
2. site for kerndist or srcdist
3. Hardware Port access under Linux C
5. Direct access to hardware (parallel port)
7. Accessing ports on a IBM Multi port USB hub
8. udpred.c: UDP Port Redirector (IP Masq)
9. port monitor tag tcp failed,no access to parallel port
10. Accessing ports on a IBM Multi port USB hub
11. HARDWARE HARDWARE HARDWARE
12. How do I access the hardware?
13. how to find out which processes are accessing which hardware?