freertos: Add memory hooks for static IDLE and Timer tasks

This commit adds the following hook functions to obtain memory
for the IDLE and Timer Daemon tasks when configSUPPORT_STATIC_ALLOCATION
is enabled:

- vApplicationGetIdleTaskMemory()
- vApplicationGetTimerTaskMemory()

Currently, both functions simply allocate from the same memory as
regular tasks (i.e., internal memory for both the stack and TCB)

Closes https://github.com/espressif/esp-idf/issues/7511
This commit is contained in:
Darian Leung
2021-10-16 01:08:46 +08:00
parent 6a93575d97
commit 5ac3b05cbe
3 changed files with 73 additions and 23 deletions

View File

@@ -145,3 +145,54 @@ bool xPortcheckValidStackMem(const void *ptr)
return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr); return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
#endif #endif
} }
// ------------- FreeRTOS Static Allocation ----------------
/*
This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
enabled and is used by FreeRTOS to obtain memory for its IDLE tasks.
Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
memory MUST be placed in internal RAM.
*/
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize )
{
StaticTask_t *pxTCBBufferTemp;
StackType_t *pxStackBufferTemp;
//Allocate TCB and stack buffer in internal memory
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
pxStackBufferTemp = pvPortMallocStackMem(configIDLE_TASK_STACK_SIZE);
assert(pxTCBBufferTemp != NULL);
assert(pxStackBufferTemp != NULL);
//Write back pointers
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
*ppxIdleTaskStackBuffer = pxStackBufferTemp;
*pulIdleTaskStackSize = configIDLE_TASK_STACK_SIZE;
}
/*
This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
enabled and is used by the FreeRTOS Timer to obtain memory for its daemone task.
Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
memory MUST be placed in internal RAM.
*/
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize )
{
StaticTask_t *pxTCBBufferTemp;
StackType_t *pxStackBufferTemp;
//Allocate TCB and stack buffer in internal memory
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
assert(pxTCBBufferTemp != NULL);
assert(pxStackBufferTemp != NULL);
//Write back pointers
*ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
*ppxTimerTaskStackBuffer = pxStackBufferTemp;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}

View File

@@ -2260,30 +2260,30 @@ void vTaskStartScheduler( void )
{ {
BaseType_t xReturn; BaseType_t xReturn;
#if ( configSUPPORT_STATIC_ALLOCATION == 1 && configSUPPORT_STATIC_ALLOCATION == 0 ) #ifdef ESP_PLATFORM
StaticTask_t *pxIdleTaskTCBBuffer[configNUM_CORES] = {NULL}; /* Create an IDLE task for each core */
StackType_t *pxIdleTaskStackBuffer[configNUM_CORES] = {NULL}; for(BaseType_t xCoreID = 0; xCoreID < configNUM_CORES; xCoreID++)
uint32_t ulIdleTaskStackSize; #endif //ESP_PLATFORM
#endif /* Add the idle task at the lowest priority. */
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
for(BaseType_t i = 0; i < configNUM_CORES; i++)
{
/* Add the idle task at the lowest priority. */
#if( 0 ) /* configSUPPORT_STATIC_ALLOCATION == 1 ) Temporarily unsupported IDF-2243 */
{ {
StaticTask_t * pxIdleTaskTCBBuffer = NULL;
StackType_t * pxIdleTaskStackBuffer = NULL;
uint32_t ulIdleTaskStackSize;
/* The Idle task is created using user provided RAM - obtain the /* The Idle task is created using user provided RAM - obtain the
address of the RAM then create the idle task. */ address of the RAM then create the idle task. */
vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer[i], &pxIdleTaskStackBuffer[i], &ulIdleTaskStackSize ); vApplicationGetIdleTaskMemory( &pxIdleTaskTCBBuffer, &pxIdleTaskStackBuffer, &ulIdleTaskStackSize );
xIdleTaskHandle[i] = xTaskCreateStaticPinnedToCore( prvIdleTask, xIdleTaskHandle[ xCoreID ] = xTaskCreateStaticPinnedToCore( prvIdleTask,
configIDLE_TASK_NAME, configIDLE_TASK_NAME,
ulIdleTaskStackSize, ulIdleTaskStackSize,
( void * ) NULL, /*lint !e961. The cast is not redundant for all compilers. */ ( void * ) NULL, /*lint !e961. The cast is not redundant for all compilers. */
portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */ portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */
pxIdleTaskStackBuffer[i], pxIdleTaskStackBuffer,
pxIdleTaskTCBBuffer[i], pxIdleTaskTCBBuffer,
i ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ xCoreID ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */
if( xIdleTaskHandle[i] != NULL ) if( xIdleTaskHandle[ xCoreID ] != NULL )
{ {
xReturn = pdPASS; xReturn = pdPASS;
} }
@@ -2300,10 +2300,10 @@ void vTaskStartScheduler( void )
configIDLE_TASK_STACK_SIZE, configIDLE_TASK_STACK_SIZE,
( void * ) NULL, ( void * ) NULL,
portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */ portPRIVILEGE_BIT, /* In effect ( tskIDLE_PRIORITY | portPRIVILEGE_BIT ), but tskIDLE_PRIORITY is zero. */
&xIdleTaskHandle[i], &xIdleTaskHandle[ xCoreID ],
i ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */ xCoreID ); /*lint !e961 MISRA exception, justified as it is not a redundant explicit cast to all supported compilers. */
if( xIdleTaskHandle[i] != NULL ) if( xIdleTaskHandle[ xCoreID ] != NULL )
{ {
xReturn = pdPASS; xReturn = pdPASS;
} }
@@ -2313,7 +2313,6 @@ void vTaskStartScheduler( void )
} }
} }
#endif /* configSUPPORT_STATIC_ALLOCATION */ #endif /* configSUPPORT_STATIC_ALLOCATION */
}
#if ( configUSE_TIMERS == 1 ) #if ( configUSE_TIMERS == 1 )
{ {

View File

@@ -247,7 +247,7 @@ PRIVILEGED_DATA portMUX_TYPE xTimerMux = portMUX_INITIALIZER_UNLOCKED;
if( xTimerQueue != NULL ) if( xTimerQueue != NULL )
{ {
#if ( configSUPPORT_STATIC_ALLOCATION == 1 && configSUPPORT_STATIC_ALLOCATION == 0 ) #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
{ {
StaticTask_t * pxTimerTaskTCBBuffer = NULL; StaticTask_t * pxTimerTaskTCBBuffer = NULL;
StackType_t * pxTimerTaskStackBuffer = NULL; StackType_t * pxTimerTaskStackBuffer = NULL;