Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A20 => Topic started by: Cosik on October 30, 2014, 02:53:59 PM

Title: GPIO Interrupts
Post by: Cosik on October 30, 2014, 02:53:59 PM
Hi,

Did anyone run external interrupt support in C/C++, successfully?
Title: Re: GPIO Interrupts
Post by: Stinde on October 30, 2014, 05:21:02 PM
I have implemented a simple GPIO counter using Linux interrupt counters in /proc/interrups. SW was in C.
This method can be used only for counter. If you need something more complicated I can't help.

BR,

Timo
Title: Re: GPIO Interrupts
Post by: Cosik on October 30, 2014, 05:53:11 PM
Hi,

It will be nice if you could share with us some code part. I'm still looking for solution.
Title: Re: GPIO Interrupts
Post by: JohnS on October 30, 2014, 05:59:42 PM
Consult kernel drivers and datasheets.

Why do you want to do it?  It's not expected that user code does it.

John
Title: Re: GPIO Interrupts
Post by: Cosik on October 30, 2014, 06:20:15 PM
Hi,

I have radio module which set 0 to pin when it get new unread data. For reduce CPU usage it's necessary to use hardware solutions like GPIO interrupt (EINT).


For some reason it's implemented on hardware ;)

Or maybe you John have a proposal of some other solution for this problem?
Title: Re: GPIO Interrupts
Post by: JohnS on October 30, 2014, 07:20:29 PM
Write a driver.

John
Title: Re: GPIO Interrupts
Post by: Stinde on October 30, 2014, 08:17:34 PM
I did my counter for A13, but the principle should be same for A20. As mentioned before this works only for counter, if you need something else, you have to write a driver.

The /proc/interrupts file contains a list of interrupts and how many times the interrupt has occured.

1. you have to define the GPIO pins in script.bin file. Only EINT pins can used for interrupts Check the A20 EINT pins from the datasheet.

2. set up the GPIO pins writing the GPIO number to /sys/class/gpio/export

3. Set the GPIOs as inputs.  In case of gpio1_pg2, write "in" to /sys/class/gpio/gpio1_pg2/direction

4 Set the interrupt edge. In case of rising edge to gpio_pg2, write "rising" into /sys/class/gpio/gpio1_pg2/edge

5. You should have new interrupt listed in /proc/interrupts file. Write down the interrupt number for the gpio.

6 repeat this for all GPIOs you need and write down the irq numbers.

there is also /proc/irq/ directory. All interrupt numbers have their own subdirectory containing file spurious, which has interrupt count and other info.
First I tried to read the spurious file with my code, but opening the file resets the interrupt counter. Now

I read the /proc/interrupts file line by line and extract the irq count after the irq number.

My code is not fully functional, so I can't publish it yet.

Timo



Title: Re: GPIO Interrupts
Post by: Cosik on October 30, 2014, 09:37:09 PM
Hi,

Ok I found solution which is working good for me.

F

This solution is for Qt

QSocketNotifier *keypad_notifier;
QFile keypad_value;
QString gpio_value_path;
gpio_value_path = QString::fromStdString("/sys/class/gpio/gpio63_pi15/value");
keypad_value.setFileName(gpio_value_path);
keypad_value.open(QFile::ReadOnly);
keypad_notifier = new QSocketNotifier(keypad_value.handle(), QSocketNotifier::Exception);
keypad_notifier->setEnabled(true);
connect(keypad_notifier, SIGNAL(activated(int)), this, SLOT(mySlot(int)));


And in slot should be function witch read file, in my case:
keypad_value.readAll();