Skip to content

Commit 2fdbf12

Browse files
Floessiefeilipu
authored andcommitted
Fix too small return type for uxTaskGetStackHighWaterMark() (#29)
* Fix too small return type for `uxTaskGetStackHighWaterMark()` * Use `configSTACK_DEPTH_TYPE` for `uxTaskGetStackHighWaterMark()` * Streamline other places with `configSTACK_DEPTH_TYPE` (by @feilipu)
1 parent eeb08c1 commit 2fdbf12

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/FreeRTOSConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
/* Set the stack pointer type to be uint16_t, otherwise it defaults to unsigned long */
8181
#define portPOINTER_SIZE_TYPE uint16_t
8282

83+
/* Set the stack depth type to be uint16_t. */
84+
#define configSTACK_DEPTH_TYPE uint16_t
85+
8386
/* Set the following definitions to 1 to include the API function, or zero
8487
to exclude the API function. */
8588

src/task.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ typedef struct xTASK_PARAMETERS
114114
{
115115
TaskFunction_t pvTaskCode;
116116
const char * const pcName; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
117-
uint16_t usStackDepth;
117+
configSTACK_DEPTH_TYPE usStackDepth;
118118
void *pvParameters;
119119
UBaseType_t uxPriority;
120120
StackType_t *puxStackBuffer;
@@ -1420,7 +1420,7 @@ TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*
14201420
* actual spaces on the stack rather than bytes) since the task referenced by
14211421
* xTask was created.
14221422
*/
1423-
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1423+
configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
14241424

14251425
/* When using trace macros it is sometimes necessary to include task.h before
14261426
FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,

src/tasks.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
658658

659659
prvInitialiseNewTask( pxTaskDefinition->pvTaskCode,
660660
pxTaskDefinition->pcName,
661-
( uint32_t ) pxTaskDefinition->usStackDepth,
661+
pxTaskDefinition->usStackDepth,
662662
pxTaskDefinition->pvParameters,
663663
pxTaskDefinition->uxPriority,
664664
pxCreatedTask, pxNewTCB,
@@ -706,7 +706,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
706706

707707
prvInitialiseNewTask( pxTaskDefinition->pvTaskCode,
708708
pxTaskDefinition->pcName,
709-
( uint32_t ) pxTaskDefinition->usStackDepth,
709+
pxTaskDefinition->usStackDepth,
710710
pxTaskDefinition->pvParameters,
711711
pxTaskDefinition->uxPriority,
712712
pxCreatedTask, pxNewTCB,
@@ -3622,7 +3622,7 @@ static void prvCheckTasksWaitingTermination( void )
36223622

36233623
#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )
36243624

3625-
static uint16_t prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )
3625+
static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )
36263626
{
36273627
uint32_t ulCount = 0U;
36283628

@@ -3634,19 +3634,19 @@ static void prvCheckTasksWaitingTermination( void )
36343634

36353635
ulCount /= ( uint32_t ) sizeof( StackType_t ); /*lint !e961 Casting is not redundant on smaller architectures. */
36363636

3637-
return ( uint16_t ) ulCount;
3637+
return ( configSTACK_DEPTH_TYPE ) ulCount;
36383638
}
36393639

36403640
#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */
36413641
/*-----------------------------------------------------------*/
36423642

36433643
#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )
36443644

3645-
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
3645+
configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark( TaskHandle_t xTask )
36463646
{
36473647
TCB_t *pxTCB;
36483648
uint8_t *pucEndOfStack;
3649-
UBaseType_t uxReturn;
3649+
configSTACK_DEPTH_TYPE uxReturn;
36503650

36513651
pxTCB = prvGetTCBFromHandle( xTask );
36523652

@@ -3660,7 +3660,7 @@ static void prvCheckTasksWaitingTermination( void )
36603660
}
36613661
#endif
36623662

3663-
uxReturn = ( UBaseType_t ) prvTaskCheckFreeStackSpace( pucEndOfStack );
3663+
uxReturn = prvTaskCheckFreeStackSpace( pucEndOfStack );
36643664

36653665
return uxReturn;
36663666
}

0 commit comments

Comments
 (0)