This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

omapl138外部中断

辛勤的工程师及各位大神好:

小弟最近在用omapl138学习6748,想利用板子上的button实现一个外部中断,结合starterware中的一些例程写好了程序,但是中断不运行,一直摸不着头脑,请各位大神指导。

#include "gpio.h"

 #include "psc.h"

#include "interrupt.h"

#include "soc_C6748.h"

 #include "lcdkC6748.h"

/****************************************************************************/

 /*              LOCAL FUNCTION PROTOTYPES                                   */

/****************************************************************************/

static void ConfigureInt(void);

static void ButtonTriggerLED(void);

static void GPIOIsr(void);

static void Delay(volatile unsigned int delay);

/****************************************************************************/

/*              GLOBAL VARIABLES                                            */

 /****************************************************************************/

volatile unsigned char flag = 0;

/****************************************************************************/

 /*             LOCAL FUNCTION DEFINITIONS                                   */

 /****************************************************************************/

void main(void)

 {

    /* The Local PSC number for GPIO is 3. GPIO belongs to PSC1 module.*/

     PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_GPIO, PSC_POWERDOMAIN_ALWAYS_ON,        PSC_MDCTL_NEXT_ENABLE);

    /* Pin Multiplexing of pin 12 & 13 of GPIO Bank 6.*/

     GPIOBank6Pin12PinMuxSetup();

     GPIOBank6Pin13PinMuxSetup();

     GPIOBank2Pin4PinMuxSetup();

     GPIOBank2Pin5PinMuxSetup();

 

    /* Sets the pin 109 (GP6[12]) & 110 (GP6[13]) as output.*/

     GPIODirModeSet(SOC_GPIO_0_REGS, 109, GPIO_DIR_OUTPUT);

     GPIODirModeSet(SOC_GPIO_0_REGS, 110, GPIO_DIR_OUTPUT);

 

    /* Sets the pin 37 (GP2[4]) & 38 (GP2[5]) as input.*/

     GPIODirModeSet(SOC_GPIO_0_REGS, 37, GPIO_DIR_INPUT);

     GPIODirModeSet(SOC_GPIO_0_REGS, 38, GPIO_DIR_INPUT);

 

    /* Configure rising edge trigger on pin 37 (GP2[4]) & 38 (GP2[5]) to generate an interrupt.*/

     GPIODirModeSet(SOC_GPIO_0_REGS, 37, GPIO_INT_TYPE_RISEDGE);

     //GPIODirModeSet(SOC_GPIO_0_REGS, 38, GPIO_INT_TYPE_RISEDGE);

 

    /*Enable interrupts for Bank 2.*/

     GPIOBankIntEnable(SOC_GPIO_0_REGS, 2);

 

    ConfigureInt();

 

    while(1)

     {

            if(flag == 1)

            {

                  ButtonTriggerLED();

             }

     }

}//end of main

/*

 ** \brief  This function sets up the status of interrupt.

 **

*/

static void ConfigureInt(void)

 {

     IntDSPINTCInit();         //initialize the interrupt controller

     IntGlobalEnable();         //enable DSP CPU interrupts globally

    IntRegister(C674X_MASK_INT4, GPIOIsr);    //register the ISR in the interrupt vector table

     IntEventMap(C674X_MASK_INT4, SYS_INT_GPIO_B2INT); //map the system event GPIO_Bank2(BUTTON) to CPU INT4

     IntEnable(C674X_MASK_INT4);       //enable the CPU masked INT4

     IntEventSet(SYS_INT_GPIO_B2INT);      //set the EVTFLAG register of GPIO_Bank2

}

/*

 ** \brief   Interrupt Service Routine to be executed on GPIO interrupts.

 **          This disables the bank interrupts, clears the system interrupt

 **          status and pin interrupt status. This also sets flag as 1.

*/

static void GPIOIsr(void)

 {

     /* Disable the interrupts for pins of bank 2 in GPIO.*/

     GPIOBankIntDisable(SOC_GPIO_0_REGS, 2);

 

    /* Clear the system interrupt status in the DSPINTC*/

     IntEventClear(SYS_INT_GPIO_B2INT);

 

    /* Clears the Interrupt Status of GP2[4] in GPIO.*/

     GPIOPinIntClear(SOC_GPIO_0_REGS, 37);

 

    flag = 1;

}

/*

 ** \brief   This function can respond the interrupt.

 */

 static void ButtonTriggerLED(void)

{

     Delay(0x1FFF);

    IntGlobalDisable();    //disable DSP CPU interrupts globally

 

    /* Clear the system interrupt status in the DSPINTC*/

     IntEventClear(SYS_INT_GPIO_B2INT);

 

    /* Clears the Interrupt Status of GP2[4] in GPIO.*/

     GPIOPinIntClear(SOC_GPIO_0_REGS, 37);

 

    if(GPIOPinRead(SOC_GPIO_0_REGS, 37))

     {

      GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_HIGH);

      GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_LOW);

     Delay(1000000);

     GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_LOW);

      GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_HIGH);

     Delay(1000000);

     }

    else

     {

      GPIOPinWrite(SOC_GPIO_0_REGS, 109, GPIO_PIN_LOW);

      GPIOPinWrite(SOC_GPIO_0_REGS, 110, GPIO_PIN_LOW);

     }

    flag = 0;

    /*Enable interrupts for Bank 2.*/

     GPIOBankIntEnable(SOC_GPIO_0_REGS, 2);

}

 

/*

 ** \brief   This function can be called to generate a delay.

 */

static void Delay(volatile unsigned int delay)

 {    

while(delay--);

 }

/*****************************END OF FILE************************************/