external interrupt

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello,
I'm running Linux 2.4.18-rmk6 on Samsung SMDK2410 dev board.
On this board there are 4 test buttons and I need to test them.
The question is: how do I handle and external interrupt (button pressed)
from the User space?
Do I need to write a sort of driver?

regards




--
Luca Contini
-------------------------------------------------------
We've slightly trimmed the long signature. Click to see the full one.
Re: external interrupt
Quoted text here. Click to load it

If you want to use an interrupt, you need to write a device driver.
That's not difficult in Linux. You should look into  "Linux device
drivers" by Rubbing and use the kernel source as a reference. The user
program e.g. does a read ion your new driver and that will block until
the interrupt is seen. (You can use "select" if you don't want to have
your program blocked".)

OTOH a button is a very slow event. So you might be able to just poll it
in the user program. Perhaps adding another thread that does a poll and
sleep cycle.

-Michael

Re: external interrupt
Quoted text here. Click to load it

That's "Alessandro Rubini", and I'll second the recommendation.

Dave

Re: external interrupt
Quoted text here. Click to load it

Thanks,
so you think it's better polling from the user space than writing a small
device driver?
I know how to write a device driver, but usually the interrupt is handled
inside the driver.
Here is different (I guess), because I need for example, to launch an
application when you press a button.

regards

Luca




Re: external interrupt
Quoted text here. Click to load it

Especially with a button, using an interrupt is not a good ide as every
push might generate many interrupts due to bouncing. Polling the bit and
do a decent debouncing (a counter counting up when pressed and down when
not pressed and notifying the user software when a limit (that is not to
be passed) on either end is reached.

Quoted text here. Click to load it

Launching the application is a user space action. so you can do it when
the event is detected, independently of the way the user space event is
generated.

-Michael

Re: external interrupt
Quoted text here. Click to load it

OK, now have to guess how to do it.
What do you mean by "polling the bit"?

regards

Luca







Re: external interrupt

Quoted text here. Click to load it

You write a loop that goes out and reads the button state
periodically.  This could be done in user-space or in a
driver.

--
Grant Edwards                   grante             Yow!  I'm having fun
                                  at               HITCHHIKING to CINCINNATI
We've slightly trimmed the long signature. Click to see the full one.
Re: external interrupt

Quoted text here. Click to load it

Pseudo code:

Main program :

...
  create polling process (or thread)
...




polling process:

const int max = 10;
int count = 0;
while (1) {
  read (bit)
  if (bit == pressed) {
    if (count <= max) {
      if (count == max) {
        notify main process(button pressed)
      };
      count ++
    };
   } else {
    if (count >= -max) {
      if (count == -max) {
        notify main process(button released)
      };
      count --
    };
   sleep(1 msec);
  };


-Michael

}

Re: external interrupt
Quoted text here. Click to load it

ok, but read (bit) means I have to read a register (interrupt register) from
the user space, because I have no kernel driver for the button.
Am I correct?

thank you and regards

Luca






Re: external interrupt

Quoted text here. Click to load it

I've always found that just polling at a rate slower than the
settling time worked fine.  If it takes 20ms for the bouncing
to settle out, poll it at 50ms intervals.  That way you don't
need any state info.  

If you've got a really slow switch and don't want the latency
involved in a slow polling cycle, you could also poll at a
faster rate and just suspend the polling for more than the
settling time after any state change.

Quoted text here. Click to load it

--
Grant Edwards                   grante             Yow!  Does someone from
                                  at               PEORIA have a SHORTER
We've slightly trimmed the long signature. Click to see the full one.
Re: external interrupt
 I've always found that just polling at a rate slower than the
Quoted text here. Click to load it

OK,
but what if the button has no driver? What do I poll?

Thanks
Luca




Re: external interrupt

Quoted text here. Click to load it

I don't have a schematic for your board, so I can't tell you
precisely.  But, on the Samsung ARM7 parts I've used, the
external interrupt pins were also all readable as input ports.

You just read the memory location where that input port is
located.

--
Grant Edwards                   grante             Yow!  .. my NOSE is NUMB!
                                  at              
We've slightly trimmed the long signature. Click to see the full one.
Re: external interrupt
Quoted text here. Click to load it


OK,
but I'm concerned about reading a register from the user space...
I should be able to unmask the corresponding bit, to read the Source pending
register and to clear the interrupt bit.
Is all that possible according to you?
Or am I missing something?

regards

Luca




Re: external interrupt
Quoted text here. Click to load it

Of course this is architecture dependent. I know in a PC linux there are
certain API calls (only usable for ADMIN users) to allow user space
access to ranges of I/O ports and there are macros to access them from C
language. I suppose similar things are available for several other
architectures as well.

-Michael

Re: external interrupt
Quoted text here. Click to load it


Oh that ****** spell checker !

-Michael

Site Timeline