Pragma intrinsic and more C Language Extensions: This section gives a brief overview of the C language extensions available in the MSP430 IAR C/C++ Compiler. The compiler provides a wide set of extensions, so to help you to find the extensions required by your application, the extensions have been grouped according to their expected usefulness. In short, this means: Important language extensions extensions specifically tailored for efficient embedded programming, typically to meet memory restrictions Useful language extensions features considered useful and typically taken from related standards, such as C99 and C++ Minor language extensions, that is, the relaxation of some minor standards issues and also some useful but minor syntax extensions. What is #PRAGMA? The #pragma directive is defined by the ISO/ANSI C standard and is a mechanism for using vendor-specific extensions in a controlled way to make sure that the source code is still portable. The pragma directives control the behavior of the compiler, for example how it allocates memory for variables and functions, whether it allows extended keywords, and whether it outputs warning messages. The pragma directives are always enabled in the compiler.
Placement at an absolute address or in a named segment The @ operator or the directive #pragma location can be used for placing global and static variables at absolute addresses, or placing a variable or function in a named segment. Alignment Each data type has its own alignment. If you want to change alignment, the #pragma pack and #pragma data_alignment are available Dedicated segment operators segment_begin and segment_end The syntax for these operators are: void * segment_begin(segment) void * segment_end(segment) These operators return the address of the first byte of the named segment and the first byte after the named segment, respectively. This can be useful if you have used the @ operator or the #pragma location directive to place a data object or a function in a user-defined segment. The named segment must be a string literal that has been declared earlier with the #pragma segment directive. Example: #pragma segment="myseg"... segment_start_address = segment_begin("myseg");
PACK The #pragma pack directive is used for changing the alignment requirements of the members of a structure. This will change the way the layout of the structure is performed. The members will be placed in the same order as when declared, but there might be less pad space between members.
segment Syntax #pragma segment="segment_name" [align] Parameters "SEGMENT_NAME" align The name of the segment Aligns the segment part. The value must be a constant integer expression to the power of two. Use this pragma directive to declare a segment name that can be used by the segment operators segment_begin and segment_end. Example #pragma segment="myseg" 4 vector Syntax #pragma vector=vector1[, vector2, vector3,...] Parameters vector The vector number(s) of an interrupt or trap function. Use this pragma directive to specify the vector(s) of an interrupt or trap function whose declaration follows the pragma directive. Example #pragma vector=0x14 interrupt void my_handler(void); location Syntax #pragma location={address SEGMENT_NAME} Parameters address The absolute address of the global or static variable for which you want an absolute location. SEGMENT_NAME A user-defined segment name; cannot be a segment name predefined for use by the compiler and linker. Use this pragma directive to specify the location the absolute address of the global or static variable whose declaration follows the pragma directive Example #pragma location="foo" char PORT1; /* PORT1 is located in segment foo */
optimize Syntax #pragma optimize=param[, param,...] Parameters s z 2 none 3 low 6 medium 9 high Optimizes for speed Optimizes for size Specifies the level of optimization
USEFUL LANGUAGE EXTENSIONS Inline functions The #pragma inline directive, alternatively the inline keyword, advises the compiler that the function whose declaration follows immediately after the directive should be inlined. inline Syntax #pragma inline[=forced] Parameters Use this pragma directive to advise the compiler that the function whose declaration follows immediately after the directive should be inlined that is, expanded into the body of the calling function. Whether the inlining actually takes place is subject to the compiler s heuristics. Specifying #pragma inline=forced disables the compiler s heuristics and forces inlining.
Intrinsic functions The intrinsic functions provide direct access to low-level processor operations and can be very useful in, for example, time-critical routines. The intrinsic functions compile into inline code, either as a single instruction or as a short sequence of instructions.
bis_sr_register Syntax void bis_sr_register(unsigned short); Sets bits in the status register. The function takes an integer literal as its argument, that is, a bit mask with the bits to be set. enable_interrupt Syntax void enable_interrupt(void); Enables interrupts by inserting the EINT instruction. get_sp_register Syntax unsigned short get_sp_register(void); Returns the value of the stack pointer register SP. no_operation Syntax void no_operation(void); Inserts a NOP instruction.
Inline assembler The syntax is: asm ("string"); The string can be a valid assembler instruction or a data definition assembler directive, but not a comment. You can write several consecutive inline assembler instructions, for example: asm ("Label: nop\n" " jmp Label"); where \n (new line) separates each new assembler instruction