Hi folks,
I try to monitor pin transitions on a beaglebone black with an android os on it.
Therefor i found the link ‘https://developer.ridgerun.com/wiki/index.php/Gpio-int-test.c’.
I set up the gpios of the BBB over ADB.
echo 60 > export
cd gpio60
echo out > direction
echo 0 > value
echo 49 > export
cd gpio49
echo in > direction
echo rising > edge
I also changed the access chmod 777 for the pins.
Gpio60 is output and Gpio49 is the input. Both pins are connected over a led and a resistor. Therefor I am able to switch the led on/ off and see at gpio40 the corresponding values 1 or 0.
My problem is that poll(…). It is always returning immediately with a POLLIN event. And I am not changing gpio60.
JNIEXPORT jstring JNICALL Java_com_hardware_drivers_Gpio_registerInterrupt(
JNIEnv* env,
jobject thiz
) {
jint pinNumber = 49;
struct pollfd fdset[1];
jint rc;
char buffer[MAX_BUFFER];
jint len = snprintf(
buffer,
sizeof(buffer),
SYSFS_GPIO_DIR “/gpio%d/value”,
pinNumber
);
jint gpio_fd = open(buffer, O_RDONLY | O_NONBLOCK);
if (gpio_fd < 0)
{
LOGE(“gpio: gpio open failed”);
return (*env)->NewStringUTF(env, “open failed”);
}
LOGE(“gpio: pin %d open”, pinNumber);
jint cnt = 0;
jboolean loopRunning = JNI_TRUE;
while(loopRunning)
{
memset((void*)fdset, 0, sizeof(fdset));
fdset[0].fd = gpio_fd;
fdset[0].events = POLLIN;
rc = poll(fdset, 1, -1);
if (rc < 0)
{
LOGE(“gpio: poll() failed %d”, rc);
return (*env)->NewStringUTF(env, “poll failed”);
}
if(fdset[0].revents & POLLIN)
{
LOGE(“gpio: interupt occured pollin %d”, fdset[0].revents);
}
cnt++;
if(cnt > 3)
loopRunning = JNI_FALSE;
}
return (*env)->NewStringUTF(env, “exit”);
}
log output:
01-01 00:13:39.648: E/Log(2213): gpio: pin 49 open
01-01 00:13:39.648: E/Log(2213): gpio: interupt occured pollin 9
01-01 00:13:39.648: E/Log(2213): gpio: interupt occured pollin 9
01-01 00:13:39.648: E/Log(2213): gpio: interupt occured pollin 9
01-01 00:13:39.648: E/Log(2213): gpio: interupt occured pollin 9
I tryed it also with POLLPRI but the result was the same
Does anybody knows why it’s not working?
With best regards in advanced,