Skip to content

Commit c6de000

Browse files
committed
Added uxTaskGetStackHighWaterMark2(), which is the same as uxTaskGetStackHighWaterMark() other than the return type.
Allows the task name parameter passed into xTaskCreate() to be NULL.
1 parent e3dc5e9 commit c6de000

File tree

14 files changed

+140
-27
lines changed

14 files changed

+140
-27
lines changed

FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/FreeRTOSConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ to exclude the API function. */
114114
#define INCLUDE_xTaskGetSchedulerState 1
115115
#define INCLUDE_xTaskGetIdleTaskHandle 1
116116
#define INCLUDE_uxTaskGetStackHighWaterMark 1
117+
#define INCLUDE_uxTaskGetStackHighWaterMark2 1
117118

118119
/* Cortex-M specific definitions. */
119120
#ifdef __NVIC_PRIO_BITS

FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/Keil_Specific/RTOSDemo.uvoptx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
<DebugFlag>
179179
<trace>0</trace>
180180
<periodic>1</periodic>
181-
<aLwin>1</aLwin>
181+
<aLwin>0</aLwin>
182182
<aCover>0</aCover>
183183
<aSer1>0</aSer1>
184184
<aSer2>0</aSer2>

FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ static void prvTaskToDelete( void *pvParameters )
766766

767767
/* For code coverage test purposes it is deleted by the Idle task. */
768768
configASSERT( uxTaskGetStackHighWaterMark( NULL ) > 0 );
769+
configASSERT( uxTaskGetStackHighWaterMark2( NULL ) > 0 );
769770
vTaskSuspend( NULL );
770771
}
771772
/*-----------------------------------------------------------*/
@@ -1057,7 +1058,7 @@ void vApplicationMallocFailedHook( void )
10571058
}
10581059
/*-----------------------------------------------------------*/
10591060

1060-
static void prvTimerCallback( TaskHandle_t xExpiredTimer )
1061+
static void prvTimerCallback( TimerHandle_t xExpiredTimer )
10611062
{
10621063
uint32_t ulCount;
10631064

FreeRTOS/Demo/Common/Minimal/StaticAllocation.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,9 @@ TaskHandle_t xCreatedTask;
729729

730730
/* The variable that will hold the TCB of tasks created by this function. See
731731
the comments above the declaration of the xCreatorTaskTCBBuffer variable for
732-
more information. */
732+
more information. NOTE: This is not static so relies on the tasks that use it
733+
being deleted before this function returns and deallocates its stack. That will
734+
only be the case if configUSE_PREEMPTION is set to 1. */
733735
StaticTask_t xTCBBuffer;
734736

735737
/* This buffer that will be used as the stack of tasks created by this function.

FreeRTOS/Demo/WIN32-MingW/FreeRTOSConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ functions anyway. */
104104
#define INCLUDE_vTaskDelayUntil 1
105105
#define INCLUDE_vTaskDelay 1
106106
#define INCLUDE_uxTaskGetStackHighWaterMark 1
107+
#define INCLUDE_uxTaskGetStackHighWaterMark2 1
107108
#define INCLUDE_xTaskGetSchedulerState 1
108109
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
109110
#define INCLUDE_xTaskGetIdleTaskHandle 1

FreeRTOS/Demo/WIN32-MingW/code_coverage_additions.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ const uint32_t ulRunTimeTollerance = ( uint32_t ) 0xfff;
381381
xReturn = pdFAIL;
382382
}
383383

384+
if( uxTaskGetStackHighWaterMark2( NULL ) != ( configSTACK_DEPTH_TYPE ) xStatus.usStackHighWaterMark )
385+
{
386+
xReturn = pdFAIL;
387+
}
388+
384389
/* Now obtain a task status without the high water mark but with the state,
385390
which in the case of the idle task should be Read. */
386391
xTimerTask = xTimerGetTimerDaemonTaskHandle();
@@ -408,6 +413,10 @@ const uint32_t ulRunTimeTollerance = ( uint32_t ) 0xfff;
408413
{
409414
xReturn = pdFAIL;
410415
}
416+
if( uxTaskGetStackHighWaterMark2( xTimerTask ) != ( configSTACK_DEPTH_TYPE ) xStatus.usStackHighWaterMark )
417+
{
418+
xReturn = pdFAIL;
419+
}
411420

