0
\$\begingroup\$

Suppose I have a library consisting of TWI.h and TWI.c which contains an ISR defined according to AVR-GCC syntax. For example:

ISR(TWI_vect)
{
   switch(TWCR)
   {
       ...
   }
}

Should the ISR code go into TWI.h or TWI.c? Or should I put the full ISR in TWI.c and put some sort of ISR "prototype" in TWI.h?

\$\endgroup\$
  • 2
    \$\begingroup\$ Generally, any executable or memory consuming code should go into the *.c files. There are cases it is not like that, but they should be well justified. \$\endgroup\$ – Eugene Sh. Mar 3 '17 at 18:56
4
\$\begingroup\$

The ISR belongs in the .c file. It's a function that directly generates code that's linked into the executable (that is, it isn't an inline-only function), so that's where it goes.

The ISR shouldn't be called by other functions, so it does not need a declaration in the header file.

\$\endgroup\$
1
\$\begingroup\$

Too minimize scoping issues, only those referenced by a calling party should be in the header.

Your Isr is generally not called by others so make it private to thee .C files IS thee way to go.

What I generally do is to insert a call back function in there soon that the user can install his own Isr.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.