How to do direct hardware I/O in Puppy?

Booting, installing, newbie
Post Reply
Message
Author
CharlieD
Posts: 6
Joined: Tue 29 Aug 2006, 13:28
Location: North West UK

How to do direct hardware I/O in Puppy?

#1 Post by CharlieD »

Hi

I am new to Puppy and Linux although I have been watching Puppy evolve and have run a number of versions on a PII 500MHz and even run a 128MB CF version. Very impressed but hampered by my lack of Linux experience.

I would like some guidance along the following lines.

I need to sometimes put together a simple test rig for testing bits of hardware.
The last rig was to test a barcode reader that was claimed to be faulty. Half a million scans latter it turned out to be the software!

I have usually used Msdos and a basic compiler. With this I can peak and poke memory and In and out to hardware ports. I would like to graduate to something more advanced, particularly to handle USB. Puppy Linux seems ideal.

So what I am looking for is a simple way (remember that I am a hardware engineer :roll: ) to IN and OUT to hardware ports.

Anyone got an idea?

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#2 Post by Flash »

I'd like to know how to poke around my computer's hardware too, particularly the DVD drive. I can't help thinking there must be a "lowest common denominator" approach to controlling hardware by computer but I haven't found it. It's like looking for the Holy Grail. The books on hardware hacking I've seen all seem to have left out this (presumed) crucial first step to understanding the subject. They seem to assume everyone already knows it and just jump right into the advanced topics as though the reader has been hacking hardware for years. Is it C programming? :cry:
[url=http://www.murga-linux.com/puppy/viewtopic.php?t=69321][color=blue]Puppy Help 101 - an interactive tutorial for Lupu 5.25[/color][/url]

CharlieD
Posts: 6
Joined: Tue 29 Aug 2006, 13:28
Location: North West UK

#3 Post by CharlieD »

UmmH that makes two of us.

Anyone else out there?

I am sure that there must be a "driver" that can be used to at least let us talk to the hardware even if certain parts of the I/O map are "protected".

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#4 Post by Flash »

CharlieD wrote:... I am sure that there must be a "driver" that can be used to at least let us talk to the hardware even if certain parts of the I/O map are "protected".
I suppose that such a driver has to be written specially for each piece of hardware. The source code for these drivers is almost never released (even when the hardware is obsolete and no longer supported.) Only the binary that interprets Windows (or Linux) commands to the device is available. Still, people have reverese engineered drivers for many things, printers for instance. How do they do it? What is their approach? Does it take specialized and expensive equipment such as logic analyzers?

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#5 Post by MU »

cat /dev/usbmouse
to show what the mouse tells you.

I don't know if this works to write to the printerport:
echo "a" >/dev/parport0

Mark

GuestToo
Puppy Master
Posts: 4083
Joined: Wed 04 May 2005, 18:11

#6 Post by GuestToo »

in Linux, everything is a file

list the files in /dev to see what drivers are installed for your hardware:

ls /dev

as root you can read/write to these devices directly ... an unprivileged user would have to access ports using the "device" /dev/port, or there would be a "segmentation fault"

for example, you can read the data on a cd drive directly, and send the data to the md5sum program, like this:

md5sum /dev/hdc

you can send the characters "<esc>J" to the parallel port like this:

echo -e "\eJ" > /dev/lp0

you can read directly from the parallel port like this:

cat /dev/lp0

this will read directly from the mouse port if you have a ps/2 mouse ... move the mouse to see the output (press ctrl+C to stop):

cat /dev/psaux

various software languages have their own syntax and usually have software packages, either built into the language or as add on packages

google for "hardware ports" and linux
and you will probably find a lot of information

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#7 Post by muggins »

c is good for such low level stuff, but i'm in the same boat. i've only ever used it on dos boxes. c has inport & outport commands, which will receive, or transmit, one byte of data. so you can send 11110000 to a port, and set four bits high, 4 low.

when you say that you used to do the same with a basic compiler, there are several basic compilers that should run quite happily on puppy.

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#8 Post by muggins »

here's an interesting article explaining about interfacing with
dos&win9x versus winXP versus linux.

http://linuxgazette.net/112/radcliffe.html

also it seems the inport/outport i used to use were particular to turbo-c, and the gcc equivalents are inb(port) & outb(port). see this:

http://linuxgazette.net/issue49/pramode.html

here's a good tut on using c to interface your pc with the world. it's dos/windows based, but could be easily adapted to linux.

http://www.learn-c.com/alltoget.htm

and lastly, there's always the "mister house" site about controlling anything in your house using perl scripts:

http://w3.misterhouse.net:81/

hopefully there's something of relevance to your project in this lot.

CharlieD
Posts: 6
Joined: Tue 29 Aug 2006, 13:28
Location: North West UK

#9 Post by CharlieD »

Many thanks for your very helpful replies.
I will take sometime to go through them.

I understand the concept that everything is a file which accepts a data stream but what I can not understand is how to write to (or read from) say an 8 bit port at (say) I/O address hex 0300. As I understand it you need to write to a driver as Linux will not let you write direct it protects the hardware from the applications (that is one of its jobs)

I have looked at several Basic compliers for Linux and none support I/O directly.

Under MSDos you could use QB45 (basic complier) to say:

OUT 768, 127

So that port at dec 768 (hex 300) all the bits would be 1 except the highest bit.

There seems to be no simple way of doing that under Linux or is there?

Sorry to be such a newbie!

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#10 Post by MU »

http://www.freebasic.net/
I think it is the one with best qb45-compatibility, though I don't know if the commands you need are supported.
Mark

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#11 Post by MU »

no...
http://referenz.freebasic.de/Referenz.p ... s&show=OUT
(sorry, german)

It says, that ports are not supported, except for VGA.

Or wait, that is for versions up to v0.14

0.15 seems to work.

Download and extract:
http://prdownloads.sourceforge.net/fbc/ ... z?download

Then open a xterm in the same folder and run
./install.sh -i

Then type
fbc
to use it, it displays the usage.

Mark

CharlieD
Posts: 6
Joined: Tue 29 Aug 2006, 13:28
Location: North West UK

#12 Post by CharlieD »

Mark - thank you for the link. It seems that FBC now supports INP and OUT to ports. Earlier versions did not have this.

I will give it a try

Again many thanks.

Charlie

Post Reply