Hmm, that code segfaults on my machine. Any idea what could cause that?
I'm running a 2.4.0 kernel on this machine with parallel port and pc-style
hardware enabled. The parallelport is set to "normal" in the bios.
Matt Roberds wrote:
> >Date: Mon, 08 Jan 2001 00:45:34 -0600
> >From: Aaron Solochek <email@example.com>
> >My goal is to have a computer, running linux, send a zephyr (instant
> >message) when our doorbell is pressed. I built hardware which
> >generates a rising edge on pin 10 when the doorbell is rung. I did
> >this because someone told me that using the interrupt would be the
> >easiest way to do this.
> I have done similar things but I've never used the interrupt. I
> just save the state of the port, check the current state, and if
> new != old, I know something changed. You can add a sleep() or
> usleep() to this if you don't need to check that often.
> Here's some sample code that does exactly this. It has to be run
> as root (or setuid root) because it hits the ports directly. Also,
> for some reason, inb() is a macro that only shows up when you turn
> on optimization in gcc. To get this to compile, you have to do
> something like 'gcc readbit.c -o readbit -O'. Just 'gcc readbit.c
> -o readbit' doesn't work.
> Right now this code only looks at one bit on the status port but
> that could easily be expanded. It will run forever or until you
> press ctl-C.
> #include <stdio.h>
> #include <asm/io.h>
> #include <sys/types.h>
> #define DATAPORT 0x0378
> #define STATUS DATAPORT+1
> #define CONTROL DATAPORT+2
> int main()
> unsigned char state=0, old=0;
> /* maybe sleep here if you can get away with it */
> state &= 0x10; /* mask off bit of interest */
> if(state == old)
> /* bit didn't change since last check */
> /* bit has changed since last check */
> >If anyone has a good URL, or sample code for doing this sort of
> >thing, I'd appreciate it.
> http://www.lvr.com/parport.htm will tell you which pins on the port
> show up on what bits on what register, and also give you some other
> good information.
> Advice: In all the "how to hook homebrew hardware to your parallel port"
> guides on the net, they tell you to not hook to the nice parallel port
> that's integrated on your motherboard - use a cheap parallel port add-in
> card. Guess what? They really mean it. :) I have smoked the port on
> my motherboard by ignoring this advice. If you have a laptop you may
> be stuck, but if you have a desktop, scrounge up a parallel port card
> to hack with.
> Good luck!
> Matt Roberds
-- To unsubscribe, send mail to: firstname.lastname@example.org --
-- with the single word "unsubscribe" in the body of the message. --
This archive was generated by hypermail 2b29 : Mon Jan 08 2001 - 13:07:55 EST