1
\$\begingroup\$

As the title said, I am trying to see if an Interrupt Vector can be embedded inside a function? I am using IAR, but gcc or ccs would work too. I don't see it done in any code online. Example:

void function_funtime (int test){
 int lm4970_state = 0;
 int abc = test + 3;
 // Port 1 interrupt service routine
 #pragma vector = PORT1_VECTOR
 __interrupt void Port_1_ISR (void)
 {
 _BIC_SR_IRQ(LPM3_bits + GIE); // Clear LPM/Disable Interrupts
 lm4970_state++; // Increase LM4970 state by 1
 P1IFG &= ~PB; // P1.3 IFG cleared
 }
}

Function "function_funtime" is called from the main code before the interrupt is ever seen. Can this be done?

asked Nov 26, 2013 at 20:40
\$\endgroup\$
8
  • 2
    \$\begingroup\$ Is nesting function definitions not prohibited in C? \$\endgroup\$ Commented Nov 26, 2013 at 20:45
  • 1
    \$\begingroup\$ And even if you could, why would you want to? \$\endgroup\$ Commented Nov 26, 2013 at 20:53
  • 2
    \$\begingroup\$ XY problem: You are asking about your attempted solution rather than your actual problem. \$\endgroup\$ Commented Nov 26, 2013 at 21:11
  • 1
    \$\begingroup\$ @Rev1.0 making tidy code that I can move between projects without having to pick through which ISR goes with which functions, without needing ifdefined checks or anything like that. \$\endgroup\$ Commented Nov 26, 2013 at 21:57
  • 1
    \$\begingroup\$ Hmm, if you want to "share" code between projects, wouldn't it be cleaner to create an independent module (c/h file combo)? That way you can encapsulate the ISR and just expose function_funtime() from the header. \$\endgroup\$ Commented Nov 27, 2013 at 7:55

1 Answer 1

1
\$\begingroup\$

No.

You can't define a function inside of another function in C. I'm not sure what you're trying to do, but maybe you can set flags for the ISR in the function or simply enable the interrupt in the function. Either of those may have the same effect.

answered Nov 26, 2013 at 20:56
\$\endgroup\$
1
  • \$\begingroup\$ Hmm, I could do if defined checks... \$\endgroup\$ Commented Nov 26, 2013 at 21:11

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.