I am facing problem with interrupt based GPIO programming on beaglebone. The code demomain.c given in starterware6 contain so many things apart from GPIO, and this demo is actually running the GUI demo on evm335x.
So, I just extracted GPIO interrupt features referring to the files demoGPIO.c, gpio_v2.c, demomain.c, interrupt.c, hw_control_am335x.h, etc. and TRM for AM335x.
I have attached my code int_gpio.c. Here I want to make GPIO1_29, GPIO1_30, GPIO1_23 as CLK input, DATA input, LED output respectively, for some application. For startup, I just wanted to blink the LED once whenever a falling edge interrupt is invoked via CLK_pin(GPIO1_29). Problems are listed below:
1. The code is built properly, and after configuring the DATA_Port (GPIO1), I am able to return back to main and print "Hello_all". After that if I give a -ve edge to the pin 29, (pin 26 of P8 on beaglebone). the processor is not entering the ISR.
2. In the code below, what is the register with offset 0x44 (not given in TRM)? 34 and 38 are OK as I read in TRM, and I configured all of them for triggering int for pin 29 = 0x20000000 (deafult was given for pin 2 = 0x4).
HWREG(GPIO_DATA_PORT + 0x34) = 0x20000000; //GPIO_IRQSTATUS_SET0
HWREG(GPIO_DATA_PORT + 0x38) = 0x20000000; //GPIO_IRQSTATUS_SET0
HWREG(GPIO_DATA_PORT + 0x44) = 0x20000000; //what is 0x44??
So far I have done normal GPIO operations and successfully drove 16x2 LCD module using GPIO APIs of starterware5 and 6. Just facing problem with interrupts.
My code "int_gpio.c" is copied below:
#include "soc_AM335x.h"
#include "beaglebone.h"
#include "gpio_v2.h"
#include "interrupt.h"
#include "hw_control_AM335x.h"
/*****************************************************************************
** INTERNAL MACRO DEFINITIONS
*****************************************************************************/
#define GPIO_DATA_PORT (SOC_GPIO_1_REGS)
#define GPIO_CLK_PIN_NUMBER (29)
#define GPIO_DATA_PIN_NUMBER (30)
#define GPIO_LED_PIN_NUMBER (23)
/*******************************************************************************
** EXTERNAL FUNCTION DECLARATIONS
*******************************************************************************/
extern void GPIO1PinMuxSetup(unsigned int pinNo);
/*****************************************************************************
** INTERNAL FUNCTION DEFINITIONS
*****************************************************************************/
/*
** A function which is used to generate a delay.
*/
static void Delay(volatile unsigned int count)
{
while(count--);
}
// A function to blink LED once each time a falling edge is encountered on CLK pin
static void gpio1Isr(void)
{
printf("Hello1\n");
/* Clear clk interrupt */
HWREG(SOC_GPIO_1_REGS + 0x2C) = 0x20000000;
HWREG(SOC_GPIO_1_REGS + 0x30) = 0x20000000;
printf("Hello2\n");
/* Driving a logic HIGH on the GPIO pin. */
GPIOPinWrite(GPIO_DATA_PORT,
GPIO_LED_PIN_NUMBER,
GPIO_PIN_HIGH);
Delay(0x3FFFF);
/* Driving a logic LOW on the GPIO pin. */
GPIOPinWrite(GPIO_DATA_PORT,
GPIO_LED_PIN_NUMBER,
GPIO_PIN_LOW);
Delay(0x3FFFF);
//again enable Falling edge IRQ
HWREG(GPIO_DATA_PORT + 0x34) = 0x20000000;
HWREG(GPIO_DATA_PORT + 0x38) = 0x20000000;
HWREG(GPIO_DATA_PORT + 0x44) = 0x20000000;
}
static void ConfigDataPort(void)
{
/* Enabling functional clocks for GPIO1 instance. */
GPIO1ModuleClkConfig();
/* Selecting GPIO1 pins for use. */
GPIO1PinMuxSetup(29);
GPIO1PinMuxSetup(23);
GPIO1PinMuxSetup(30);
/* Enabling the GPIO module. */
GPIOModuleEnable(GPIO_DATA_PORT);
/* Resetting the GPIO module. */
GPIOModuleReset(GPIO_DATA_PORT);
/* Setting the GPIO data as an input pin. */
GPIODirModeSet(GPIO_DATA_PORT,
GPIO_DATA_PIN_NUMBER,
GPIO_DIR_INPUT);
/* Setting the GPIO clock as an input pin. */
GPIODirModeSet(GPIO_DATA_PORT,
GPIO_CLK_PIN_NUMBER,
GPIO_DIR_INPUT);
/* Setting the GPIO LED as an output pin. */
GPIODirModeSet(GPIO_DATA_PORT,
GPIO_LED_PIN_NUMBER,
GPIO_DIR_OUTPUT);
//**************** Check enabling of LED pin ****************
/* Driving a logic HIGH on the GPIO pin. */
GPIOPinWrite(GPIO_DATA_PORT,
GPIO_LED_PIN_NUMBER,
GPIO_PIN_HIGH);
Delay(0x3FFFF);
/* Driving a logic LOW on the GPIO pin. */
GPIOPinWrite(GPIO_DATA_PORT,
GPIO_LED_PIN_NUMBER,
GPIO_PIN_LOW);
Delay(0x3FFFF);
//************* Now enable interrupt on CLK pin *************
/* Initialize the ARM Interrupt Controller */
IntAINTCInit();
IntMasterIRQEnable();
/* GPIO interrupts */
IntSystemEnable(SYS_INT_GPIOINT1A);
IntPrioritySet(SYS_INT_GPIOINT1A, 0, AINTC_HOSTINT_ROUTE_IRQ);
IntRegister(SYS_INT_GPIOINT1A, gpio1Isr);
IntSystemEnable(SYS_INT_GPIOINT1B);
IntPrioritySet(SYS_INT_GPIOINT1B, 0, AINTC_HOSTINT_ROUTE_IRQ);
IntRegister(SYS_INT_GPIOINT1B, gpio1Isr);
/* Setting the GPIO_CLK_PIN_NUMBER to raise IRQ at falling edge of input */
GPIOIntTypeSet(GPIO_DATA_PORT,
GPIO_CLK_PIN_NUMBER,
GPIO_INT_TYPE_FALL_EDGE);
HWREG(GPIO_DATA_PORT + 0x34) = 0x20000000;
HWREG(GPIO_DATA_PORT + 0x38) = 0x20000000;
HWREG(GPIO_DATA_PORT + 0x44) = 0x20000000;
}
/*
** The main function. Application starts here.
*/
int main()
{
ConfigDataPort();
printf("Hello_all\n");
while(1);
}
/******************************* End of file *********************************/
Please tell me what is missing or what is wrong?
--Thanks in advance