interrupt on BeagleBone

Hi guys,
I’m trying to use the interrupts on my BeagleBone running QNX 6.5.

I would use the GPIO1_12 on P8 header connector as source. My intention should be to detect when a user press a button and the GPIO1_12 falls to GND.
So, in order to do that, I set-up the GPIO1_12 as input, in pullup configuration and setup the GPIO_FALLINGDETECT register.

Unfortunately something goes wrong and when I try to press the button, nothing happens.

Here is my code:

#include <cstdlib>
#include <iostream>
#include <sys/mman.h>
#include <pthread.h>
#include <sys/neutrino.h>
#include <errno.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdint.h>
#include <hw/inout.h>
#include <am335x.h>
#include <stdio.h>

#define AM335X_CTRL_BASE	0x44E10000
#define conf_gpmc_ad12		0x0830 // (AM335X_CTRL_BASE+0x0830)
#define SLEWCTRL			(0x1 << 6)
#define	RXACTIVE			(0x1 << 5)
#define	PULLUP_EN			(0x1 << 4) /* Pull UP Selection */
#define PULLUDEN			(0x0 << 3) /* Pull up enabled */
#define PULLUDDIS			(0x1 << 3) /* Pull up disabled */
#define MODE(val)			val
#define GPIO_OE 			0x134
#define AM335X_GPIO_SIZE	0x00001000
#define AM335X_GPIO1_BASE   0x4804C000
#define GPIO1_IRQ 98

int init_gpio1_12(void);
const struct sigevent * isr_handler (void *arg, int id);
void * int_thread (void *arg);

struct sigevent event;
uintptr_t ptr;
uintptr_t ptr2;
int count;
int error;

int main(int argc, char *argv[]) {

	init_gpio1_12();

	event.sigev_notify = SIGEV_INTR;

	printf("Creating interrupt thread…\n");

	pthread_create (NULL, NULL, int_thread, NULL);
	delay(5);

	while(!error) {
	printf("count=%i\n", count);
	fflush(stdout);
	sleep(1);
	}

    return EXIT_SUCCESS;

}

int init_gpio1_12()
{
	int pad;

   	ThreadCtl(_NTO_TCTL_IO, 0);

   	ptr = (uintptr_t)mmap_device_memory(0, AM335X_CTRL_BASE+0x0840, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, AM335X_CTRL_BASE);

	if ( ptr == MAP_DEVICE_FAILED ) {
		perror( "mmap_device_memory for physical address failed");
		return -1;
	}

	pad = in32(ptr + conf_gpmc_ad12) & 0x0000ffff;

	out32(ptr + conf_gpmc_ad12, MODE(7) | PULLUDEN | PULLUP_EN | RXACTIVE | SLEWCTRL);

	pad = in32(ptr + conf_gpmc_ad12);

   	ptr2 = (uint32_t) mmap_device_memory(0, AM335X_GPIO_SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, AM335X_GPIO1_BASE);

	if ( ptr2 == MAP_DEVICE_FAILED ) {
		perror( "mmap_device_memory for physical address failed");
		return -1;
	}

	out32(ptr2 + GPIO_OE,(1<<12));

	out32(ptr2 + GPIO_FALLINGDETECT, (1 << 12));
}

const struct sigevent * isr_handler (void *arg, int id)
{
	return (&event);
}

void * int_thread (void *arg)
{
	// enable I/O privilege
	ThreadCtl (_NTO_TCTL_IO, 0);

	// attach the ISR to IRQ
	if (InterruptAttach (GPIO1_IRQ, isr_handler, NULL, 0, _NTO_INTR_FLAGS_TRK_MSK) == -1)
	{
		error = 1;
	}

	while (1)
	{
		InterruptWait (NULL, NULL);
		count++;
	}
}

Someone can help me? :neutral_face:

Thanks

Alessandro

Why not put the count++ in the ISR? That would eliminate the possibility of error in the notification.

Hi maschoen,
thanks for your suggestion, but unfortunaely it doesn’t work.
But if I want to detect a FALLING EDGE, I should put the interrupt in PULLUP configuration, right?

Bye

What doesn’t work? If you put the count++ inside the isr, either the count increases or it doesn’t and you know more.
If it increments, you have a software problem. If it doesn’t increment, the interupt isn’t firing and you know you have a hardware problem.

Well, I’m not much of a hardware guy. What you say sounds right. The interrupt controller has to be set up right to detect the falling edge.

Hi maschoen,
in order to avoid errors on hardware side, I’ve tried to check the interrupt with a simple test. After running the code, I’ve tried to connect the GPIO to GND in order to detect the falling edge, but it didn’t work.

Bye