412421
/* Attempting to abort a delay in the idle task should be guaranteed to
413422
fail as the idle task should never block. */

FreeRTOS/Demo/WIN32-MingW/main_full.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int main_full( void )
201201
vStartDynamicPriorityTasks();
202202
vStartQueueSetTasks();
203203
vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );
204-
xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
204+
xTaskCreate( prvDemoQueueSpaceFunctions, NULL, configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); /* Name is null for code coverage. */
205205
vStartEventGroupTasks();
206206
vStartInterruptSemaphoreTasks();
207207
vStartQueueSetPollingTask();

FreeRTOS/Source/include/FreeRTOS.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ extern "C" {
156156
#define INCLUDE_uxTaskGetStackHighWaterMark 0
157157
#endif
158158

159+
#ifndef INCLUDE_uxTaskGetStackHighWaterMark2
160+
#define INCLUDE_uxTaskGetStackHighWaterMark2 0
161+
#endif
162+
159163
#ifndef INCLUDE_eTaskGetState
160164
#define INCLUDE_eTaskGetState 0
161165
#endif

FreeRTOS/Source/include/mpu_prototypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ UBaseType_t MPU_uxTaskGetNumberOfTasks( void );
6161
char * MPU_pcTaskGetName( TaskHandle_t xTaskToQuery );
6262
TaskHandle_t MPU_xTaskGetHandle( const char *pcNameToQuery );
6363
UBaseType_t MPU_uxTaskGetStackHighWaterMark( TaskHandle_t xTask );
64+
configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );
6465
void MPU_vTaskSetApplicationTaskTag( TaskHandle_t xTask, TaskHookFunction_t pxHookFunction );
6566
TaskHookFunction_t MPU_xTaskGetApplicationTaskTag( TaskHandle_t xTask );
6667
void MPU_vTaskSetThreadLocalStoragePointer( TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue );

FreeRTOS/Source/include/mpu_wrappers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ only for ports that are using the MPU. */
6767
#define pcTaskGetName MPU_pcTaskGetName
6868
#define xTaskGetHandle MPU_xTaskGetHandle
6969
#define uxTaskGetStackHighWaterMark MPU_uxTaskGetStackHighWaterMark
70+
#define uxTaskGetStackHighWaterMark2 MPU_uxTaskGetStackHighWaterMark2
7071
#define vTaskSetApplicationTaskTag MPU_vTaskSetApplicationTaskTag
7172
#define xTaskGetApplicationTaskTag MPU_xTaskGetApplicationTaskTag
7273
#define vTaskSetThreadLocalStoragePointer MPU_vTaskSetThreadLocalStoragePointer

