Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

What does the "__even_in_range" function do?

It's in a part of a code example: msp430fr69xx_ta0_04.c. Besides this functions, I would like to understand this switch condition. 

// Timer0_A1 Interrupt Vector (TAIV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TIMER0_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) TIMER0_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(TA0IV, TA0IV_TAIFG))
{
case TA0IV_NONE: break; // No interrupt
case TA0IV_TACCR1: break; // CCR1 not used
case TA0IV_TACCR2: break; // CCR2 not used
case TA0IV_3: break; // reserved
case TA0IV_4: break; // reserved
case TA0IV_5: break; // reserved
case TA0IV_6: break; // reserved
case TA0IV_TAIFG: // overflow
P1OUT ^= BIT0;
break;
default: break;
}
}

  • See SLAU367L section 24.3.15.4. The assembly equivalent is in section 19.2.6.2.1.

    I think it's also described in more detail in the CCS C compiler manual.
  • Further to Bruce's anwer, the family user's guide covers the general structure of the switch statement, but doesn't explain __even_in_range.

    The MSP430 Optimizing C/C++ Compiler User's Guide has a description of __even_in_range, but it's pretty terse (see section 5.11.27)

    __even_in_range is a compiler intrinsic function; intrinsics trigger special case behaviours in the compiler. In this case, the function just indicates to the compiler that the first parameter is an even number between zero and the second parameter (inclusive).

    switch(__even_in_range(TA0IV, TA0IV_TAIFG))

    is equivalent to:

    switch(TA0IV)

    but using __even_in_range allows the compiler to generate more efficient code to handle the switch statement.

**Attention** This is a public forum