|
|
Interrupt management on Beaglebone running QNX 6.5
|
|
09/25/2013 4:36 PM
post105406
|
Interrupt management on Beaglebone running QNX 6.5
Hi guys,
I'm tryingot fogire out how can I use interrupts on my Beaglebone running QNX 6.5.
My need is to use GPIO1_12 as interrupt line when a user push down a botton.
In order to do so I've setup the GPIO1_12 in pullup mode in order to detect, thorough falling detect condiction when the
user press the button.
Based on my researches, I've written the following code, it compiles but it doesn't work:
Do you have some suggetions?
Thanks guys.
################################ 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 99
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);
// The register that I want to use as gpio (conf_gpmc_ad12) is located at the address 0x0830, so I will map the
memory from AM335X_CTRL_BASE addresss to AM335X_CTRL_BASE+0x0840
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;
// I set conf_gpmc_ad12 in MODE 7 to enable the pin as GPIO1_12
out32(ptr + conf_gpmc_ad12, MODE(7) | PULLUDEN | PULLUP_EN | RXACTIVE | SLEWCTRL);
//pad = in32(ptr + conf_gpmc_ad12);
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;
}
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++;
}
}
|
|
|
|
|