Writing Processor Expert components is not always completely independent of the compiler and underlying microcontroller. In many cases I need to know the compiler for which the source code is generated. Or I need to know on which CPU architecture the code shall run. For this I need to know the compiler and the CPU family.
CPU Family
To know the architecture, the %CPUfamily variable can be checked in the component code. The following values I’m aware of:
- “Kinetis”: Freescale Cortex-M family.
- “ColdFireV1”: ColdFire V1 family.
- “MCF”: ColdFire V2-4 family.
- “HCS08” and “HC08”: HC(S)08 family of microcontrollers.
- “RS08”: RS08 family of microcontrollers.
- “HCS12”, “HC12” and “HCS12X” : HC(S)12(X) family of microcontrollers.
- “56800”: Hawk/DSC controller family.
Following example illustrates the usage (taken from the FreeRTOS component):
%if (CPUfamily = "ColdFireV1") | (CPUfamily = "MCF") unsigned portLONG uxCriticalNesting = 0x9999UL; %elif (CPUfamily = "HCS08") | (CPUfamily = "HC08") | (CPUfamily = "HCS12") | (CPUfamily = "HCS12X") | (CPUfamily = "56800") volatile unsigned portBASE_TYPE uxCriticalNesting; %elif (CPUfamily = "Kinetis") /* Each task maintains its own interrupt status in the critical nesting variable. */ static unsigned portBASE_TYPE uxCriticalNesting = 0xaaaaaaaa; %else #error "undefined target %CPUfamily!" %endif
A good trick is as well to have that #error statement as shown above: that way I will know the CPUfamily if I have missed it.
Compiler
The other important thing to know is the compiler. The compiler is a property of the CPU component:
To check on the compiler the macro %Compiler can be used. Following values are known to me:
- “MetrowerksHC08CC” and “MetrowerksHCS08CC”: HIWARE/Metrowerks/Freescale HC(S)08 compiler.
- “CodeWarriorRS08”: Freescale RS08 compiler.
- “MetrowerksHC12CC” and “MetrowerksHC12XCC”: HIWARE/Metrowerks/Freescale HC(S)12(X) compiler.
- “GNUC”: GNU gcc compiler, I use it in combination with %CPUfamily.
- “CodeWarriorColdFireV1”: Metrowerks/Freescale ColdFire V1 compiler.
- “CodeWarriorMCF”: Metrowerks ColdFire V2-V4 compiler.
- “CodeWarriorARM”: Freescale ARM/Kinetis compiler.
- “MetrowerksDSP”: Metrowerks/Freescale DSC/Hawk compiler.
Below is a piece of code showing the usage of it:
%- ********************************************************************** %- Macros for compiler support %- ********************************************************************** %if (%Compiler = "CodeWarriorColdFireV1") | (%Compiler = "CodeWarriorMCF") | (%Compiler = "CodeWarriorARM") | (%Compiler = "MetrowerksDSP") %define COMPILER_MW %elif %Compiler = "CodeWarriorRS08CC" %elif %Compiler = "MetrowerksHC08CC" %elif %Compiler = "MetrowerksHCS08CC" %elif %Compiler = "MetrowerksHC12CC" %elif %Compiler = "MetrowerksHC12XCC" %elif %Compiler = "GNUC" %else %warning "Unknown compiler %Compiler" %endif
Happy Compiling 🙂