This information has been added to file "InterMSP430CompilerPortability.h". To assist with code portability between compilers and assemblers use can be made of predefined macro names. For example 1. Suppose you use Code Composer Essentials and IAR V3 tool sets 2. Suppose you have both C and assembler 3. Suppose it is important to know if an include file is being used for assembler or C as well as knowing which tool set is being used Then the following code, say in file "target.h" takes advantage of predefined macros from the tool sets. The TOOLSET macro name is a reference to C code for setting macros for interrupt use and optimised switch statements in file "InterMSP430CompilerPortability.h". //say this file is in target.h #ifdef __TI_COMPILER_VERSION__ //Code Composer Essentials compiler and assembler #define TOOLSET TOOLSET_TICCE #ifdef __ASM_HEADER__ #define CCEA //Code Composer Essentials assembler #else #define CCEC //Code Composer Essentials compiler #endif #else #ifdef __IAR_SYSTEMS_ICC__ #define TOOLSET TOOLSET_IAR #define IARC //IAR C Compiler #else #ifdef __IAR_SYSTEMS_ASM__ //defining a TOOLSET here is pointless. #define IARA //IAR Assembler #else #error "Unrecognised MSP430 compiler or assembler" #endif #endif #endif While IAR has similar preprocessing language constructs between C and assembler, Code Composer Essentials provides a facility to convert a wider range of useful information from C using the .cdecls directive. However the .cdecls directive cannot be used on pure assembly. There is also another problem. Code Composer Essentials assembler will only define __ASM_HEADER__ for sections belonging to a .cdecls directive. For pure assembly the preprocessor symbol .MSP430 is defined For example the following is pure assembly that will only assemble 'as is' with Code Composer Essentials. Code Composer Essentials uses a '.' instead of '#' to indicate a preprocessor directive. .if .MSP430 .sect ".some_section" .else RSEG SOME_SECTION .endif To make this assembler file assemble correctly under IAR it needs to be run through an external program that will convert .if to #if, .else to #else, .endif to #endif and will convert .MSP430 to a valid but undefined symbol name under IAR assembler, such as _MSP430. Since _MSP430 should not be defined under IAR, the IAR assembler will make the correct choice. It is very simple to do this. For example all of the above can be accomplished with the following single command that can be placed in a command file. sed -e 's/\.MSP430/_MSP430/' -e 's/\.if/#if/' -e 's/\.else/#else/' join with line above: -e 's/\.endif/#endif/' file.asm > file.s43 sed is standard program in Unix and Linux distributions. There are versions of sed compiled for Windows for example http://gnuwin32.sourceforge.net/packages/sed.htm I have also made it easier to manage the addition of new interrupts through use of the preprocessor macro argument concatenation operator ##. While it might seem an obvious approach to make, it is not as successful as might be hoped: two lines are necessary for each interrupt name in "InterMSP430CompilerPortability.h". It is not possible to use #pragma in a macro and under IAR the preprocessor operator _Pragma must have its sole argument quoted and stubbornly refuses to work with substitutions that are quotes (for example #define QP(A) _Pragma(#A) does not work) Tests with a debugger have been conducted for both Code Composer Essentials and IRA V3. Tests have not been conducted for GCC and Crossworks. John Heenan
Using predefined macros names to assist with inter compiler. Upadate to file.
Started by ●October 19, 2005
Reply by ●October 20, 20052005-10-20
Hi John! > I have also made it easier to manage the addition of > new interrupts through use of the preprocessor macro > argument concatenation operator ##. While it might seem > an obvious approach to make, it is not as successful > as might be hoped: two lines are necessary for each > interrupt name in "InterMSP430CompilerPortability.h". > It is not possible to use #pragma in a macro and under > IAR the preprocessor operator _Pragma must have its > sole argument quoted and stubbornly refuses to > work with substitutions that are quotes > (for example #define QP(A) _Pragma(#A) does not work) It sure does; and for good reasons too -- that is the way the it should work, according to the standard. However, I think that I have a solution that work, but I had to dig quite deep into my bag of preprocessor tricks to manage it: #define STRANGE_VECTOR 100 // Just for the example // Concatenate two identifiers #define CONCAT0(x,y) x##y #define CONCAT(x,y) CONCAT0(x,y) // PRAGMA, unlike _Pragma it don't want its arguments quoted. #define PRAGMA(x) _Pragma(#x) // PV - pragma vector. #define PV0(x) PRAGMA(vector=x) #define PV(x) PV0(CONCAT(x,_VECTOR)) PV(STRANGE) __interrupt void foo(void) { } John, keep up the good work maintaining the MSP430 interop file! -- Anders Lindgren, IAR Systems -- Disclaimer: Opinions expressed in this posting are strictly my own and not necessarily those of my employer.