FreeRTOS/Source/include/task.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,12 @@ TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*
14131413
* a value of 1 means 4 bytes) since the task started. The smaller the returned
14141414
* number the closer the task has come to overflowing its stack.
14151415
*
1416+
* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1417+
* same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1418+
* user to determine the return type. It gets around the problem of the value
1419+
* overflowing on 8-bit types without breaking backward compatibility for
1420+
* applications that expect an 8-bit return type.
1421+
*
14161422
* @param xTask Handle of the task associated with the stack to be checked.
14171423
* Set xTask to NULL to check the stack of the calling task.
14181424
*
@@ -1422,6 +1428,33 @@ TaskHandle_t xTaskGetHandle( const char *pcNameToQuery ) PRIVILEGED_FUNCTION; /*
14221428
*/
14231429
UBaseType_t uxTaskGetStackHighWaterMark( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
14241430

1431+
/**
1432+
* task.h
1433+
* <PRE>configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask );</PRE>
1434+
*
1435+
* INCLUDE_uxTaskGetStackHighWaterMark2 must be set to 1 in FreeRTOSConfig.h for
1436+
* this function to be available.
1437+
*
1438+
* Returns the high water mark of the stack associated with xTask. That is,
1439+
* the minimum free stack space there has been (in words, so on a 32 bit machine
1440+
* a value of 1 means 4 bytes) since the task started. The smaller the returned
1441+
* number the closer the task has come to overflowing its stack.
1442+
*
1443+
* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
1444+
* same except for their return type. Using configSTACK_DEPTH_TYPE allows the
1445+
* user to determine the return type. It gets around the problem of the value
1446+
* overflowing on 8-bit types without breaking backward compatibility for
1447+
* applications that expect an 8-bit return type.
1448+
*
1449+
* @param xTask Handle of the task associated with the stack to be checked.
1450+
* Set xTask to NULL to check the stack of the calling task.
1451+
*
1452+
* @return The smallest amount of free stack space there has been (in words, so
1453+
* actual spaces on the stack rather than bytes) since the task referenced by
1454+
* xTask was created.
1455+
*/
1456+
configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
1457+
14251458
/* When using trace macros it is sometimes necessary to include task.h before
14261459
FreeRTOS.h. When this is done TaskHookFunction_t will not yet have been defined,
14271460
so the following two prototypes will cause a compilation error. This can be

FreeRTOS/Source/portable/Common/mpu_wrappers.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ BaseType_t xRunningPrivileged = xPortRaisePrivilege();
420420
#endif
421421
/*-----------------------------------------------------------*/
422422

423+
#if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
424+
configSTACK_DEPTH_TYPE MPU_uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )
425+
{
426+
configSTACK_DEPTH_TYPE uxReturn;
427+
BaseType_t xRunningPrivileged = xPortRaisePrivilege();
428+
429+
uxReturn = uxTaskGetStackHighWaterMark2( xTask );
430+
vPortResetPrivilege( xRunningPrivileged );
431+
return uxReturn;
432+
}
433+
#endif
434+
/*-----------------------------------------------------------*/
435+
423436
#if ( INCLUDE_xTaskGetCurrentTaskHandle == 1 )
424437
TaskHandle_t MPU_xTaskGetCurrentTaskHandle( void )
425438
{

FreeRTOS/Source/portable/ThirdParty/GCC/RISC-V/portasm.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
STORE x29, 28 * REGBYTES(sp)
132132
STORE x30, 29 * REGBYTES(sp)
133133
STORE x31, 30 * REGBYTES(sp)
134-
134+
135135
/* Store current stackpointer in task control block (TCB) */
136136
LOAD t0, pxCurrentTCB //pointer
137137
STORE sp, 0x0(t0)

FreeRTOS/Source/tasks.c

Lines changed: 69 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ changed then the definition of StaticTask_t must also be updated. */
100100
/* If any of the following are set then task stacks are filled with a known
101101
value so the high water mark can be determined. If none of the following are
102102
set then don't fill the stack so there is no unnecessary dependency on memset. */
103-
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )
103+
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) || ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) )
104104
#define tskSET_NEW_STACKS_TO_KNOWN_VALUE 1
105105
#else
106106
#define tskSET_NEW_STACKS_TO_KNOWN_VALUE 0
@@ -521,7 +521,7 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait, const BaseT
521521
* This function determines the 'high water mark' of the task stack by
522522
* determining how much of the stack remains at the original preset value.
523523
*/
524-
#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )
524+
#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) )
525525

526526
static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte ) PRIVILEGED_FUNCTION;
527527

@@ -861,8 +861,6 @@ UBaseType_t x;
861861
uxPriority &= ~portPRIVILEGE_BIT;
862862
#endif /* portUSING_MPU_WRAPPERS == 1 */
863863

864-
configASSERT( pcName );
865-
866864
/* Avoid dependency on memset() if it is not required. */
867865
#if( tskSET_NEW_STACKS_TO_KNOWN_VALUE == 1 )
868866
{
@@ -905,26 +903,35 @@ UBaseType_t x;
905903
#endif /* portSTACK_GROWTH */
906904

907905
/* Store the task name in the TCB. */
908-
for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )
906+
if( pcName != NULL )
909907
{
910-
pxNewTCB->pcTaskName[ x ] = pcName[ x ];
911-
912-
/* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than
913-
configMAX_TASK_NAME_LEN characters just in case the memory after the
914-
string is not accessible (extremely unlikely). */
915-
if( pcName[ x ] == ( char ) 0x00 )
916-
{
917-
break;
918-
}
919-
else
908+
for( x = ( UBaseType_t ) 0; x < ( UBaseType_t ) configMAX_TASK_NAME_LEN; x++ )
920909
{
921-
mtCOVERAGE_TEST_MARKER();
910+
pxNewTCB->pcTaskName[ x ] = pcName[ x ];
911+
912+
/* Don't copy all configMAX_TASK_NAME_LEN if the string is shorter than
913+
configMAX_TASK_NAME_LEN characters just in case the memory after the
914+
string is not accessible (extremely unlikely). */
915+
if( pcName[ x ] == ( char ) 0x00 )
916+
{
917+
break;
918+
}
919+
else
920+
{
921+
mtCOVERAGE_TEST_MARKER();
922+
}
922923
}
923-
}
924924

