Question

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?

Was it helpful?

Solution

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();
}

OTHER TIPS

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();
}

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top