Just started using freeRTOS yesterday and am so far VERY impressed :-). There is one item (so far) which I am having difficulty getting my head around however, and thats the stack usage vs free.
I have a VERY simple background task which just flashes an LED then waits using vTaskDelay. I added some diagnostic code to view the TCB - to try to understand the stack requirement/usage (as it crashed with the default minimal stack setting).
The first time I call my debug code - uxTaskGetStackHighWaterMark returns 266 (decimal) - my stack size is fixed at 300. The second and subsequent times I call, it tells me 107. The code is in a simple loop.
I could understand that the high watermark could be this after a task switch, so how do I get the ‘free’ figure ??.
The first entry in the TCB (apparently the current SP ??) is :
0x0dfe at the first call
0x0d02 on subsequent calls
According to (my understanding of) the TCB - the first TCB entry is supposed to be the current Top Of Stack :
volatile portSTACK_TYPE *pxTopOfStack; /*< Points to the location of the last item placed on the tasks stack. THIS MUST BE THE FIRST MEMBER OF THE STRUCT. */
Also - the ‘other’ TCB entries don’t seem to add up (to me anyway) :
*pxStack = 0x0c8e
*pxEndOfStack = 0x0ee4
Should these two figures be 300 decimal words ? apart - as they are ± 2.
The Pic stack is supposed to grow upwards - so would this be from 0c8e -> 0d02.
Sorry but I am well confused here now - as the numbers reported don’t seem to add up.
NB I am not new to RTOS’s in general and have been working with embedded multi-taskers written in Forth for almost 30 years :-O.
Any advice gratefully accepted :-O.