![]() |
![]() |
![]() |
![]() |
![]() |
Adaptation to Compilers
In this section the steps are explained that must be carried out in order to deal with a new C compiler which is not yet in the list of available compilers.
The following parts may be modified manually:
- In mk_stim.c, there are template functions as templates which have to be modified to adapt another hardware/compiler to the SDL system time (Now).
- In mk_cpu.c, there are templates for functions which represent hardware access. Those are required if the preemptive Cmicro Kernel is used.
The following parts can be added by using the Targeting Expert:
- A compiler specific header file user_cc.h which will automatically be included in ml_typ.h. Please view Compiler Definition for Compilation.
- An entry in the Targeting Expert's configuration files. Please view Compiler Definition for Compilation.
List of Available C Compilers in ml_typ.h
C compilers are to be selected by the user by choosing from an available list with the help of the Targeting Expert.
The Targeting Expert will generate a C define into the ml_mcf.h file. When compiling Cmicro sources, the right C compiler section in ml_typ.h is selected by using a #ifdef <compilername> construct.
The following <compilername> defines are currently defined in ml_typ.h:
If none of these compiler flags is defined during compilation the file user_cc.h (generated by the Targeting Expert) will be included in ml_typ.h.
The remaining part of the code of the Cmicro Library should be compilable without performing any modifications. If there are problems with adapting a new compiler or hardware please contact Cmicro technical support.
The user may however decide to define his own C compiler. This is explained in the following subsection.
Introducing a new C Compiler
Adding a new C Compiler to the Project
The first alternative to add a new user defined C compiler, is to add that compiler to a user's project. This can be achieved with the Targeting Expert.
- Give the C compiler a name for using it within Cmicro. The name should as a recommendation be in the notation of C macros, that is, it should be 8 to approximately 16 characters long in uppercase letters.
- Below the Targeting Expert's Edit menu there is a choice called "Add a new C Compiler" by which the new C compiler can be defined.
- It is also possible to remove the user defined C compiler later on by using this menu.
These changes are not stored within the installation, but within the user's project directory (which is the target directory that was chosen when the Targeting Expert was started).
Do the C Compiler Adaptations
- Create a new file with the name user_cc.h. If a C compiler is selected, which is not in the list of available C compilers in the Cmicro product, the user_cc.h is included automatically. This can easily be done by using the Targeting Expert's Edit menu "Edit compiler section".
- Take care that the right path names are specified when the C compiler is invoked. There usually should be something like a "-I." option which must point to the path in which user_cc.h is stored.
Description of user_cc.h
The things that are to be defined by the user are:
#undef XNOPROTO #define XPP(x) x #define PROTO(x) x #define XNOPROTO #define XPP(x) #define PROTO(x)
#define xmk_OPT_INT char #define xmk_OPT_INT integer
#undef X_REGISTER #define X_REGISTER >register< /* Nothing to do for X_REGISTER */
- >register< is the compiler specific command to store variables in registers.
- Default setting:
#define xptrint unsigned long
This setting should work for the very most compilers In a few cases it is necessary to define xptrint as unsigned int.- Default setting:
#define xint32 long
This setting should work for the very most compilers. In a few cases it is necessary to define xint32 as int.- Is the compiler able to handle the C keyword const in the correct way?
#define XCONST const #undef XCONST
- In general, the compilers which are able to produce ROM-able code, can handle the keyword const. Compilers may generate false object code, if using const.
- Critical paths must be enabled and disabled:
#undef XMK_END_CRITICAL_PATH
#define XMK_END_CRITICAL_PATH \
if (xmk_InterruptsDisabled) \
{\
xmk_InterruptsDisabled--;\
if (!xmk_InterruptsDisabled) \
{ ENABLE; }}
#undef XMK_BEGIN_CRITICAL_PATH
#define XMK_BEGIN_CRITICAL_PATH \
DISABLE;\
xmk_InterruptsDisabled++;- A #include of <stdio.h>, if supported by the compiler (not all the target compilers do). Write:
#ifdef XMK_ADD_STDIO#include <stdio.h>#endif- Which include header files must be added?
- The include header files containing the prototypes for dynamic memory allocation and string and memory functions must be added. This subsection should look like this for allowing the user to select either the memory functions from the C compiler or from Cmicro:
#ifdef XMK_USE_SDL_MEM
#include "ml_mem.h"
#else
#include "string.h"
#endif /* XMK_USE_SDL_MEM */
- It must be checked if malloc(), free(), calloc() etc. are really prototyped in string.h, on other compilers it might be stdlib.h. Cmicro always calls xAlloc() and xFree() which are given as examples in the mk_cpu.c file below the template directory. For more information on dynamic memory allocation please view the subsection Dynamic Memory Allocation.
Defining the SDL System Time Functions in mk_stim.c
The following functions exist in the module mk_stim.c:
- void xmk_InitSystime(void)
Initialize the hardware registers to support the system time- void xmk_DeinitSystime(void)
Give up to use the system time. This normally cannot happen, but in some applications, where the SDL system is stopped and restarted again during run-time, it may prove useful.- void xmk_SetTime(xmk_T_TIME)
This function sets the system-time to the given value. Called by Cmicro Kernel in the case when an overrun in the time value is detected.- xmk_T_TIME xmk_NOW(void)
This is the most important C function to handle SDL system-time. This function returns the absolute time, which is by default defined as a long value (xmk_T_TIME).Usually, the above functions are conditionally compiled. To make the functions available in the target system, at least one timer in SDL must be declared. The functions are not included if there is no timer declared but duration, time or now is used in SDL. This will lead to compilation errors.
To make timers in SDL operable, absolute time must be implemented. This can be reached by using a hardware free running counter or by using a timer interrupt service routine, which clocks a global variable containing the absolute time.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |