|
Logical Area Sizes |
Top Previous Next |
|
The configurer must know the sizes of the logical areas of all the tasks on a processor. This is easy for code and static storage, as the linker stores the information in the task image files, but you must explicitly supply sizes of the stack and heap areas.
Working out the stack and heap requirements of a task can be quite difficult. Unfortunately, the compiler cannot do it, as stack and heap use depend upon the program's requirements at run time. Worse, the TI compiler does not provide a mechanism to include automatic stack checks during the development of C code.
For the size of the stack, you must work out how much space is needed for all the functions that may be active at once, based on the sizes of the auto variables they use. Each level of function calling uses a minimum of about three words of stack space in addition to the space required for function data. Also, library functions use varying amounts of stack space as working storage.
Similarly, for the heap, you must estimate the maximum needed at any one time. Heap storage is currently allocated by the run-time library in blocks of 4K octets (eight-bit bytes), so if your task uses the heap, be sure to allocate at least that much space for it. In addition to the amount of space you estimate your task actually needs, you must allocate an extra 200 octets (330 octets for processors from the C64 family) on the stack. The kernel uses this to manage the task. The absolute minimum amount of space you need to execute the simplest of tasks or threads safely is given by the C macro THREAD_MIN_STACK.
Once you have decided the sizes of the stack and heap areas, you can chose between two ways of specifying them to the configurer. These can be used by themselves or, if you wish, in conjunction with the OPT attribute discussed above. |