Last active
November 30, 2023 11:32
-
-
Save Lauszus/3251ef567475e5b59e1f8b61f6cd5edf to your computer and use it in GitHub Desktop.
FreeRTOS get stack size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* task.h | |
* <PRE>UBaseType_t uxTaskGetStackSize( TaskHandle_t xTask );</PRE> | |
* | |
* Returns the stack size associated with xTask. That is, the stack | |
* size (in words, so on a 32 bit machine a value of 1 means 4 bytes) of the task. | |
* | |
* @param xTask Handle of the task associated with the stack to be checked. | |
* Set xTask to NULL to check the stack of the calling task. | |
* | |
* @return The stack size (in words) associated with xTask. | |
*/ | |
UBaseType_t uxTaskGetStackSize( TaskHandle_t xTask ) PRIVILEGED_FUNCTION; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UBaseType_t uxTaskGetStackSize( TaskHandle_t xTask ) | |
{ | |
TCB_t *pxTCB; | |
UBaseType_t uxReturn; | |
pxTCB = prvGetTCBFromHandle( xTask ); | |
#if( portSTACK_GROWTH < 0 ) | |
{ | |
uxReturn = pxTCB->pxEndOfStack - pxTCB->pxStack + 1UL; | |
} | |
#else /* portSTACK_GROWTH */ | |
{ | |
uxReturn = pxTCB->pxStack - pxTCB->pxEndOfStack + 1UL; | |
} | |
#endif /* portSTACK_GROWTH */ | |
return uxReturn; | |
} |
Thanks guys! I've now fixed it :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pxEndOfStack and pxStack are both
StackType_t*
notStackType_t
. Subtracting them will give you the distance apart of the two pointers in units of StackType_t which may be bigger than what can be contained in StackType_t. Compare to uxTaskGetStackHighWaterMark that returns UBaseType_t.