Tool/software: Code Composer Studio
I'm developing on a TMS320C5535 using the XDS110 debugger, the C5000 chip support library, and Code Composer version: 8.2.0.00007. I'm trying to initialize the general purpose timer (GPT0) peripheral to blink an LED and I'm coming across a strange behavior in my code. I originally had:
CASE 1
/////////////* Main Function *///////////// int main(void) {
CSL_Status SYS_status;
/////////////* System Level Initializations *///////////// SYS_status = SYS_PLL_LDO_init(); SYS_status = SYS_EBSR_init(); SYS_status = SYS_GPIO_init(); SYS_status = SYS_I2C_init(); SYS_status = SYS_SPI_init(); SYS_status = SYS_UART_init(); SYS_status = SYS_RTC_init(); SYS_status = SYS_GPT_init(); /* Initialize Interrupt Vector table */ IRQ_setVecs((Uint32) (&VECSTART)); /////////////* Initialize ISRs *///////////// IRQ_globalDisable(); // Disable CPU interrupts IRQ_clearAll(); // Clear any pending interrupt IRQ_disableAll(); // Disable all interrupts IRQ_plug(GPIO_EVENT, &GPIO_isr); IRQ_plug(INT1_EVENT, &ADS_DRDY_isr); IRQ_plug(RTC_EVENT, &RTC_isr); IRQ_plug(TINT_EVENT, &GPT_isr); // IRQ_enable(GPIO_EVENT); // Enable interrupt // IRQ_enable(INT1_EVENT); // Enable interrupt // IRQ_enable(RTC_EVENT); // Enable interrupt IRQ_enable(TINT_EVENT); IRQ_globalEnable(); // Enable CPU interrupts SYS_status = GPT_start(hGpt0); /////////////* Infinite Loop *///////////// while (1) { } }
where SYS_GPT_init() is:
CSL_Status SYS_GPT_init(void){ CSL_Status status; CSL_Config hwConfig; CSL_GptObj gptObj; hGpt0 = GPT_open(GPT_0, &gptObj, &status); // hGpt1 = GPT_open(GPT_1, &gptObj, &status); // hGpt2 = GPT_open(GPT_2, &gptObj, &status); status |= GPT_reset(hGpt0); // status |= GPT_reset(hGpt1); // status |= GPT_reset(hGpt2); // Setup GPT0 to 1 second to blink LEDs hwConfig.autoLoad = GPT_AUTO_ENABLE; hwConfig.ctrlTim = GPT_TIMER_ENABLE; hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;// 100Mhz/4 = 25Mhz hwConfig.prdLow = 0x7840; // Period 25,000,000 ticks hwConfig.prdHigh = 0x017D; // So 1 second interval /* Configure the GPT module */ status |= GPT_config(hGpt0, &hwConfig); return status; }
I expect the GPT to trigger an LED through an ISR (not shown) but nothing happens.
CASE 2:
However, when I remove the SYS_GPT_init() function and put the contents of the function directly into main():
See line 13: SYS_GPT_init() was commented out
See lines 15-35: the code from SYS_GPT_init() is inserted there
int main(void) { CSL_Status SYS_status; /////////////* System Level Initializations *///////////// SYS_status = SYS_PLL_LDO_init(); SYS_status = SYS_EBSR_init(); SYS_status = SYS_GPIO_init(); SYS_status = SYS_I2C_init(); SYS_status = SYS_SPI_init(); SYS_status = SYS_UART_init(); SYS_status = SYS_RTC_init(); // SYS_status = SYS_GPT_init(); CSL_Status status; CSL_Config hwConfig; CSL_GptObj gptObj; hGpt0 = GPT_open(GPT_0, &gptObj, &status); // hGpt1 = GPT_open(GPT_1, &gptObj, &status); // hGpt2 = GPT_open(GPT_2, &gptObj, &status); status |= GPT_reset(hGpt0); // status |= GPT_reset(hGpt1); // status |= GPT_reset(hGpt2); // Setup GPT0 to 1 second to blink LEDs hwConfig.autoLoad = GPT_AUTO_ENABLE; hwConfig.ctrlTim = GPT_TIMER_ENABLE; hwConfig.preScaleDiv = GPT_PRE_SC_DIV_1;// 100Mhz/4 = 25Mhz hwConfig.prdLow = 0x7840; // Period 25,000,000 ticks hwConfig.prdHigh = 0x017D; // So 1 second interval /* Configure the GPT module */ status |= GPT_config(hGpt0, &hwConfig); /* Initialize Interrupt Vector table */ IRQ_setVecs((Uint32) (&VECSTART)); /////////////* Initialize ISRs *///////////// IRQ_globalDisable(); // Disable CPU interrupts IRQ_clearAll(); // Clear any pending interrupt IRQ_disableAll(); // Disable all interrupts IRQ_plug(GPIO_EVENT, &GPIO_isr); IRQ_plug(INT1_EVENT, &ADS_DRDY_isr); IRQ_plug(RTC_EVENT, &RTC_isr); IRQ_plug(TINT_EVENT, &GPT_isr); // IRQ_enable(GPIO_EVENT); // Enable interrupt // IRQ_enable(INT1_EVENT); // Enable interrupt // IRQ_enable(RTC_EVENT); // Enable interrupt IRQ_enable(TINT_EVENT); IRQ_globalEnable(); // Enable CPU interrupts SYS_status = GPT_start(hGpt0); /////////////* Infinite Loop *///////////// while (1) { } }
The LED DOES begin to work and blinks as expected in CASE 2.
I have done a forward declaration for all functions already, so that should not be a problem.
Why is it that the LED/GPT does not work in case 1, but DOES work in case 2? Both cases SHOULD produce the same results because the code is exactly the same. The only difference between the two cases is that case 1 calls SYS_GPT_init() but case 2 does not call SYS_GPT_init().