external interrupt

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

------------------------------------------------------- Tecneitalia - AKHELA System Engineer Office: (+39) 070 2466 5503 Mobile: (+39) 328 911 6656 Fax: (+39) 070 2466 5111 snipped-for-privacy@akhela.com URL:

formatting link

--------------------------------------------------------

Reply to
Luca Contini
Loading thread data ...

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

Reply to
Michael Schnell

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

Dave

Reply to
David N. Welton

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

Reply to
Luca Contini

Oh that ****** spell checker !

-Michael

Reply to
Michael Schnell

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

Reply to
Michael Schnell

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

regards

Luca

Reply to
Luca Contini

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
                               visi.com            ATTENTION span than me?
Reply to
Grant Edwards

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
                               visi.com            or FAR ROCKAWAY!!
Reply to
Grant Edwards

I've always found that just polling at a rate slower than the

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

Thanks Luca

Reply to
Luca Contini

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               
                               visi.com
Reply to
Grant Edwards

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

Reply to
Luca Contini

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 released) }; count -- }; sleep(1 msec); };

-Michael

}
Reply to
Michael Schnell

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

Reply to
Luca Contini

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

Reply to
Michael Schnell

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.