Hi,
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.
Actually I'm not sure about the IRQ number used by GPIO1.
Reading the AM335x TRM (p.214) I see that there are two IRQ associated to GPIO1
INT # | ACRONYM/NAME | SOURCE | SIGNAL NAME |
98 | GPIOINT1A | GPIO1 | POINTRPEND1 |
99 | GPIOINT1B | GPIO 1 | POINTRPEND2 |
So, I've tried both but the code still doesn't work.
Maybe I should use another IRQ number?
Can you help me explaining me what is the procedure to set a GPIO as interrupt source for detecting falling edge event?
For your reference I attach my code (QNX) to check if I'm going on the right way:
#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 <stdio.h>
#include <sys/syspage.h>
struct sigevent event;
volatile unsigned counter;
#define AM335X_CTRL_BASE 0x44E10000
#define conf_gpmc_ad12 0x0830
#define SLEWCTRL (0x1 << 6)
#define RXACTIVE (0x1 << 5)
#define PULLUP_EN (0x0 << 4) /* Pull UP Selection */ /*0x1*/
#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 99
#define GPIO_RISINGDETECT 0x148 // Rising-edge Detection Enable Register Section 9.3.15
#define GPIO_FALLINGDETECT 0x14C // Falling-edge Detection Enable Register Section 9.3.16
#define GPIO_IRQSTATUS_0 0x02C // Status Register for Interrupt 1 Section 9.3.5
#define GPIO_IRQSTATUS_1 0x030 // Status Register for Interrupt 2 Section 9.3.5
uintptr_t ptr;
uintptr_t ptr2;
int pad;
int id;
int i;
const struct sigevent *handler( void *area, int id ) {
++counter;
return( &event );
}
int main() {
counter = 0;
// root privilegies
ThreadCtl(_NTO_TCTL_IO, 0);
// mapping memory for register conf_gpmc_ad12
// ptr = mmap_device_io(AM335X_CTRL_BASE+0x0840,AM335X_CTRL_BASE);
ptr = (uintptr_t)mmap_device_memory(0, AM335X_CTRL_BASE+0x0840, PROT_READ|PROT_WRITE|PROT_NOCACHE, 0, AM335X_CTRL_BASE);
// register conf_gpmc_ad12 configured as GPIO1_12 input
out32(ptr + conf_gpmc_ad12, MODE(7) | PULLUDEN | PULLUP_EN | RXACTIVE | SLEWCTRL);
// register configuration for detecting the FALLING on GPIO1_12
// ptr2 = (uintptr_t) mmap_device_io(AM335X_GPIO_SIZE,AM335X_GPIO1_BASE);
ptr2 = (uintptr_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;
}
// clear interrupt status
out32(ptr2 + GPIO_IRQSTATUS_1, in32(ptr2 + GPIO_IRQSTATUS_1) | 0xFFFFFFFF);
// setting FALLING DETECTION on GPIO1_12
out32(ptr2 + GPIO_FALLINGDETECT, (1<<12));
// Initialize event structure
event.sigev_notify = SIGEV_INTR;
printf("In attesa di interrupt...\n");
// Attach ISR vector
id=InterruptAttach(GPIO1_IRQ, &handler,NULL, 0, 0 ); // SYSPAGE_ENTRY(qtime)->intr
printf("id value: %d\n",id);
printf("Interrupt wait...\n");
for( i = 0; i < 10; ++i ) {
// Wait for ISR to wake us up
InterruptWait( 0, NULL );
printf("valore di counter: %d\n",counter);
}
// Disconnect the ISR handler
InterruptDetach(id);
return 0;
}
Thanks,
Alessandro