Hello;
I have built a simple program using the gpioLEDBlink and gpioCardDetect StarterWare examples. I want to test the GPIO Interrupts. My idea consists of switching on a LED when a GPIO port detects an input (1) and switching it off when there is no input (0). I have included some printf to know where is the program. When I debug, my problem is that the GPIO Interrupt does not happen or that when it happes it does not enter into the GPIOIsr Interrupt sub-routine.
I am working with CCS v5 and with a Beaglebone Black, running my example into he CortxA8. My debugg device is a Texas Instruments XDS100v2 USB Emulator. I have make sure that the options "when assembly stepping, source stepping and running" are not enabled so that the interrupts are not disabled. Also, I have deselected "Automatically step over functions without debug information when source stepping". However, I keeps on not working.
How can I make it work? Is that a code problem or a CCS v5 problem?
Here I attach my code program.
/**
* \file gpioLEDBlink.c
*
* \brief This application uses a GPIO pin to blink the LED.
*
* Application Configurations:
*
* Modules Used:
* GPIO1
*
* Configuration Parameters:
* None
*
* Application Use Case:
* 1) The GPIO pin GPIO1[23] is used as an output pin.
* 2) This pin is alternately driven HIGH and LOW. A finite delay
* is given to retain the pin in its current state.
*
* Running the example:
* On running the example, the LED on beaglebone would be seen
* turning ON and OFF alternatively.
*
*/
/*
* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
*/
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "soc_AM335x.h"
#include "evmAM335x.h"
#include "interrupt.h"
#include "gpio_v2.h"
#include "delay.h"
#include "pin_mux.h"
/*****************************************************************************
** INTERNAL MACRO DEFINITIONS
*****************************************************************************/
#define GPIO_INSTANCE_ADDRESS (SOC_GPIO_1_REGS)
#define GPIO_INSTANCE_PIN_NUMBER (24)
#define GPIO_INSTANCE_ADDRESS_0 (SOC_GPIO_0_REGS)
#define GPIO_CD_PIN_NUM (27)
#define GPIO_INST_SYS_INT_NUM (SYS_INT_GPIOINT0A)
/*****************************************************************************
** INTERNAL FUNCTION PROTOTYPES
*****************************************************************************/
static void Delay1(unsigned int count);
static void GPIOINTCConfigure(void);
static void CheckCardStatus(void);
static void GPIOIsr(void);
/*****************************************************************************
** INTERNAL VARIABLE DEFINITIONS
*****************************************************************************/
static volatile unsigned int gpioIsrFlag = 0;
/*****************************************************************************
** INTERNAL FUNCTION DEFINITIONS
*****************************************************************************/
/*
** The main function. Application starts here.
*/
int main()
{
/* INICIALIZACIÓN GPIO1 - LED */
/* Enabling functional clocks for GPIO1 instance. */
GPIO1ModuleClkConfig();
/* Selecting GPIO1[23] pin for use. */
GPIO1Pin23PinMuxSetup();
/* Enabling the GPIO module. */
GPIOModuleEnable(GPIO_INSTANCE_ADDRESS);
/* Resetting the GPIO module. */
GPIOModuleReset(GPIO_INSTANCE_ADDRESS);
/* Setting the GPIO pin as an output pin. */
GPIODirModeSet(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_DIR_OUTPUT);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_HIGH);
Delay1(0x3FFFF);
Delay1(0x3FFFF);
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_LOW);
/* INICIALIZACIÓN GPIO0 - DETECCIÓN */
/* This function enables the functional clocks for the GPIO1 instance. */
GPIO0ModuleClkConfig();
/* Perform Pin Multiplexing for the pin GPIO0[6]. */
GPIO_PMUX_OFFADDR_VALUE(0, 27, PAD_FS_RXE_PU_PUPDE(7));
/* Enable the GPIO Module. */
GPIOModuleEnable(GPIO_INSTANCE_ADDRESS_0);
/* Perform a reset of the GPIO Module. */
GPIOModuleReset(GPIO_INSTANCE_ADDRESS_0);
/* Configure the Card Detection Pin as an Input Pin. */
GPIODirModeSet(GPIO_INSTANCE_ADDRESS_0, GPIO_CD_PIN_NUM, GPIO_DIR_INPUT);
/* Enable Debouncing feature for the Intput GPIO Pin. */
GPIODebounceFuncControl(GPIO_INSTANCE_ADDRESS_0, GPIO_CD_PIN_NUM, GPIO_DEBOUNCE_FUNC_ENABLE);
/* Configure the Debouncing Time for all the input pins of the seleceted GPIO instance. */
GPIODebounceTimeConfig(GPIO_INSTANCE_ADDRESS_0, 48);
/* Configure the INTC to receive GPIO Interrupts. */
GPIOINTCConfigure();
/* Disable interrupt generation on detection of a logic HIGH or LOW levels. */
GPIOIntTypeSet(GPIO_INSTANCE_ADDRESS_0, GPIO_CD_PIN_NUM, GPIO_INT_TYPE_NO_LEVEL);
/* Enable interrupt generation on detection of a rising or a falling edge. */
GPIOIntTypeSet(GPIO_INSTANCE_ADDRESS_0, GPIO_CD_PIN_NUM, GPIO_INT_TYPE_BOTH_EDGE);
/* Enable interrupt for the specified GPIO Input Pin. */
GPIOPinIntEnable(GPIO_INSTANCE_ADDRESS_0, GPIO_INT_LINE_1, GPIO_CD_PIN_NUM);
/* Clear the Interrupt Status of the GPIO Card Detect pin. */
//GPIOPinIntClear(GPIO_INSTANCE_ADDRESS_0, GPIO_INT_LINE_1, GPIO_CD_PIN_NUM);
while(1)
{
/* Read the data on the GPIO Card Detect Pin. */
if(GPIOPinRead(GPIO_INSTANCE_ADDRESS_0, GPIO_CD_PIN_NUM))
{
/* Drive a logic LOW on the GPIO Pin controlling the LED. */
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_HIGH);
printf("Connected.\n");
}
else
{
/* Drive a logic HIGH on the GPIO Pin controlling the LED. */
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_LOW);
printf("Disconnected\n");
}
if(1 == gpioIsrFlag)
{
CheckCardStatus();
}
}
}
/*
** This function checks the insertion and ejection status of the MicroSD card
** and does appropriate operations.
*/
static void CheckCardStatus(void)
{
/* Read the data on the GPIO Card Detect Pin. */
if(GPIOPinRead(GPIO_INSTANCE_ADDRESS_0, GPIO_CD_PIN_NUM))
{
printf("Connection removed.\n");
/* Drive a logic LOW on the GPIO Pin controlling the LED. */
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_LOW);
}
else
{
printf("Connection added.\n");
/* Drive a logic HIGH on the GPIO Pin controlling the LED. */
GPIOPinWrite(GPIO_INSTANCE_ADDRESS, GPIO_INSTANCE_PIN_NUMBER, GPIO_PIN_HIGH);
}
gpioIsrFlag = 0;
}
/*
** GPIO Interrupt Service Routine.
*/
static void GPIOIsr(void)
{
printf("Enter interrupt routine.");
/* Check the Interrupt Status of the GPIO Card Detect pin. */
if(GPIOPinIntStatus(GPIO_INSTANCE_ADDRESS_0, GPIO_INT_LINE_1, GPIO_CD_PIN_NUM) & (1 << GPIO_CD_PIN_NUM))
{
/* Clear the Interrupt Status of the GPIO Card Detect pin. */
GPIOPinIntClear(GPIO_INSTANCE_ADDRESS_0, GPIO_INT_LINE_1, GPIO_CD_PIN_NUM);
}
gpioIsrFlag = 1;
}
static void GPIOINTCConfigure(void)
{
/* Initialize the ARM Interrupt Controller. */
IntAINTCInit();
/* Register the Interrupt Service Routine(ISR). */
IntRegister(GPIO_INST_SYS_INT_NUM, GPIOIsr);
/* Set the priority for the GPIO0 system interrupt in INTC. */
IntPrioritySet(GPIO_INST_SYS_INT_NUM, 0, AINTC_HOSTINT_ROUTE_IRQ);
/* Enable the GPIO0 system interrupt in INTC. */
IntSystemEnable(GPIO_INST_SYS_INT_NUM);
}
/*
** A function which is used to generate a delay.
*/
static void Delay1(volatile unsigned int count)
{
while(count--);
}
/******************************* End of file *********************************/

