views:

446

answers:

3

Guys,

I know that when working with the MSP430F2619 and TI's CCSv4, I can get more than one interrupt to use the same interrupt handler with code that looks something like this:

#pragma vector=TIMERA1_VECTOR
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void){

ServiceWatchdogTimer();
}

My question is, when I find myself in that interrupt, is there a way to figure out which one of these interrupts got me here?

Thank you,

Joe

+2  A: 

Not really a "good" answer but why not make 2 separate interrupt handlers call the same function?

something like

__interrupt void Timer_A0_handler (void){
  Timer_Handler(0);
}
__interrupt void Timer_A1_handler (void){
  Timer_Handler(1);
}
void Timer_Handler(int which){
  if(which==1){
    ...
  }else{
    ...
  }
  ...
  ServiceWatchdogTimer();
}
Earlz
Note also, that there may be some platform specific way to figure out what interrupt is currently executing. I do not know this platform.
Earlz
I dont' like this idea because what I really want to do was setup a lookup table of specific handlers, so when the interrupt is called, it looks at the vector number, looks up the interrupt handler for that vector. If its NULL, throw an error, and if its not NULL, execute the handler. Your solution would get very messy.
TheDelChop
yea, it would. Sadly I don't see a way around it. Making an OS for the PC(x86) I wanted to do something similar and I had to end up writing self-modifying/duplicating code to populate the look up table at runtime. It wasn't pretty either, but much more pretty than over 32 duplicate functions for each interrupt I handle.
Earlz
+1  A: 

Looking at the MSP430x1xx Family User's Guide, it looks like the device doesn't maintain a interrupt status register with that information directly. You'll either need to have 2 separate interrupts vectors so you can identify the difference directly, or you'll need to query both devices to see which needs service.

If you use 2 interrupt vectors, they can certainly call or jump (if you're using assembly) to the same routine to perform the bulk of the work as in the answer given by Earlz.

Note that the chip has an an interrupt vector table already, so to do what you're talking about in the comment you made in another answer, you just have to point the interrupt vector entries for the 'unused' interrupts to the routine that throws an error.

Michael Burr
+3  A: 

The general answer to your question is no there is no direct method to detect which interrupt is currently being called. However each interrupt has its own interrupt flag so you can check each flag in the interrupt. You should and the flag with the enable to make sure you are handling the interrupt that actually was called. Also with the timers on the MSP430 there is vector TAIV which can tell you what to handle in the A1 handler. Case 0 of the TAIV is that there was no interrupt for A1 handler so for that case you can assume it is the A0 handler.

I would do something like the following.

#pragma vector=TIMERA0_VECTOR
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A (void)
{
   switch (TAIV)         // Efficient switch-implementation
   {
     case  TAIV_NONE:          // TACCR0             TIMERA0_VECTOR
        break;
     case  TAIV_TACCR1:        // TACCR1             TIMERA1_VECTOR
        break;
     case  TAIV_TACCR2:        // TACCR2             TIMERA1_VECTOR
        break;
     case TBIV_TBIFG:          // Timer_A3 overflow  TIMERA1_VECTOR
        break;
     default;
        break;
   }
   ServiceWatchdogTimer();
}
Rex Logan
You should replave your numbers in the switch with TAIV_NONE,TAIV_TACCR1,TAIV_TACCR2,TBIV_TBIFG.
eaanon01