Date: Tue, 23 Apr 1996 01:01:43 +0000 From: "Franz Hollerer" <eeg@telecom.at> To: kuku@gilberto.physik.rwth-aachen.de, Gabor Zahemszky <zgabor@CoDe.hu> Cc: freebsd-questions@freebsd.org Subject: Re: How can I read/write from/to an I/O-port? Message-ID: <199604222308.BAA123184@pina1.telecom.at>
next in thread | raw e-mail | index | archive | help
> > > I have a little problem. So I hope someone can help > > > me: > > > > > > Under Linux a /dev/port exits to write/read to/from an I/O-port. > > > Does a similar /dev/??? exits under FreeBSD or must I write > > > a little device driver for this? > > > > Under FreeBSD there is /dev/io. > > > > Do an open("/dev/io",flags,mode) on it and you can access i/o > > ports using in/out instructions. > > OK. How? What does flags mean? How can I use the fd, I get from open? > (A little example please....) Hi, I did not exactly understand why it works, but it works! I have looked at the code too. It really seams that port-io will change (Linux like). So I give you the example for Linux and SCO too. For SCO I wrote a little device driver which behaves like /dev/port under Linux. Please notice that the example is a fragment of a library. Franz /* ============================================================ */ /* read /write from/to an io-port: inp(), outp() 22.04.96 Franz Hollerer */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #if defined FreeBSD # include <machine/cpufunc.h> #endif #include <fcntl.h> #include "decl.h" /* ============================================================ */ int prnterr PARAMS((const char *fmt, ...)); char *getprgname PARAMS(()); void outp PARAMS((int addr, u_char b)); u_char inp PARAMS(()); /* ============================================================ */ #if defined LINUX || defined SCO /* output byte from port */ void outp(addr, b) /* Linux || SCO */ int addr; u_char b; { static int fd=-1; if (fd==-1 && (fd=open("/dev/port", O_WRONLY))==-1) { prnterr("%s: cannot open '/dev/port'\n", getprgname()); exit(1); } lseek(fd, addr, SEEK_SET); write(fd, &b, 1); } /* eof outp */ #endif /* LINUX */ #if defined FreeBSD /* output byte from port */ void outp(addr, b) /* FreeBSD */ int addr; u_char b; { static int fd=-1; if (fd==-1 && (fd=open("/dev/io", O_WRONLY))==-1) { prnterr("%s: cannot open '/dev/io'\n", getprgname()); exit(1); } outbv(addr, b); } /* eof outp */ #endif /* FreeBSD */ #if !defined LINUX && !defined FreeBSD && !defined SCO # warning "outp() not implemented!" #endif /* !LINUX && !FreeBSD */ /* ============================================================ */ #if defined LINUX || SCO /* input byte from port */ u_char inp(addr) /* Linux || SCO */ int addr; { static int fd=-1; u_char b; if (fd==-1 && (fd=open("/dev/port", O_RDONLY))==-1) { prnterr("%s: cannot open '/dev/port'\n", getprgname()); exit(1); } lseek(fd, addr, SEEK_SET); read(fd, &b, 1); return(b); } /* eof inp */ #endif /* LINUX */ #if defined FreeBSD /* input byte from port */ u_char inp(addr) /* FreeBSD */ int addr; { static int fd=-1; u_char b; if (fd==-1 && (fd=open("/dev/io", O_RDONLY))==-1) { prnterr("%s: cannot open '/dev/io'\n", getprgname()); exit(1); } b=inbv(addr); return(b); } /* eof inp */ #endif /* FreeBSD */ #if !defined LINUX && !defined FreeBSD && !defined SCO # warning: "inp() not implemented!" #endif /* !LINUX && !FreeBSD */ EEG, Hard&Software Development Austria We have no kangaroos.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604222308.BAA123184>