TI中文支持网
TI专业的中文技术问题搜集分享网站

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************************************/

Gary Wu:

如果是学习,建议还是仔细研究代码

前提是你的硬件是work的

Tony Tang:

回复 Gary Wu:

请确认有在相关GPIO上给触发信号吗?

建议分两步调试:

#1. 手动设置相应的ESR寄存器,看是否能进中断,以确定中断向量与中断函数及CPU的中断配置正确。

#2. 将相应GPIO的方向设为输出,设置相应的SET_DATA寄存器位状态,产生GPIO触发信号。

Note that the direction of the GPIO signal does not have to be an input for the interrupt event generationto work. When a GPIO signal is configured as an output, the software can change the GPIO signal stateand, in turn, generate an interrupt. This can be useful for debugging interrupt signal connectivity.

fei wu1:

回复 bin cao:

你好,我想问一下在头文件中有GPIOBank6Pin12PinMuxSetup()函数,但是没有GPIOBank6Pin13PinMuxSetup()这个函数,是要自己写还是我没有把它include进来?

weiwei ai:

回复 fei wu1:

GPIOBank6Pin12PinMuxSetup()这个函数虽然在lcdkOMAPL138.h中定义了,但是编译的时候一直不通过,提示说未定义字符

undefined first referencedsymbol in file ——— —————-GPIOBank6Pin12PinMuxSetup ./main.obj

这是为什么啊?

Tony Tang:

回复 weiwei ai:

这个函数定义在\platform\lcdkOMAPL138\gpio.c里,所以请确认是否包含了相应的platform.lib,正确的目录应该为\binary\armv5\cgt_ccs\omapl138\lcdkOMAPL138\platform\Debug\platform.lib,不要弄成了evmOMAPL138目录下的platfrom.lib。

weiwei ai:

回复 Tony Tang:

嗯嗯,好的,谢谢!能帮忙看下我intcVectorTable的那个问题吗?

weiwei ai:

回复 Tony Tang:

_intcVectorTable与intcVectorTable是在OMAPL138_StarterWare_1_10_04_01\system_config\c674x中找到的并添加进去的,但是里面只是对其进行了申明,内容没有定义,这是为什么?要自己编写中断向量表吗?

赞(0)
未经允许不得转载:TI中文支持网 » omapl138外部中断
分享到: 更多 (0)