Hi John
Here is a guide to using malloc/free in the CW project. I haven't had problems with the typdef for
size_t, either set to be
unsigned int or
unsigned long, however if your project does have a problem then either adapt it in
types.h accordingly or else remove it from there and let it be defined for the whole project by stdlib.h.
The following 2 threads may have also something related:
http://www.utasker.com/forum/index.php?topic=44.msg180#msg180http://www.utasker.com/forum/index.php?topic=30.msg121#msg121Using malloc/free in the CW projectThe size of the CodeWarrior malloc() heap can be defined by HEAP_SIZE in the linker script file (eg. M52235EVB_FLASH.lcf). This defines a fixed block of memory by the heap management software, the end of which is supplied by the linker as a variable
extern unsigned char __HEAP_END.
If malloc () and other heap management routines in the CodeWarrior library are not used HEAP_SIZE can be set to 0.
The uTasker uMalloc uses the location of this variable #define HEAP_START_ADDRESS &__HEAP_END to define the start of its own, variable length heap. The uMalloc heap size is defined in TaskConfig.h:
const HEAP_NEEDS ctOurHeap[] = {
{DEFAULT_NODE_NUMBER,
OUR_HEAP_SIZE}, // our node requires this amount of heap space
{0} // end
};
In this example the size is fixed at OUR_HEAP_SIZE but in a multi-node or multiple configuration system each node can have its own individual heap size.
Thus the memory has the following construction for the M5223X with 32k internal SRAM.
To ensure that the CW project operates correctly when using malloc/free from the library observe the following points:
- Add the library C_4i_CF_SZ_MSL.a (deliveres the malloc, free etc.) to the project. (This is suitable for the delivered uTasker project set up).
Note that the Codewarrior project configuration was modified in SP6 to use register passing, which produces smaller and faster code. When using this configuration the library C_4i_CF_RegABI_SZ_MSL.a should be used since it is built to be compatible with this option.- Make sure that you include <stdlib.h> so that malloc is known (due to the next setting it is imperative that all prototypes are correct).
- In the file
\Applications\uTaskerV1.3\CodeWarrior_M5223X\uTaskerV1.3\include\mwerks.hensure that the following pragma is set:
#pragma pointers_in_A0If instead
#pragma pointers_in_D0 is defined, change it to the above. This will ensure that the project is compatible with the library as delivered with CW.
Now malloc/free should work correctly and the complete project will use A0 register passing for return pointers, rather than D0 (calling functions must always know whether a pointer or a normal data value is being returned - if the prototype is not exact it can result in a serous error! The project is however set up to demand prototypes and will not build if something is not known.)
Regards
Mark