11.07.2015 Views

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

MSP430 IAR C/C++ Compiler reference guide - Rice University

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

FunctionsThis creates an interrupt service routine where you must make sure that the code withinthe routine does not affect any of the registers used by the interrupted environment.Typically, this is useful for applications that have an empty foreground loop and useinterrupt routines to perform all work.Note: The same effect can be achieved for normal functions by using the __taskkeyword.Interrupt Vector Generator interrupt functionsThe <strong>MSP430</strong> <strong>IAR</strong> C/<strong>C++</strong> <strong>Compiler</strong> provides a way to write very efficient interruptservice routines for the modules that has Interrupt Vector Generators, this includesTimer A (TAIV), Timer B (TBIV), the I 2 C module (I2CIV), and the ADC12 module.The interrupt vector register contains information about the interrupt source, and theinterrupt service routine normally uses a switch statement to find out which interruptsource issued the interrupt. To help the compiler generate optimal code for the switchstatement, the intrinsic function __even_in_range can be used. The followingexample defines a Timer A interrupt routine:#pragma vector=TIMERA1_VECTOR__interrupt void Timer_A1_ISR(void){switch (__even_in_range(TAIV, 10)){case 2: P1POUT ˆ= 0x04;break;case 4: P1POUT ˆ= 0x02;break;case 10: P1POUT ˆ= 0x01;break;}}The intrinsic function __even_in_range requires two parameters, the interrupt vectorregister and the last value in the allowed range, which in this example is 10. The effectof the intrinsic function is that the generated code can only handle even values withinthe given range, which is exactly what is required in this case as the interrupt vectorregister for Timer A can only be 0, 2, 4, 6, 8, or 10. If the __even_in_range intrinsicfunction is used in a case where an odd value or a value outside the given range couldoccur, the program will fail.For more information about the intrinsic keyword, see __even_in_range, page 221.Part 1. Using the compiler25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!