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.

TMS320C6678: GPIO Interrupt Setting

Part Number: TMS320C6678


Dear TI engineers:

I'm developing on C6678 without OS. And GPIO number 14 of C6678 is connected to FPGA on my board. I want to trigger GPIO interrupt on the rising edge of a 1kHz clock generated by FPGA. I configured GPIO by code I found on TI forum. And it turns out that DSP always enter ISR function for 239 times and then collapse, entering unkonwn address. I can not figure out what mistakes I've made and how to solve this problem. Please do me a favor. Thanks! Here is my code:

#include "ti/csl/csl_chip.h"
#include "ti/csl/csl_chipAux.h"
#include "ti/csl/src/intc/csl_intc.h"
#include "ti/csl/csl_gpio.h"
#include "ti/csl/csl_gpioAux.h"
#include <stdio.h>

CSL_IntcContext intcContext;
CSL_IntcEventHandlerRecord EventHandler[30];
CSL_IntcObj intcObj;
CSL_IntcHandle hTest;
CSL_IntcGlobalEnableState state;
CSL_IntcEventHandlerRecord EventRecord;
CSL_IntcParam vectId;
CSL_GpioHandle hGpio;


volatile int a = 0;

int count = 0;

interrupt void intIsr(void)
{
    a = 1;
    count++;

}

