mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Support reset kernel state for restarting scheduler (#944)
* Adding the following functions to reset kernel state. These functions are only required for application which needs to restart the scheduler. - void vTaskResetState( void ) - void vTimerResetState( void ) - void vPortHeapResetState( void ) - void vCoRoutineResetState( void ) --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Chris Morgan <cmorgan@boston-engineering.com> Co-authored-by: Soren Ptak <ptaksoren@gmail.com> Co-authored-by: Rahul Kar <118818625+kar-rahul-aws@users.noreply.github.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
This commit is contained in:
parent
e68975fcf7
commit
1a500f1a74
27
croutine.c
27
croutine.c
|
@ -52,8 +52,10 @@
|
||||||
|
|
||||||
/* Other file private variables. --------------------------------*/
|
/* Other file private variables. --------------------------------*/
|
||||||
CRCB_t * pxCurrentCoRoutine = NULL;
|
CRCB_t * pxCurrentCoRoutine = NULL;
|
||||||
static UBaseType_t uxTopCoRoutineReadyPriority = 0;
|
static UBaseType_t uxTopCoRoutineReadyPriority = ( UBaseType_t ) 0U;
|
||||||
static TickType_t xCoRoutineTickCount = 0, xLastTickCount = 0, xPassedTicks = 0;
|
static TickType_t xCoRoutineTickCount = ( TickType_t ) 0U;
|
||||||
|
static TickType_t xLastTickCount = ( TickType_t ) 0U;
|
||||||
|
static TickType_t xPassedTicks = ( TickType_t ) 0U;
|
||||||
|
|
||||||
/* The initial state of the co-routine when it is created. */
|
/* The initial state of the co-routine when it is created. */
|
||||||
#define corINITIAL_STATE ( 0 )
|
#define corINITIAL_STATE ( 0 )
|
||||||
|
@ -378,5 +380,26 @@
|
||||||
|
|
||||||
return xReturn;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vCoRoutineResetState( void )
|
||||||
|
{
|
||||||
|
/* Lists for ready and blocked co-routines. */
|
||||||
|
pxDelayedCoRoutineList = NULL;
|
||||||
|
pxOverflowDelayedCoRoutineList = NULL;
|
||||||
|
|
||||||
|
/* Other file private variables. */
|
||||||
|
pxCurrentCoRoutine = NULL;
|
||||||
|
uxTopCoRoutineReadyPriority = ( UBaseType_t ) 0U;
|
||||||
|
xCoRoutineTickCount = ( TickType_t ) 0U;
|
||||||
|
xLastTickCount = ( TickType_t ) 0U;
|
||||||
|
xPassedTicks = ( TickType_t ) 0U;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
#endif /* configUSE_CO_ROUTINES == 0 */
|
#endif /* configUSE_CO_ROUTINES == 0 */
|
||||||
|
|
|
@ -746,6 +746,13 @@ void vCoRoutineAddToDelayedList( TickType_t xTicksToDelay,
|
||||||
*/
|
*/
|
||||||
BaseType_t xCoRoutineRemoveFromEventList( const List_t * pxEventList );
|
BaseType_t xCoRoutineRemoveFromEventList( const List_t * pxEventList );
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function resets the internal state of the coroutine module. It must be
|
||||||
|
* called by the application before restarting the scheduler.
|
||||||
|
*/
|
||||||
|
void vCoRoutineResetState( void ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,6 +194,12 @@ size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
||||||
#define vPortFreeStack vPortFree
|
#define vPortFreeStack vPortFree
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function resets the internal state of the heap module. It must be called
|
||||||
|
* by the application before restarting the scheduler.
|
||||||
|
*/
|
||||||
|
void vPortHeapResetState( void ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
|
#if ( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3438,6 +3438,20 @@ BaseType_t xTaskCheckForTimeOut( TimeOut_t * const pxTimeOut,
|
||||||
*/
|
*/
|
||||||
BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
|
BaseType_t xTaskCatchUpTicks( TickType_t xTicksToCatchUp ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* task.h
|
||||||
|
* @code{c}
|
||||||
|
* void vTaskResetState( void );
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* This function resets the internal state of the task. It must be called by the
|
||||||
|
* application before restarting the scheduler.
|
||||||
|
*
|
||||||
|
* \defgroup vTaskResetState vTaskResetState
|
||||||
|
* \ingroup SchedulerControl
|
||||||
|
*/
|
||||||
|
void vTaskResetState( void ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
|
* SCHEDULER INTERNALS AVAILABLE FOR PORTING PURPOSES
|
||||||
|
|
|
@ -1417,6 +1417,12 @@ BaseType_t xTimerGenericCommandFromISR( TimerHandle_t xTimer,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function resets the internal state of the timer module. It must be called
|
||||||
|
* by the application before restarting the scheduler.
|
||||||
|
*/
|
||||||
|
void vTimerResetState( void ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
#endif /* configAPPLICATION_ALLOCATED_HEAP */
|
#endif /* configAPPLICATION_ALLOCATED_HEAP */
|
||||||
|
|
||||||
/* Index into the ucHeap array. */
|
/* Index into the ucHeap array. */
|
||||||
static size_t xNextFreeByte = ( size_t ) 0;
|
static size_t xNextFreeByte = ( size_t ) 0U;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -150,3 +150,16 @@ size_t xPortGetFreeHeapSize( void )
|
||||||
{
|
{
|
||||||
return( configADJUSTED_HEAP_SIZE - xNextFreeByte );
|
return( configADJUSTED_HEAP_SIZE - xNextFreeByte );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vPortHeapResetState( void )
|
||||||
|
{
|
||||||
|
xNextFreeByte = ( size_t ) 0U;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -113,6 +113,9 @@ PRIVILEGED_DATA static BlockLink_t xStart, xEnd;
|
||||||
* fragmentation. */
|
* fragmentation. */
|
||||||
PRIVILEGED_DATA static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;
|
PRIVILEGED_DATA static size_t xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;
|
||||||
|
|
||||||
|
/* Indicates whether the heap has been initialised or not. */
|
||||||
|
PRIVILEGED_DATA static BaseType_t xHeapHasBeenInitialised = pdFALSE;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -155,7 +158,6 @@ void * pvPortMalloc( size_t xWantedSize )
|
||||||
BlockLink_t * pxBlock;
|
BlockLink_t * pxBlock;
|
||||||
BlockLink_t * pxPreviousBlock;
|
BlockLink_t * pxPreviousBlock;
|
||||||
BlockLink_t * pxNewBlockLink;
|
BlockLink_t * pxNewBlockLink;
|
||||||
PRIVILEGED_DATA static BaseType_t xHeapHasBeenInitialised = pdFALSE;
|
|
||||||
void * pvReturn = NULL;
|
void * pvReturn = NULL;
|
||||||
size_t xAdditionalRequiredSize;
|
size_t xAdditionalRequiredSize;
|
||||||
|
|
||||||
|
@ -384,3 +386,16 @@ static void prvHeapInit( void ) /* PRIVILEGED_FUNCTION */
|
||||||
pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
|
pxFirstFreeBlock->pxNextFreeBlock = &xEnd;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vPortHeapResetState( void )
|
||||||
|
{
|
||||||
|
xFreeBytesRemaining = configADJUSTED_HEAP_SIZE;
|
||||||
|
|
||||||
|
xHeapHasBeenInitialised = pdFALSE;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -92,3 +92,15 @@ void vPortFree( void * pv )
|
||||||
( void ) xTaskResumeAll();
|
( void ) xTaskResumeAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vPortHeapResetState( void )
|
||||||
|
{
|
||||||
|
/* No state needs to be re-initialised in heap_3. */
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -163,10 +163,10 @@ PRIVILEGED_DATA static BlockLink_t * pxEnd = NULL;
|
||||||
|
|
||||||
/* Keeps track of the number of calls to allocate and free memory as well as the
|
/* Keeps track of the number of calls to allocate and free memory as well as the
|
||||||
* number of free bytes remaining, but says nothing about fragmentation. */
|
* number of free bytes remaining, but says nothing about fragmentation. */
|
||||||
PRIVILEGED_DATA static size_t xFreeBytesRemaining = 0U;
|
PRIVILEGED_DATA static size_t xFreeBytesRemaining = ( size_t ) 0U;
|
||||||
PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U;
|
PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = ( size_t ) 0U;
|
||||||
PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = 0;
|
PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = ( size_t ) 0U;
|
||||||
PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = 0;
|
PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = ( size_t ) 0U;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -608,3 +608,19 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vPortHeapResetState( void )
|
||||||
|
{
|
||||||
|
pxEnd = NULL;
|
||||||
|
|
||||||
|
xFreeBytesRemaining = ( size_t ) 0U;
|
||||||
|
xMinimumEverFreeBytesRemaining = ( size_t ) 0U;
|
||||||
|
xNumberOfSuccessfulAllocations = ( size_t ) 0U;
|
||||||
|
xNumberOfSuccessfulFrees = ( size_t ) 0U;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
@ -187,10 +187,10 @@ PRIVILEGED_DATA static BlockLink_t * pxEnd = NULL;
|
||||||
|
|
||||||
/* Keeps track of the number of calls to allocate and free memory as well as the
|
/* Keeps track of the number of calls to allocate and free memory as well as the
|
||||||
* number of free bytes remaining, but says nothing about fragmentation. */
|
* number of free bytes remaining, but says nothing about fragmentation. */
|
||||||
PRIVILEGED_DATA static size_t xFreeBytesRemaining = 0U;
|
PRIVILEGED_DATA static size_t xFreeBytesRemaining = ( size_t ) 0U;
|
||||||
PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = 0U;
|
PRIVILEGED_DATA static size_t xMinimumEverFreeBytesRemaining = ( size_t ) 0U;
|
||||||
PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = 0;
|
PRIVILEGED_DATA static size_t xNumberOfSuccessfulAllocations = ( size_t ) 0U;
|
||||||
PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = 0;
|
PRIVILEGED_DATA static size_t xNumberOfSuccessfulFrees = ( size_t ) 0U;
|
||||||
|
|
||||||
#if ( configENABLE_HEAP_PROTECTOR == 1 )
|
#if ( configENABLE_HEAP_PROTECTOR == 1 )
|
||||||
|
|
||||||
|
@ -707,3 +707,24 @@ void vPortGetHeapStats( HeapStats_t * pxHeapStats )
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vPortHeapResetState( void )
|
||||||
|
{
|
||||||
|
pxEnd = NULL;
|
||||||
|
|
||||||
|
xFreeBytesRemaining = ( size_t ) 0U;
|
||||||
|
xMinimumEverFreeBytesRemaining = ( size_t ) 0U;
|
||||||
|
xNumberOfSuccessfulAllocations = ( size_t ) 0U;
|
||||||
|
xNumberOfSuccessfulFrees = ( size_t ) 0U;
|
||||||
|
|
||||||
|
#if ( configENABLE_HEAP_PROTECTOR == 1 )
|
||||||
|
pucHeapHighAddress = NULL;
|
||||||
|
pucHeapLowAddress = NULL;
|
||||||
|
#endif /* #if ( configENABLE_HEAP_PROTECTOR == 1 ) */
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
58
tasks.c
58
tasks.c
|
@ -8694,3 +8694,61 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
|
||||||
|
|
||||||
#endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configKERNEL_PROVIDED_STATIC_MEMORY == 1 ) && ( portUSING_MPU_WRAPPERS == 0 ) ) */
|
#endif /* #if ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configKERNEL_PROVIDED_STATIC_MEMORY == 1 ) && ( portUSING_MPU_WRAPPERS == 0 ) ) */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vTaskResetState( void )
|
||||||
|
{
|
||||||
|
BaseType_t xCoreID;
|
||||||
|
|
||||||
|
/* Task control block. */
|
||||||
|
#if ( configNUMBER_OF_CORES == 1 )
|
||||||
|
{
|
||||||
|
pxCurrentTCB = NULL;
|
||||||
|
}
|
||||||
|
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
|
||||||
|
|
||||||
|
#if ( INCLUDE_vTaskDelete == 1 )
|
||||||
|
{
|
||||||
|
uxDeletedTasksWaitingCleanUp = ( UBaseType_t ) 0U;
|
||||||
|
}
|
||||||
|
#endif /* #if ( INCLUDE_vTaskDelete == 1 ) */
|
||||||
|
|
||||||
|
#if ( configUSE_POSIX_ERRNO == 1 )
|
||||||
|
{
|
||||||
|
FreeRTOS_errno = 0;
|
||||||
|
}
|
||||||
|
#endif /* #if ( configUSE_POSIX_ERRNO == 1 ) */
|
||||||
|
|
||||||
|
/* Other file private variables. */
|
||||||
|
uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
|
||||||
|
xTickCount = ( TickType_t ) configINITIAL_TICK_COUNT;
|
||||||
|
uxTopReadyPriority = tskIDLE_PRIORITY;
|
||||||
|
xSchedulerRunning = pdFALSE;
|
||||||
|
xPendedTicks = ( TickType_t ) 0U;
|
||||||
|
|
||||||
|
for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
|
||||||
|
{
|
||||||
|
xYieldPendings[ xCoreID ] = pdFALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
xNumOfOverflows = ( BaseType_t ) 0;
|
||||||
|
uxTaskNumber = ( UBaseType_t ) 0U;
|
||||||
|
xNextTaskUnblockTime = ( TickType_t ) 0U;
|
||||||
|
|
||||||
|
uxSchedulerSuspended = ( UBaseType_t ) 0U;
|
||||||
|
|
||||||
|
#if ( configGENERATE_RUN_TIME_STATS == 1 )
|
||||||
|
{
|
||||||
|
for( xCoreID = 0; xCoreID < configNUMBER_OF_CORES; xCoreID++ )
|
||||||
|
{
|
||||||
|
ulTaskSwitchedInTime[ xCoreID ] = 0U;
|
||||||
|
ulTotalRunTime[ xCoreID ] = 0U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* #if ( configGENERATE_RUN_TIME_STATS == 1 ) */
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
12
timers.c
12
timers.c
|
@ -1322,6 +1322,18 @@
|
||||||
#endif /* configUSE_TRACE_FACILITY */
|
#endif /* configUSE_TRACE_FACILITY */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reset the state in this file. This state is normally initialized at start up.
|
||||||
|
* This function must be called by the application before restarting the
|
||||||
|
* scheduler.
|
||||||
|
*/
|
||||||
|
void vTimerResetState( void )
|
||||||
|
{
|
||||||
|
xTimerQueue = NULL;
|
||||||
|
xTimerTaskHandle = NULL;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/* This entire source file will be skipped if the application is not configured
|
/* This entire source file will be skipped if the application is not configured
|
||||||
* to include software timer functionality. If you want to include software timer
|
* to include software timer functionality. If you want to include software timer
|
||||||
* functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
|
* functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
|
||||||
|
|
Loading…
Reference in a new issue