Hello!
I need a direct access to some I/O ports but when I do outb(..) my app
crashes. I've read that /dev/port can be used, but I don't know how.
If I want to write byte "b" to port "p" how can I do it??
Please, help me!
Thanks
I need a direct access to some I/O ports but when I do outb(..) my app
crashes. I've read that /dev/port can be used, but I don't know how.
If I want to write byte "b" to port "p" how can I do it??
Please, help me!
Thanks
> Hello!
> I need a direct access to some I/O ports but when I do outb(..) my app
> crashes. I've read that /dev/port can be used, but I don't know how.
> If I want to write byte "b" to port "p" how can I do it??
> Please, help me!
> Thanks
The standard way for communication with a device is to have a device
driver (either compiled into the kernel or a module) associate a major
and a minor number to the device. These numbers simply state what kind
of device you have, the major number divides all devices into classes
such as 'pointer devices', 'disks', etc.
You can't write to I/O ports directly in Linux, since this would violate
all protection mechanisms, and in a multi-user environment this would
create absolute mayhem. Your device driver defines what you can do with
the device, and all actions go through it.
When your driver has been loaded, you can create a 'device' file under
/dev, my doing mknod. You must tell mknod which major and minor number
to use, and it will create an ordinary file.
When you open this file and write to it, all data will go to the driver
and (hopefully) to your device. Same thing when you read from it.
Depending on what kind of device you have, you might want to do other
things than reading and writing, which can be done through ioctl().
Exactly what ioctldoes depends on what the driver allowes you to do
through it, it's not a generic function like open, read and write.
There's much more to it than this, writing device drivers is an art in
itself, but this is basically what it comes down to.
If you're trying to write "reset" to your serial port for instance, a
simple "echo reset > /dev/ttyS0" will do the trick. In C, you would do
handle = open("/dev/ttyS0");
write(handle,"reset",5);
close(handle);
--
Arne Joris
#603 9747 106st
T5K 1B4 Edmonton, AB
> I need a direct access to some I/O ports but when I do outb(..) my app
> crashes. I've read that /dev/port can be used, but I don't know how.
> If I want to write byte "b" to port "p" how can I do it??
--
Nate Eldredge
I've just experimented this way:Quote:>You can't write to I/O ports directly in Linux, since this would violate
>all protection mechanisms, and in a multi-user environment this would
>create absolute mayhem.
I know about this way. But I'm writing a software for a PIC microcontrollersQuote:>Your device driver defines what you can do with
>the device, and all actions go through it.
>When your driver has been loaded, you can create a 'device' file under
>/dev, my doing mknod. You must tell mknod which major and minor number
>to use, and it will create an ordinary file.
>When you open this file and write to it, all data will go to the driver
>and (hopefully) to your device. Same thing when you read from it.
>Depending on what kind of device you have, you might want to do other
>things than reading and writing, which can be done through ioctl().
>Exactly what ioctldoes depends on what the driver allowes you to do
>through it, it's not a generic function like open, read and write.
> I've just experimented this way:
> f = open("/dev/port", O_RDWR);
> lseek(f, port, SEEK_SET);
> write(f, value, sizeof(char));
> and it WORKED !!
> (I ran it as root, because of access rights to /dev/port...)
<and so forth>Quote:> >Your device driver defines what you can do with
> >the device, and all actions go through it.
> >When your driver has been loaded, you can create a 'device' file under
> >/dev, my doing mknod. You must tell mknod which major and minor number
What arne told you was basically right. What he forgot to say isQuote:> I know about this way. But I'm writing a software for a PIC microcontrollers
> toolkit and I don't wanna complicate it by writing a kernel module. All of
> this project is experimental anyway....
So if you need to experiment with changes, or just understand what's
happening you can start with that code.
--
Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
--- Food, Shelter, Source code. ---
: It depends on what kind of device you're trying to access.
: The standard way for communication with a device is to have a device
: driver (either compiled into the kernel or a module) associate a major
: and a minor number to the device. These numbers simply state what kind
: of device you have, the major number divides all devices into classes
: such as 'pointer devices', 'disks', etc.
: You can't write to I/O ports directly in Linux, since this would violate
Not "cannot" but basically "shouldnot". There are exceptions. X server
is most notable one. It is user space program, which accesses videocard
directly, and typically in time-critical manner.
So, it uses outb and inb. Moreover, if you are developing driver for
some new hardware it might be desirable to debug all the
device-communication issues in user-space program before converting it
to kernel module.
So, there _IS_ the way to access ports from user-space.
See ioperm system call.
There is even special document on this topic - Linux IO-Port Programming
HOWTO.
`
--
> I need a direct access to some I/O ports but when I do outb(..) my app
> crashes. I've read that /dev/port can be used, but I don't know how.
> If I want to write byte "b" to port "p" how can I do it??
> Please, help me!
> Thanks
Have you looked at the mini HOWTO's ?
There is one about io port access.
Essentially you need ioperm for the ports you need to access
and root privileges to do this.
hth
norm
1. LILO, DOS on /dev/hda1, LINUX /dev/hdb1
How must LILO be configured to successfully boot Linux, when drive
hda is totally DOS, and drive hdb is totally Linux? If boot is from
BMR (hda), it tries to load Linux from hda -- of course it fails. If boot
is from root Linux (hdb), it doesn't even see it (never looks);
boots straight from DOS.
There must be a parameter somewhere....
3. What is the difference between /dev/sg0, /dev/scd0 /dev/hdd and /dev/cdrom ?
5. Parallel port /dev files don't work
6. Help! XF86 on compaq prolinea 4/33
7. Why doesn't the serial port /dev/cua3 work?
9. /dev/dsp, /dev/audio, /dev/midi., /dev/sndsta
10. serial ports work with DOS but don't probe with FreeBSD 2.2.2
11. DTC 2130D 2nd EIDE Port only works after booting with DOS
12. /dev/midi, /dev/sequencer do not work
13. /dev/cdrom (or /dev/sbpcd) not working