Do you have a question? Post it now! No Registration Necessary
- Luca Contini
May 26, 2004, 10:12 am

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
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
-------------------------------------------------------
Luca Contini
-------------------------------------------------------
We've slightly trimmed the long signature. Click to see the full one.

Re: external interrupt

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

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

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.

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

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
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

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

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.

--
Grant Edwards grante Yow! Does someone from
at PEORIA have a SHORTER
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 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
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

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

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
Site Timeline
- » U-boot and Seyon
- — Next thread in » Embedded Linux
-
- » task queues
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » pemohon
- — The site's Newest Thread. Posted in » Electronics Computer-Aided Design
-