Electrical – Where should an ISR be declared in a library

avr-gccinterrupts

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?

Best Answer

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.