Quantcast
Channel: Processors forum - Recent Threads
Viewing all articles
Browse latest Browse all 17527

TMS320C5535: Interrupt not going to ISR

$
0
0

Part Number:TMS320C5535

Using the examples from the CSL support library, I've tried to set up a GPT interrupt that blinks an LED on and off so that I can get familiar with the processor. However, I can't seem to set it up correctly because the program never enters the ISR. To help with the debugging, I initialized a flag and am trying to toggle the flag in the ISR at a rate of 1 second using a GPT with a system clock of 100Mhz. 

My code is as follows: 

#include <stdio.h>
#include <stdint.h>
#include <csl_general.h>
#include "csl_sysctrl.h"
#include "csl_gpio.h"
#include "csl_intc.h"
#include "csl_gpt.h"
#include "csl_pll.h"
#include "csl_pllAux.h"

/////////////* Preprocessor Directives */////////////
#define CSL_TEST_FAILED    (1u)
#define CSL_TEST_PASSED    (0)
#define CSL_PLL_CLOCKIN    (32768u)

/////////////* Function Forward Declarations */////////////
int EBSR_init(void);
int GPIO_init(void);
int GPT_init(void);

/////////////* Global Variables */////////////
Uint32 sysClk = 0;
Uint16 readLED1_Val;
Uint16 readLED2_Val;

/////////////* Global Structs and Objects */////////////
CSL_GpioObj gpioObj;
CSL_GpioObj *hGpio;

PLL_Obj pllObj;
PLL_Obj *hPll;

PLL_Config pllCfg1;
PLL_Config *pConfigInfo;

PLL_Config pllCfg_100MHz = { 0x8BE8, 0x8000, 0x0806, 0x0000 };

/////////////* Volatile Variables */////////////
extern void VECSTART(void);
interrupt void blinkLED(void);
volatile Bool flag = 0;

Uint32 ctrVal = 0;
CSL_Handle hGpt;

/////////////* Main Function */////////////
int main(void)
{
    /////////////* Initializations */////////////
    int result;

    PLL_init(&pllObj, CSL_PLL_INST_0);
    hPll = (PLL_Handle) (&pllObj);

    PLL_reset(hPll);

    /* Configure the PLL for 100MHz */
    pConfigInfo = &pllCfg_100MHz;
    PLL_config(hPll, pConfigInfo);

    result = EBSR_init();
    result = GPIO_init();
    result = GPT_init();


    while (result != CSL_SOK)
    {
    }; // Catches errors
    /////////////* Infinite Loop */////////////
    while (1){
        GPT_getCnt( hGpt, &ctrVal);
    }
}

/////////////* Function Definitions */////////////
int EBSR_init(void)
{
    CSL_Status status;

    status = SYS_setEBSR(CSL_EBSR_FIELD_PPMODE, CSL_EBSR_PPMODE_1);
    status |= SYS_setEBSR(CSL_EBSR_FIELD_SP1MODE, CSL_EBSR_SP1MODE_1);
    status |= SYS_setEBSR(CSL_EBSR_FIELD_SP0MODE, CSL_EBSR_SP0MODE_1);

    if (status != CSL_SOK)
    {
        return (CSL_TEST_FAILED);
    }

    return status;

}

int GPIO_init()
{
    CSL_Status status;
    CSL_GpioConfig config;

    /* Open GPIO Module */
    hGpio = GPIO_open(&gpioObj, &status);

    if (hGpio == NULL || status != CSL_SOK)
    {
        return (CSL_TEST_FAILED);
    }

    GPIO_reset(hGpio); // Resets all pins to default values

    /* Configure GPIO module */
    config.GPIODIRL = 0x9420;
    config.GPIODIRH = 0x0002;
    config.GPIOINTTRIGL = 0x0010;
    config.GPIOINTTRIGH = 0x0000;
    config.GPIOINTENAL = 0x4810;
    config.GPIOINTENAH = 0x0001;

    status = GPIO_config(hGpio, &config);

    /* Config PDINHIBRn regs */
    ioport volatile CSL_SysRegs *sysRegs;
    sysRegs = (CSL_SysRegs *)CSL_SYSCTRL_REGS;
    sysRegs->PDINHIBR1 = CSL_SYS_PDINHIBR1_RESETVAL;                                                // Config PDINHIBR1
    CSL_FINS(sysRegs->PDINHIBR2, SYS_PDINHIBR2_INT0PU, CSL_SYS_PDINHIBR2_INT0PU_ENABLE);            // Config PDINHIBR2
//    sysRegs->PDINHIBR3 =


    if (status != CSL_SOK)
    {
        return (CSL_TEST_FAILED);
    }

    else
        return CSL_TEST_PASSED;
}

int GPT_init(void)
{
    CSL_Status status;
    CSL_Config hwConfig;
    CSL_GptObj gptObj;

    /* Get the System clock value at which CPU is currently running */
    sysClk = getSysClk();

    /* Open the CSL GPT module */
    hGpt = GPT_open(GPT_0, &gptObj, &status);

    /* Reset the GPT module */
    status = GPT_reset(hGpt);

    // Initialize ISRs
    /* Disable CPU interrupt */
    IRQ_globalDisable();

    /* Clear any pending interrupts */
    IRQ_clearAll();

//    /* Disable all the interrupts */
//    IRQ_disableAll();

    /* Initialize Interrupt Vector table */
    IRQ_setVecs((Uint32) (&VECSTART));
//
//    /* Clear any pending Interrupt */
//    IRQ_clear(TINT_EVENT);

    IRQ_plug(TINT_EVENT, &blinkLED);

    /* Enabling Interrupt */
    IRQ_enable(TINT_EVENT);

    hwConfig.autoLoad = GPT_AUTO_ENABLE;
    hwConfig.ctrlTim = GPT_TIMER_ENABLE;
    hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;// 100Mhz/4 = 25Mhz
    hwConfig.prdLow = (sysClk)/4;           // Period 250,000 ticks
    hwConfig.prdHigh = 0x0000;              // So 1 second interval

    /* Configure the GPT module */
    status = GPT_config(hGpt, &hwConfig);

    IRQ_globalEnable();
    /* Start the Timer */
    GPT_start(hGpt);

    GPT_getCnt(hGpt, &ctrVal);

    return status;

}

interrupt void blinkLED(void)
{
    IRQ_clear(TINT_EVENT);
    CSL_SYSCTRL_REGS->TIAFR = 0x01;
    if (flag == 0){ flag = 1;}
    if (flag == 1){ flag = 0;}


//    GPIO_read(hGpio, CSL_GPIO_PIN15, &readLED1_Val);
//    if ( readLED1_Val == 1 )
//    {
//        GPIO_write(hGpio, CSL_GPIO_PIN15, 0);
//    }
//
//    else GPIO_write(hGpio, CSL_GPIO_PIN15, 1);
//
//    GPIO_read(hGpio, CSL_GPIO_PIN12, &readLED2_Val);
//    if ( readLED2_Val == 0 )
//    {
//        GPIO_write(hGpio, CSL_GPIO_PIN12, 0);
//    }
//
//    else GPIO_write(hGpio, CSL_GPIO_PIN12, 1);

}


Any guidance or advice would be greatly appreciated!


Viewing all articles
Browse latest Browse all 17527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>