Electronic – MSP430 how to make configurable ISRs in a module (Code composer studio C)

cinterruptsisrmicrocontrollermsp430

I have a question that I think the answer to is quite simple. But I've been unable to find a straight answer to.

If i have this service routine in some module foo.c

#pragma vector = SOME_VECTOR
interrupt void fooISR(){
    dosomething;
    IFG = 0;
}

if i have in my main.

#include "foo.h"

Then it appears that the fooISR() does indeed get loaded into the SOME_VECTOR and the ISR will trigger whenever the corresponding IFG is set.

I wanted to ask if this is the right way to write modules that utilize interrupts. Because with this approach the fooISR() will be in the SOME_VECTOR whenever I include foo.h this doesn't really allow for much configuration for the person working in main.

For example if in main.c I wanted to access some functionality of foo.c but wanted to write a separate ISR for SOME_VECTOR I'd be outta luck with this method right?

Best Answer

The concern that you express in the last paragraph is correct. It doesn't seem to be a good idea to bundle an ISR with other functionality that you might want to reuse separately from the ISR.

I usually do one of the 3 things:

  • Put the ISRs and main into the same file as main(). ISRs are short, so they don't clutter the main.c too much.
  • Put all ISRs together into a separate module. No other functionality in that module. No intention to make this ISRs module reusable.
  • Put each ISR into its own module. No other functionality in those modules.

You could put the ISR inside of an #ifdef block, if it makes sense in your particular situation.