zhaolei / WiringOP

This is a GPIO access library for OrangePi. It is based on the original WiringPi for Raspberry Pi.
GNU Lesser General Public License v3.0
351 stars 134 forks source link

Issue with IRQ #16

Closed riccardomanfrin closed 5 years ago

riccardomanfrin commented 5 years ago

I've tried the following code (after echo'ing 3 > /sys/class/gpio/export)


#include <stdio.h>
#include <wiringPi.h>
#include <stdint.h>
#define TRIGGER 2
#define ECHO 3

int IRQcount = 0;

void irq(void) {
    //printf("Falling edge\n");
    IRQcount++;
}

int main() {
    wiringPiSetup();
    pinMode(TRIGGER, OUTPUT);
    pinMode(ECHO, INPUT);
    //Next line fails miserably
    wiringPiISR(ECHO, INT_EDGE_RISING, &irq);   
    for (;;) {
        printf("On [%i]\n", IRQcount);
        digitalWrite(TRIGGER, HIGH);
        delayMicroseconds(4000000);
        printf("Off [%i]\n", IRQcount);
        digitalWrite(TRIGGER, LOW);
        delayMicroseconds(4000000);
    }
    return (0);
}```

The interrpt is invoked, but then it won't ever stop forever, hitting the callback until I don't stop the program.
It's not bouncing or anything it really keeps beeing called forever.

Is there a way to disarm the irq?
riccardomanfrin commented 5 years ago

Despite what documented in https://www.kernel.org/doc/Documentation/gpio/sysfs.txt after irq consumption closing the fd is the only way. fseek does not appear to be working. Closing /reopening the fd does the job.