freertos: Refactor port common functions

This commit refactors port_common.c so that it only contains implementation of
FreeRTOS port functions that are common to all FreeRTOS ports (i.e., on all
architectures and on all FreeRTOS implementations).
This commit is contained in:
Darian Leung
2022-11-24 22:28:13 +08:00
committed by Sudeep Mohanty
parent feee3a3059
commit 68646e23ae
4 changed files with 45 additions and 111 deletions

View File

@@ -50,6 +50,7 @@ if(CONFIG_FREERTOS_SMP)
endif() endif()
list(APPEND srcs list(APPEND srcs
"port_common.c"
"FreeRTOS-Kernel-SMP/croutine.c" "FreeRTOS-Kernel-SMP/croutine.c"
"FreeRTOS-Kernel-SMP/event_groups.c" "FreeRTOS-Kernel-SMP/event_groups.c"
"FreeRTOS-Kernel-SMP/list.c" "FreeRTOS-Kernel-SMP/list.c"
@@ -113,7 +114,7 @@ else()
endif() endif()
list(APPEND srcs list(APPEND srcs
"FreeRTOS-Kernel/portable/port_common.c" "port_common.c"
"FreeRTOS-Kernel/portable/port_systick.c" "FreeRTOS-Kernel/portable/port_systick.c"
"FreeRTOS-Kernel/croutine.c" "FreeRTOS-Kernel/croutine.c"
"FreeRTOS-Kernel/event_groups.c" "FreeRTOS-Kernel/event_groups.c"

View File

@@ -385,52 +385,6 @@ void vPortFreeStack( void *pv )
} }
#endif #endif
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize )
{
StackType_t *pxStackBufferTemp;
StaticTask_t *pxTCBBufferTemp;
/* Stack always grows downwards (from high address to low address) on all
* ESP RISC-V targets. Given that the heap allocator likely allocates memory
* from low to high address, we allocate the stack first and then the TCB so
* that the stack does not grow downwards into the TCB.
*
* Allocate TCB and stack buffer in internal memory. */
pxStackBufferTemp = pvPortMalloc(CONFIG_FREERTOS_IDLE_TASK_STACKSIZE);
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
assert(pxStackBufferTemp != NULL);
assert(pxTCBBufferTemp != NULL);
// Write back pointers
*ppxIdleTaskStackBuffer = pxStackBufferTemp;
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
*pulIdleTaskStackSize = CONFIG_FREERTOS_IDLE_TASK_STACKSIZE;
}
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize )
{
StackType_t *pxStackBufferTemp;
StaticTask_t *pxTCBBufferTemp;
/* Stack always grows downwards (from high address to low address) on all
* ESP RISC-V targets. Given that the heap allocator likely allocates memory
* from low to high address, we allocate the stack first and then the TCB so
* that the stack does not grow downwards into the TCB.
*
* Allocate TCB and stack buffer in internal memory. */
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
assert(pxStackBufferTemp != NULL);
assert(pxTCBBufferTemp != NULL);
// Write back pointers
*ppxTimerTaskStackBuffer = pxStackBufferTemp;
*ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
#endif //( configSUPPORT_STATIC_ALLOCATION == 1 )
// ------------------------ Stack -------------------------- // ------------------------ Stack --------------------------
#if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER #if CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER
/** /**

View File

@@ -405,52 +405,6 @@ void vPortFreeStack( void *pv )
} }
#endif #endif
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize )
{
StackType_t *pxStackBufferTemp;
StaticTask_t *pxTCBBufferTemp;
/* Stack always grows downwards (from high address to low address) on all
* ESP Xtensa targets. Given that the heap allocator likely allocates memory
* from low to high address, we allocate the stack first and then the TCB so
* that the stack does not grow downwards into the TCB.
*
* Allocate TCB and stack buffer in internal memory. */
pxStackBufferTemp = pvPortMalloc(CONFIG_FREERTOS_IDLE_TASK_STACKSIZE);
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
assert(pxStackBufferTemp != NULL);
assert(pxTCBBufferTemp != NULL);
// Write back pointers
*ppxIdleTaskStackBuffer = pxStackBufferTemp;
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
*pulIdleTaskStackSize = CONFIG_FREERTOS_IDLE_TASK_STACKSIZE;
}
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize )
{
StaticTask_t *pxTCBBufferTemp;
StackType_t *pxStackBufferTemp;
/* Stack always grows downwards (from high address to low address) on all
* ESP Xtensa targets. Given that the heap allocator likely allocates memory
* from low to high address, we allocate the stack first and then the TCB so
* that the stack does not grow downwards into the TCB.
*
* Allocate TCB and stack buffer in internal memory. */
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
assert(pxStackBufferTemp != NULL);
assert(pxTCBBufferTemp != NULL);
// Write back pointers
*ppxTimerTaskStackBuffer = pxStackBufferTemp;
*ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
#endif //( configSUPPORT_STATIC_ALLOCATION == 1 )
// ------------------------ Stack -------------------------- // ------------------------ Stack --------------------------
// User exception dispatcher when exiting // User exception dispatcher when exiting

View File

@@ -11,8 +11,14 @@
#include "esp_memory_utils.h" #include "esp_memory_utils.h"
#include "sdkconfig.h" #include "sdkconfig.h"
/* ----------------------------------------- Port Implementations (Common) --------------------------------------------
* - Common FreeRTOS port function implementations
* - These functions are common to all FreeRTOS ports (i.e., on all architectures and all FreeRTOS implementations).
* ------------------------------------------------------------------------------------------------------------------ */
// -------------------- Heap Related ----------------------- // -------------------- Heap Related -----------------------
#if !CONFIG_FREERTOS_SMP // IDF-3997
bool xPortCheckValidTCBMem(const void *ptr) bool xPortCheckValidTCBMem(const void *ptr)
{ {
return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr); return esp_ptr_internal(ptr) && esp_ptr_byte_accessible(ptr);
@@ -26,16 +32,18 @@ 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
} }
#endif
// ------------- FreeRTOS Static Allocation ---------------- // ------------- FreeRTOS Static Allocation ----------------
/* /*
This function is required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is These function are required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
enabled and is used by FreeRTOS to obtain memory for its IDLE tasks. enabled and is used by FreeRTOS to obtain memory for its IDLE/Timer tasks.
Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack Like the pvPortMallocTcbMem() and pvPortMallocStackMem() macros, TCB and stack
memory MUST be placed in internal RAM. memory MUST be placed in internal RAM.
*/ */
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer, void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer, StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize ) uint32_t *pulIdleTaskStackSize )
@@ -49,14 +57,24 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
#if (portSTACK_GROWTH > 0) #if (portSTACK_GROWTH > 0)
{ {
//Allocate TCB and stack buffer in internal memory //Allocate TCB and stack buffer in internal memory
#if CONFIG_FREERTOS_SMP // IDF-3997
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
#else
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t)); pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
pxStackBufferTemp = pvPortMallocStackMem(configIDLE_TASK_STACK_SIZE); pxStackBufferTemp = pvPortMallocStackMem(configIDLE_TASK_STACK_SIZE);
#endif /* CONFIG_FREERTOS_SMP */
} }
#else /* portSTACK_GROWTH */ #else /* portSTACK_GROWTH */
{ {
//Allocate TCB and stack buffer in internal memory //Allocate TCB and stack buffer in internal memory
#if CONFIG_FREERTOS_SMP // IDF-3997
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
#else
pxStackBufferTemp = pvPortMallocStackMem(configIDLE_TASK_STACK_SIZE); pxStackBufferTemp = pvPortMallocStackMem(configIDLE_TASK_STACK_SIZE);
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t)); pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
#endif /* CONFIG_FREERTOS_SMP */
} }
#endif /* portSTACK_GROWTH */ #endif /* portSTACK_GROWTH */
@@ -65,17 +83,13 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
//Write back pointers //Write back pointers
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp; *ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
*ppxIdleTaskStackBuffer = pxStackBufferTemp; *ppxIdleTaskStackBuffer = pxStackBufferTemp;
#if CONFIG_FREERTOS_SMP
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
#else
*pulIdleTaskStackSize = configIDLE_TASK_STACK_SIZE; *pulIdleTaskStackSize = configIDLE_TASK_STACK_SIZE;
#endif /* CONFIG_FREERTOS_SMP */
} }
/*
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, void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
StackType_t **ppxTimerTaskStackBuffer, StackType_t **ppxTimerTaskStackBuffer,
uint32_t *pulTimerTaskStackSize ) uint32_t *pulTimerTaskStackSize )
@@ -89,14 +103,24 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
#if (portSTACK_GROWTH > 0) #if (portSTACK_GROWTH > 0)
{ {
//Allocate TCB and stack buffer in internal memory //Allocate TCB and stack buffer in internal memory
#if CONFIG_FREERTOS_SMP // IDF-3997
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
#else
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t)); pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH); pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
#endif /* CONFIG_FREERTOS_SMP */
} }
#else /* portSTACK_GROWTH */ #else /* portSTACK_GROWTH */
{ {
//Allocate TCB and stack buffer in internal memory //Allocate TCB and stack buffer in internal memory
#if CONFIG_FREERTOS_SMP // IDF-3997
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
#else
pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH); pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t)); pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
#endif /* CONFIG_FREERTOS_SMP */
} }
#endif /* portSTACK_GROWTH */ #endif /* portSTACK_GROWTH */
@@ -107,3 +131,4 @@ void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
*ppxTimerTaskStackBuffer = pxStackBufferTemp; *ppxTimerTaskStackBuffer = pxStackBufferTemp;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH; *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
} }
#endif // configSUPPORT_STATIC_ALLOCATION == 1