small syntax problem with C code (implemented in Code Composer Studio)
I'm writing some C code in Code Composer Studio that will be built onto a TI DSP and I'm having a minor problem with my code. When I write my code and build the project it gives me the following errors:
line 100: error: declaration may not appear after executable statement in block interrupt void TINT0_prd_clock (void) "user_lab3.c", line 100: error: expected a "}" interrupt void TINT0_prd_clock (void) I tried doing a function declaration at the top of my code but it didn't change any of the errors. I attempted to put in the } in line 100 as it asks for and then I get more errors. I don't know if this has to do with fact that this is an interrupt function but I think it's just a minor C syntax error. I've tried as best as I can to put in opening and closing parentheses to get rid of this error thinking that I might just have nested parentheses somewhere that has stuff grouped together in the wrong fashion but that hasn't helped. I would post my code but it's about 300 lines long and don't want to make this post obnoxiously large but if anyone wants to see it I can send it. Thanks |
Hmm, I doubt anyone will be able to help without seeing the code. Let's have a look and see if I can help.
|
As per your request, here is the code. Keep in mind that there are some custom header files that call specific functions needed to build the code onto the DSP but that's not the issure here I don't think. Here is the code:
//#include "coecsl.h" #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File int inttimer = 0; int intcount = 0; int countout = 0; int LED = 0; int temp = 0; #include "DSP281x_Device.h" // DSP281x Headerfile Include File #include "DSP281x_Examples.h" // DSP281x Examples Include File #include "f:\f2812 \coecsl\coecsl.h" //????????????????????????????? // Prototype statements for functions found within this file. interrupt void adc_isr(void); // Global variables used in this example: Uint16 LoopCount; Uint16 ConversionCount; // #pragma directive tell the C compiler to locate the data // buffer in a certain section of memory. In this // case we want to locate the buffer in external RAM // so that large number of data points can be stored #pragma DATA_SECTION(Voltage1,"extdata"); #pragma DATA_SECTION(Voltage2,"extdata"); Uint16 Voltage1[10]; Uint16 Voltage2[10]; // You can make these two vectors much larger interrupt void eva_timer1_isr(void); void init_eva_timer1(void); volatile Uint32 time_ms = 0; Uint32 EvaTimer1InterruptCount; void init_eva_timer1(void) { // Initialize EVA Timer 1: // Setup Timer 1 Registers (EV A) EvaRegs.GPTCONA.all = 0; // Set the Period for the GP timer 1 to 0x0200; EvaRegs.T1PR = HISPCLK_KHZ/128; // Period //EvaRegs.T1PR = 40000*2/128; EvaRegs.T1CMPR = 0x0000; // Compare Reg // Enable Period interrupt bits for GP timer 1 // Count up, x128, internal clk, enable compare, use own period EvaRegs.EVAIMRA.bit.T1PINT = 1; EvaRegs.EVAIFRA.bit.T1PINT = 1; // Clear the counter for GP timer 1 EvaRegs.T1CNT = 0x0000; // EvaRegs.T1CON.all = 0x1742; EvaRegs.T1CON.all = 0x1342; // Start EVA ADC Conversion on timer 1 Period interrupt // EvaRegs.GPTCONA.bit.T1TOADC = 2; } interrupt void eva_timer1_isr (void) { temp++; switch(temp%500) { case 0: EvaTimer1InterruptCount++; LED=LED+256; break; case 1: GpioDataRegs.GPBDAT.all=(GpioDataRegs.GPBDAT.all & 0xC0FF) | (LED & 0x3F00); serial_printf(&SerialB,"time=%ld\n\r", EvaTimer1InterruptCount/500); break; } //enables timer 1 EvaRegs.EVAIMRA.bit.T1PINT =1; //sets flag for timer 1 EvaRegs.EVAIFRA.all = BIT7; // Acknowledge interrupt to receive more interrupts from PIE group 2 PieCtrlRegs.PIEACK.all = PIEACK_GROUP2; // prd clock interrupt interrupt void TINT0_prd_clock(void) { // this functions only task is to increment the integer time_ms. The global // variable time_ms is monitored in the main() function to perform low priority // periodic tasks. time_ms++; // clear cpu timer interrupt flags CpuTimer0Regs.TCR.bit.TIF = 1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; } // initialize prd clock void init_prd(void) { // set interrupt function EALLOW; PieVectTable.TINT0 = &TINT0_prd_clock; EDIS; // initialize cpu timer (32bit) InitCpuTimers(); // Set clock period given input frequency in MHz and output period in microseconds ConfigCpuTimer(&CpuTimer0, (float) SYSCLKOUT_KHZ/1000.0F, 1000); // clear and enable cpu timer interrupt // Enable TINT0 in the PIE: Group 1 interrupt 7 PieCtrlRegs.PIEIER1.bit.INTx7 = 1; // Enable CPU_INT1 which is connected to CPU-Timer 0 IER |= M_INT1; // Clear Pending Group 1 interrupts PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // start cpu timer StartCpuTimer0(); } interrupt void adc_isr(void) { Voltage1[ConversionCount] = AdcRegs.ADCRESULT0 >>4; Voltage2[ConversionCount] = AdcRegs.ADCRESULT1 >>4; // If 40 conversions have been logged, start over if(ConversionCount == 9) { ConversionCount = 0; } else ConversionCount++; // Reinitialize for next ADC sequence - see SPRU060B AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1; // Reset SEQ1 see pp 2-5 AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1; // Clear INT SEQ1 bit see pp 2-14 //---------------------------------------------------------- --- PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge interrupt to PIE return; } int main(void) { Uint32 prd_ms = 0; int toggle_cnt = 0; int display_cnt = 0; // Initialize Flash, External RAM, and PLL init_COECSL(); // Initialize the off chip SPI Flash chip init_dataflash(); // Initialize Serial Port B to 115200 Baud init_serial(&SerialB,115200,NULL); // Initialize 8 bits for Port A. NOTE!! The mux function MUST be selected before // the Direction is set. EALLOW; GpioMuxRegs.GPAMUX.bit.PWM1_GPIOA0 = 0; GpioMuxRegs.GPAMUX.bit.PWM2_GPIOA1 = 0; GpioMuxRegs.GPAMUX.bit.PWM3_GPIOA2 = 0; GpioMuxRegs.GPAMUX.bit.PWM4_GPIOA3 = 0; GpioMuxRegs.GPAMUX.bit.PWM5_GPIOA4 = 0; GpioMuxRegs.GPAMUX.bit.PWM6_GPIOA5 = 0; GpioMuxRegs.GPAMUX.bit.T1PWM_GPIOA6 = 0; GpioMuxRegs.GPAMUX.bit.T2PWM_GPIOA7 = 0; GpioMuxRegs.GPADIR.bit.GPIOA0 = 1; GpioMuxRegs.GPADIR.bit.GPIOA1 = 1; GpioMuxRegs.GPADIR.bit.GPIOA2 = 1; GpioMuxRegs.GPADIR.bit.GPIOA3 = 1; GpioMuxRegs.GPADIR.bit.GPIOA4 = 1; GpioMuxRegs.GPADIR.bit.GPIOA5 = 1; GpioMuxRegs.GPADIR.bit.GPIOA6 = 1; GpioMuxRegs.GPADIR.bit.GPIOA7 = 1; EDIS; // simple periodic handler init_prd(); // Enable the Global interrupt EINT; // Enable the Real-time debugging interrupt. Currently not in use. But may use in the future. ERTM; //Interrupts that are used in this example are re- mapped to // ISR functions found within this file. EALLOW; // This is needed to write to EALLOW protected register PieVectTable.ADCINT = &adc_isr; //this interupt is called at teh end of each ADC conversion sequence (two ch.) EDIS; // This is needed to disable write to EALLOW protected registers // Step 4. Initialize all the Device Peripherals: // This function is found in DSP281x_InitPeripherals.c // InitPeripherals(); // Not required for this example InitAdc(); // For this example, init the ADC (fortunately, this has been done for us) LoopCount = 0; ConversionCount = 0; // Configure ADC (see SPRU060B) AdcRegs.ADCMAXCONV.all = 0x0001; // Setup 2 conv's on SEQ1 -- Table 2-1 AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA0 as 1st SEQ1 conv. -- Sect. 2.5 AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup ADCINA1 as 2nd SEQ1 conv. AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1 --pp. 2-4 & 2-6 AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS) --pp. 2-5 (bit 11) AdcRegs.ADCTRL1.bit.ACQ_PS = 4; // Current guess at the sample hold timing --sect. 1.4 AdcRegs.ADCTRL3.bit.ADCCLKPS = 9; // Current guess at the ADCCLK value 4.16MHz --sect. 1.4.1 // see also Ex. 1-3 pp 1-23 EvaRegs.GPTCONA.bit.T1TOADC = 2; // Enable EVASOC in EVA on Timer Period Event --5-5 & 5-7 EvaRegs.T1CON.all = 0x1342; // Enable timer 1 (upcount mode) with prescale set to 8 -- 5-3 // TMODE1 =1 for a continuous upcount // TPS1,TPS0 = 11 (binary) --> Clock divided by 8 // TENABLE = 1 to enable the timer // TECMPR=1 to enable compare // Configure EVA // Assumes EVA Clock is already enabled in InitSysCtrl(); // See SPRU065B note Fig 1-1 EvaRegs.T1PR = 2.0 * (HISPCLK_KHZ >> EvaRegs.T1CON.bit.TPS); // 2 ms period (see pp 5-3 // Step 5. User specific code, enable interrupts: // Enable ADCINT in PIE PieCtrlRegs.PIEIER1.bit.INTx6 = 1; IER |= M_INT1; // Enable CPU Interrupt 1 EINT; // Enable Global interrupt INTM ERTM; // Enable Global realtime interrupt DBGM // Perform background task while(1) { LoopCount++; } for (;;) { // Wait here for prd_ms to match actual time determined by time_ms while (prd_ms >= time_ms) {} prd_ms++; // 1000 ms prd (stagger periodic functions) // These tasks run once a second switch (prd_ms%1000) { case 0: // First 1000ms Task serial_printf(&SerialB,"time=% ld\n\r", prd_ms); break; case 1: // Second 1000ms Task // set LEDS 0-3 to lower 4 bits of count value; GpioDataRegs.GPADAT.all = (GpioDataRegs.GPADAT.all & 0xFFF0) | (display_cnt & 0xF); display_cnt++; break; case 2: // Third 1000ms Task // just here to show example break; } // 250 ms prd (stagger periodic functions) // These tasks run 4 times a second switch (prd_ms%250) { case 0: // First 250ms Task serial_printf(&SerialB,"ledstate=0x% x\n\r", (int) (GpioDataRegs.GPADAT.all) & 0xFF); break; case 1: // Second 250ms Task // blink LEDS 4-7 if (toggle_cnt == 0) { toggle_cnt = 1; GpioDataRegs.GPATOGGLE.bit.GPIOA4 = 1; GpioDataRegs.GPATOGGLE.bit.GPIOA6 = 1; } else { toggle_cnt = 0; GpioDataRegs.GPATOGGLE.bit.GPIOA5 = 1; GpioDataRegs.GPATOGGLE.bit.GPIOA7 = 1; } break; } } } |
Got it. There's no } at the end of the eva_timer1_isr (void) function.
|
Awesome, thanks a lot man.
|
No problem. I know how easy it can be to miss things like that.
|
Whrer can i find coecsl.h?? need help here..
|
All times are GMT -5. The time now is 09:43 PM. |