Stack overflows are the most common source of problems in FreeRTOS.org application. I have therefore added two new features to the SVN head of tasks.c:
1) New function uxTaskGetStackHighWaterMark() as described below.
* <PRE>unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( void );</PRE>
* INCLUDE_uxTaskGetStackHighWaterMark must be set to 1 in FreeRTOSConfig.h for
* this function to be available.
* Returns the high water mark for the stack of the calling task. That is,
* the minimum free stack space there has been (in bytes) since the task
* started. The small the returned number the closer the task has come
* to overflowing its stack.
unsigned portBASE_TYPE uxTaskGetStackHighWaterMark( void );
2) Stack overflow hook, as described below:
* Call the stack overflow hook function if the stack of the task being swapped
* out is currently overflowed, or looks like it might have overflowed in the
* Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
* the current stack state only - comparing the current top of stack value to
* the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
* will also cause the last few stack bytes to be checked to ensure the value
* to which the bytes were set when the task was created have not been
* overwritten. Note this second test does not guarantee that an overflowed
* stack will always be recognised.
If configCHECK_FOR_STACK_OVERFLOW is set to greater than 0 then the application must provide a function with the prototype:
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName );
In addition, the tasks.c and queue.c code have been laced with trace macros that permit user defined trace functionality to be implemented. More on this later.