925-
/* Ensure the name string is terminated in the case that the string length
926-
was greater or equal to configMAX_TASK_NAME_LEN. */
927-
pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';
925+
/* Ensure the name string is terminated in the case that the string length
926+
was greater or equal to configMAX_TASK_NAME_LEN. */
927+
pxNewTCB->pcTaskName[ configMAX_TASK_NAME_LEN - 1 ] = '\0';
928+
}
929+
else
930+
{
931+
/* The task has not been given a name, so just ensure there is a NULL
932+
terminator when it is read out. */
933+
pxNewTCB->pcTaskName[ 0 ] = 0x00;
934+
}
928935

929936
/* This is used as an array index so must ensure it's not too large. First
930937
remove the privilege bit if one is present. */
@@ -3686,7 +3693,7 @@ static void prvCheckTasksWaitingTermination( void )
36863693
#endif /* configUSE_TRACE_FACILITY */
36873694
/*-----------------------------------------------------------*/
36883695

3689-
#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) )
3696+
#if ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) )
36903697

36913698
static configSTACK_DEPTH_TYPE prvTaskCheckFreeStackSpace( const uint8_t * pucStackByte )
36923699
{
@@ -3703,7 +3710,47 @@ static void prvCheckTasksWaitingTermination( void )
37033710
return ( configSTACK_DEPTH_TYPE ) ulCount;
37043711
}
37053712

3706-
#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) ) */
3713+
#endif /* ( ( configUSE_TRACE_FACILITY == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark == 1 ) || ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 ) ) */
3714+
/*-----------------------------------------------------------*/
3715+
3716+
#if ( INCLUDE_uxTaskGetStackHighWaterMark2 == 1 )
3717+
3718+
/* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are the
3719+
same except for their return type. Using configSTACK_DEPTH_TYPE allows the
3720+
user to determine the return type. It gets around the problem of the value
3721+
overflowing on 8-bit types without breaking backward compatibility for
3722+
applications that expect an 8-bit return type. */
3723+
configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask )
3724+
{
3725+
TCB_t *pxTCB;
3726+
uint8_t *pucEndOfStack;
3727+
configSTACK_DEPTH_TYPE uxReturn;
3728+
3729+
/* uxTaskGetStackHighWaterMark() and uxTaskGetStackHighWaterMark2() are
3730+
the same except for their return type. Using configSTACK_DEPTH_TYPE
3731+
allows the user to determine the return type. It gets around the
3732+
problem of the value overflowing on 8-bit types without breaking
3733+
backward compatibility for applications that expect an 8-bit return
3734+
type. */
3735+
3736+
pxTCB = prvGetTCBFromHandle( xTask );
3737+
3738+
#if portSTACK_GROWTH < 0
3739+
{
3740+
pucEndOfStack = ( uint8_t * ) pxTCB->pxStack;
3741+
}
3742+
#else
3743+
{
3744+
pucEndOfStack = ( uint8_t * ) pxTCB->pxEndOfStack;
3745+
}
3746+
#endif
3747+
3748+
uxReturn = prvTaskCheckFreeStackSpace( pucEndOfStack );
3749+
3750+
return uxReturn;
3751+
}
3752+
3753+
#endif /* INCLUDE_uxTaskGetStackHighWaterMark2 */
37073754
/*-----------------------------------------------------------*/
37083755

37093756
#if ( INCLUDE_uxTaskGetStackHighWaterMark == 1 )

0 commit comments

Comments
 (0)