void main(void)
{
    //GpioInit(); //GPIO Initialization
    int pinNum;
    int bankNum;

    /************************************************
    *************** INTC Configuration *************
    ************************************************/

    printf ("Debug: GEM-INTC Configuration...\n");

    /* INTC module initialization */
    intcContext.eventhandlerRecord = EventHandler;
    intcContext.numEvtEntries = 10;
    if (CSL_intcInit(&intcContext) != CSL_SOK)
    {
        printf("Error: GEM-INTC initialization failed\n");
        return;
    }

    /* Enable NMIs */
    if (CSL_intcGlobalNmiEnable() != CSL_SOK)
    {
        printf("Error: GEM-INTC global NMI enable failed\n");
        return;
    }

    /* Enable global interrupts */
    if (CSL_intcGlobalEnable(&state) != CSL_SOK)
    {
        printf ("Error: GEM-INTC global enable failed\n");
        return;
    }

    /* Open the INTC Module for Vector ID: 4 and Event ID: 88 (GPIO_n in C6678)*/
    vectId = CSL_INTC_VECTID_4;
    hTest = CSL_intcOpen (&intcObj, 88, &vectId , NULL);
    if (hTest == NULL)
    {
        printf("Error: GEM-INTC Open failed\n");
        return;
    }

    /* Register an call-back handler which is invoked when the event occurs. */
    EventRecord.handler = &intIsr;
    EventRecord.arg = 0;
    if (CSL_intcPlugEventHandler(hTest,&EventRecord) != CSL_SOK)
    {
        printf("Error: GEM-INTC Plug event handler failed\n");
        return;
    }

    /* Enabling the events. */
    if (CSL_intcHwControl(hTest,CSL_INTC_CMD_EVTENABLE, NULL) != CSL_SOK)
    {
        printf("Error: GEM-INTC CSL_INTC_CMD_EVTENABLE command failed\n");
        return;
    }

    printf ("Debug: GEM-INTC Configuration Completed\n");

    // 1. Init Flag
    a = 0;
    printf("a = %d\n",a);

    // 2. Trigger GPIO_14 in Core0
    pinNum = 14;
    bankNum = 0;

    // Open the CSL GPIO Module 0
    hGpio = CSL_GPIO_open (0);

    // Set GPIO pin number as an input pin
    CSL_GPIO_setPinDirInput (hGpio, pinNum);

    // Set interrupt detection on GPIO pin to rising edge
    CSL_GPIO_setRisingEdgeDetect (hGpio, pinNum);

    // Enable GPIO per bank interrupt for bank zero
    CSL_GPIO_bankInterruptEnable (hGpio, bankNum);


    // 3. Wait for entering into ISR
    while(a!=1){}

    printf("a = %d\n",a);
    printf("GPIO interrupt occurs\n");

    while(1){}
}

  • Hi Li,

    Kindly follow the SDk documentation to give inteerupt via GPIO. URL : https://software-dl.ti.com/processor-sdk-rtos/esd/docs/latest/rtos/index_device_drv.html#gpio.

    Kindly refer the GPIO API reference guide in TI-RTOS SDK in following location : C:\ti\pdk_c667x_X_X_XX\packages\ti\drv\gpio\docs\doxygen\html\index.html

    Also, Refer the example of GPIO Interrupt customization (AM57X) in this link : https://software-dl.ti.com/processor-sdk-rtos/esd/docs/latest/rtos/index_how_to_guides.html#rtos-customization-using-an-external-input-to-trigger-an-interrupt-on-am57x

    Thanks,

    Rajarajan U

  • Hi Li,

    We can control GPIO using two libraries,

    1. CSL
    2. GPIO

    Code that you have implemented was using CSL API, the below code uses code functions from the CSL API (location : {TI_SDK_INSTALL_DIR}\pdk_c665x_2_0_16\packages\ti\csl\docs\doxygen\html\group___c_s_l___g_p_i_o.html

    I have modified your code,

        // 2. Trigger GPIO_14 in Module 0
        pinNum = 14; 
        bankNum = 0;
    
        // Open the CSL GPIO Module 0
        hGpio = CSL_GPIO_open (0);
    
    	// Enable GPIO per bank interrupt for bank zero
        CSL_GPIO_bankInterruptEnable (hGpio, bankNum);
    
        // Set GPIO pin number as an input pin
        CSL_GPIO_setPinDirInput (hGpio, pinNum);
    
        // Set interrupt detection on GPIO pin to rising edge
        CSL_GPIO_setRisingEdgeDetect (hGpio, pinNum);
    
       // Check interrupt status on pin 1
         while (CSL_GPIO_getInterruptStatus (hGpio, pinNum) == 0)
         {
             // Interrupt has not occured, waiting in while loop
    
         }

    Use this code in "main()", intead of "intIsr" interrupt. I am reaing the status of "Interrupt Status" register in while loop. This document helped in GPIO register info (link : GPIO for keystone devices 

    Thanks,

    Rajarajan U

  • Hi, Rajarajan, thanks for your reply!  It helps a lot. But in my project, there are some other functions to be implemented in "main()" , and the interrupt needs to be triggered periodically. So maybe I can't replace the  "intIsr" interrupt with a while loop in "main()".  Thank you again!

  • Hi Li,

    #include "ti/csl/csl_chip.h"
    #include "ti/csl/csl_chipAux.h"
    #include "ti/csl/src/intc/csl_intc.h"
    #include "ti/csl/csl_gpio.h"
    #include "ti/csl/csl_gpioAux.h"
    #include <stdio.h>
    
    CSL_IntcContext intcContext;
    CSL_IntcEventHandlerRecord EventHandler[30];
    CSL_IntcObj intcObj;
    CSL_IntcHandle hTest;
    CSL_IntcGlobalEnableState state;
    CSL_IntcEventHandlerRecord EventRecord;
    CSL_IntcParam vectId;
    CSL_GpioHandle hGpio;
    
    
    volatile int a = 0;
    
    int count = 0;
    
    interrupt void intIsr(void)
    {
        if (CSL_GPIO_getInterruptStatus (hGpio, pinNum) == 0)
        {
            a = 1;
            count++;
        }
    }
    
    void main(void)
    {
        //GpioInit(); //GPIO Initialization
        int pinNum;
        int bankNum;
    
        /************************************************
        *************** INTC Configuration *************
        ************************************************/
    
        printf ("Debug: GEM-INTC Configuration...\n");
    
        /* INTC module initialization */
        intcContext.eventhandlerRecord = EventHandler;
        intcContext.numEvtEntries = 10;
        if (CSL_intcInit(&intcContext) != CSL_SOK)
        {
            printf("Error: GEM-INTC initialization failed\n");
            return;
        }
    
        /* Enable NMIs */
        if (CSL_intcGlobalNmiEnable() != CSL_SOK)
        {
            printf("Error: GEM-INTC global NMI enable failed\n");
            return;
        }
    
        /* Enable global interrupts */
        if (CSL_intcGlobalEnable(&state) != CSL_SOK)
        {
            printf ("Error: GEM-INTC global enable failed\n");
            return;
        }
    
        /* Open the INTC Module for Vector ID: 4 and Event ID: 88 (GPIO_n in C6678)*/
        vectId = CSL_INTC_VECTID_4;
        hTest = CSL_intcOpen (&intcObj, 88, &vectId , NULL);
        if (hTest == NULL)
        {
            printf("Error: GEM-INTC Open failed\n");
            return;
        }
    
        /* Register an call-back handler which is invoked when the event occurs. */
        EventRecord.handler = &intIsr;
        EventRecord.arg = 0;
        if (CSL_intcPlugEventHandler(hTest,&EventRecord) != CSL_SOK)
        {
            printf("Error: GEM-INTC Plug event handler failed\n");
            return;
        }
    
        /* Enabling the events. */
        if (CSL_intcHwControl(hTest,CSL_INTC_CMD_EVTENABLE, NULL) != CSL_SOK)
        {
            printf("Error: GEM-INTC CSL_INTC_CMD_EVTENABLE command failed\n");
            return;
        }
    
        printf ("Debug: GEM-INTC Configuration Completed\n");
    
        // 1. Init Flag
        a = 0;
        printf("a = %d\n",a);
    
        // 2. Trigger GPIO_14 in Module 0
        pinNum = 14; 
        bankNum = 0;
    
        // Open the CSL GPIO Module 0
        hGpio = CSL_GPIO_open (0);
    
    	// Enable GPIO per bank interrupt for bank zero
        CSL_GPIO_bankInterruptEnable (hGpio, bankNum);
    
        // Set GPIO pin number as an input pin
        CSL_GPIO_setPinDirInput (hGpio, pinNum);
    
        // Set interrupt detection on GPIO pin to rising edge
        CSL_GPIO_setRisingEdgeDetect (hGpio, pinNum);
    
    
        // 3. Wait for entering into ISR
        while(a!=1){}
    
        printf("a = %d\n",a);
        printf("GPIO interrupt occurs\n");
    
        while(1){}
    }

    So maybe I can't replace the  "intIsr" interrupt with a while loop in "main()"

    I have modified the interrupt function to suit your condition, kindly check this works for you.

    Thanks,

    Rajarajan U