Skip to content

Instantly share code, notes, and snippets.

@perimeno
Forked from Lauszus/task.h
Last active May 30, 2021 21:58
Show Gist options
  • Save perimeno/2e257bf4001569b6a35b8ba84aa64618 to your computer and use it in GitHub Desktop.
Save perimeno/2e257bf4001569b6a35b8ba84aa64618 to your computer and use it in GitHub Desktop.
FreeRTOS get stack size
/**
* task.h
* <PRE>UBaseType_t uxTaskGetStackSize( TaskHandle_t xTask );</PRE>
*
* INCLUDE_pxTaskGetStackSize must be set to 1 in FreeRTOSConfig.h for
* this function to be available.
*
* Returns the stack size associated with xTask in bytes.
*
* @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;
#if ( INCLUDE_pxTaskGetStackSize == 1 )
UBaseType_t uxTaskGetStackSize( TaskHandle_t xTask )
{
TCB_t *pxTCB;
UBaseType_t uxReturn;
pxTCB = prvGetTCBFromHandle( xTask );
#if( portSTACK_GROWTH < 0 )
{
uxReturn = pxTCB->pxEndOfStack - pxTCB->pxStack + sizeof(UBaseType_t);
}
#else /* portSTACK_GROWTH */
{
uxReturn = pxTCB->pxStack - pxTCB->pxEndOfStack + sizeof(UBaseType_t);
}
#endif /* portSTACK_GROWTH */
uxReturn/=sizeof(StackType_t);
return uxReturn;
}
#endif /* INCLUDE_pxTaskGetStackSize */
/*-----------------------------------------------------------*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment