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?
-
2\$\begingroup\$ Is nesting function definitions not prohibited in C? \$\endgroup\$user28910– user289102013年11月26日 20:45:14 +00:00Commented Nov 26, 2013 at 20:45
-
1\$\begingroup\$ And even if you could, why would you want to? \$\endgroup\$user28910– user289102013年11月26日 20:53:15 +00:00Commented Nov 26, 2013 at 20:53
-
2\$\begingroup\$ XY problem: You are asking about your attempted solution rather than your actual problem. \$\endgroup\$Rev– Rev2013年11月26日 21:11:59 +00:00Commented 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\$Passerby– Passerby2013年11月26日 21:57:26 +00:00Commented 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\$Rev– Rev2013年11月27日 07:55:23 +00:00Commented Nov 27, 2013 at 7:55
1 Answer 1
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.
-
\$\begingroup\$ Hmm, I could do if defined checks... \$\endgroup\$Passerby– Passerby2013年11月26日 21:11:05 +00:00Commented Nov 26, 2013 at 21:11