Skip to content

Commit 4bfb9b2

Browse files
chinglee-iotaggarg
andauthored
Update SMP get idle task memory for static allocation (#784)
* Add static idle task memory support for SMP * Rename vApplicationMinimalIdleTask to vApplicationPassiveIdleTask * Rename the macro configUSE_MINIMAL_IDLE_HOOK to configUSE_PASSIVE_IDLE_HOOK * Update xTaskGetIdleTaskHandle for SMP * Add more check in xTaskGetIdleTaskHandle * Support configKERNEL_PROVIDED_STATIC_MEMORY for SMP --------- Signed-off-by: Gaurav Aggarwal <[email protected]> Co-authored-by: Gaurav Aggarwal <[email protected]> Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
1 parent 92a4d17 commit 4bfb9b2

File tree

3 files changed

+233
-190
lines changed

3 files changed

+233
-190
lines changed

include/FreeRTOS.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@
175175
#endif
176176

177177
#if ( configNUMBER_OF_CORES > 1 )
178-
#ifndef configUSE_MINIMAL_IDLE_HOOK
179-
#error Missing definition: configUSE_MINIMAL_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
178+
#ifndef configUSE_PASSIVE_IDLE_HOOK
179+
#error Missing definition: configUSE_PASSIVE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
180180
#endif
181181
#endif
182182

@@ -473,9 +473,9 @@
473473
#define configUSE_CORE_AFFINITY 0
474474
#endif /* configUSE_CORE_AFFINITY */
475475

476-
#ifndef configUSE_MINIMAL_IDLE_HOOK
477-
#define configUSE_MINIMAL_IDLE_HOOK 0
478-
#endif /* configUSE_MINIMAL_IDLE_HOOK */
476+
#ifndef configUSE_PASSIVE_IDLE_HOOK
477+
#define configUSE_PASSIVE_IDLE_HOOK 0
478+
#endif /* configUSE_PASSIVE_IDLE_HOOK */
479479

480480
/* The timers module relies on xTaskGetSchedulerState(). */
481481
#if configUSE_TIMERS == 1
@@ -1834,8 +1834,14 @@
18341834
#define traceRETURN_uxTaskGetSystemState( uxTask )
18351835
#endif
18361836

1837-
#ifndef traceENTER_xTaskGetIdleTaskHandle
1838-
#define traceENTER_xTaskGetIdleTaskHandle()
1837+
#if ( configNUMBER_OF_CORES == 1 )
1838+
#ifndef traceENTER_xTaskGetIdleTaskHandle
1839+
#define traceENTER_xTaskGetIdleTaskHandle()
1840+
#endif
1841+
#else
1842+
#ifndef traceENTER_xTaskGetIdleTaskHandle
1843+
#define traceENTER_xTaskGetIdleTaskHandle( xCoreID )
1844+
#endif
18391845
#endif
18401846

18411847
#ifndef traceRETURN_xTaskGetIdleTaskHandle

include/task.h

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,8 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL
19301930

19311931
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
19321932

1933+
#if ( configNUMBER_OF_CORES == 1 )
1934+
19331935
/**
19341936
* task.h
19351937
* @code{c}
@@ -1943,10 +1945,41 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL
19431945
* @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
19441946
* @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
19451947
*/
1946-
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
1947-
StackType_t ** ppxIdleTaskStackBuffer,
1948-
uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
1949-
#endif
1948+
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
1949+
StackType_t ** ppxIdleTaskStackBuffer,
1950+
uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
1951+
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
1952+
1953+
/**
1954+
* task.h
1955+
* @code{c}
1956+
* void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize, BaseType_t xCoreID )
1957+
* @endcode
1958+
*
1959+
* This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Tasks TCB. This function is required when
1960+
* configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
1961+
*
1962+
* In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
1963+
* 1. 1 Active idle task which does all the housekeeping.
1964+
* 2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
1965+
* These idle tasks are created to ensure that each core has an idle task to run when
1966+
* no other task is available to run.
1967+
*
1968+
* The function vApplicationGetIdleTaskMemory is called with xCoreID 0 to get the
1969+
* memory for Active idle task. It is called with xCoreID 1, 2 ... ( configNUMBER_OF_CORES - 1 )
1970+
* to get memory for passive idle tasks.
1971+
*
1972+
* @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
1973+
* @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
1974+
* @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
1975+
* @param xCoreId The core index of the idle task buffer
1976+
*/
1977+
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
1978+
StackType_t ** ppxIdleTaskStackBuffer,
1979+
uint32_t * pulIdleTaskStackSize, /*lint !e526 Symbol not defined as it is an application callback. */
1980+
BaseType_t xCoreID );
1981+
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
1982+
#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
19501983

19511984
/**
19521985
* task.h
@@ -1970,8 +2003,22 @@ BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
19702003
*
19712004
* Simply returns the handle of the idle task. It is not valid to call
19722005
* xTaskGetIdleTaskHandle() before the scheduler has been started.
2006+
*
2007+
* In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
2008+
* 1. 1 Active idle task which does all the housekeeping.
2009+
* 2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
2010+
* These idle tasks are created to ensure that each core has an idle task to run when
2011+
* no other task is available to run.
2012+
*
2013+
* Set xCoreID to 0 to get the Active idle task handle. Set xCoreID to
2014+
* 1,2 ... ( configNUMBER_OF_CORES - 1 ) to get the Passive idle task
2015+
* handles.
19732016
*/
1974-
TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
2017+
#if ( configNUMBER_OF_CORES == 1 )
2018+
TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
2019+
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
2020+
TaskHandle_t xTaskGetIdleTaskHandle( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
2021+
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
19752022

19762023
/**
19772024
* configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for

0 commit comments

Comments
 (0)