forked from espressif/esp-idf
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:
@@ -53,6 +53,7 @@ else()
|
|||||||
list(APPEND srcs
|
list(APPEND srcs
|
||||||
"app_startup.c"
|
"app_startup.c"
|
||||||
"FreeRTOS-openocd.c"
|
"FreeRTOS-openocd.c"
|
||||||
|
"port_common.c"
|
||||||
"${kernel_dir}/portable/${arch}/portasm.S")
|
"${kernel_dir}/portable/${arch}/portasm.S")
|
||||||
|
|
||||||
list(APPEND private_include_dirs
|
list(APPEND private_include_dirs
|
||||||
@@ -63,7 +64,6 @@ else()
|
|||||||
list(APPEND include_dirs "${kernel_dir}/portable/${arch}/include/freertos") # Xtensa headers via #include "xx.h"
|
list(APPEND include_dirs "${kernel_dir}/portable/${arch}/include/freertos") # Xtensa headers via #include "xx.h"
|
||||||
else()
|
else()
|
||||||
list(APPEND srcs
|
list(APPEND srcs
|
||||||
"${kernel_dir}/portable/port_common.c"
|
|
||||||
"${kernel_dir}/portable/port_systick.c"
|
"${kernel_dir}/portable/port_systick.c"
|
||||||
"esp_additions/freertos_v8_compat.c")
|
"esp_additions/freertos_v8_compat.c")
|
||||||
|
|
||||||
|
@@ -385,72 +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;
|
|
||||||
|
|
||||||
/* If the stack grows down then allocate the stack then the TCB so the stack
|
|
||||||
* does not grow into the TCB. Likewise if the stack grows up then allocate
|
|
||||||
* the TCB then the stack. */
|
|
||||||
#if (portSTACK_GROWTH > 0)
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
|
||||||
}
|
|
||||||
#else /* portSTACK_GROWTH */
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
}
|
|
||||||
#endif /* portSTACK_GROWTH */
|
|
||||||
|
|
||||||
assert(pxStackBufferTemp != NULL);
|
|
||||||
assert(pxTCBBufferTemp != NULL);
|
|
||||||
// Write back pointers
|
|
||||||
*ppxIdleTaskStackBuffer = pxStackBufferTemp;
|
|
||||||
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
|
|
||||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
|
|
||||||
StackType_t **ppxTimerTaskStackBuffer,
|
|
||||||
uint32_t *pulTimerTaskStackSize )
|
|
||||||
{
|
|
||||||
StaticTask_t *pxTCBBufferTemp;
|
|
||||||
StackType_t *pxStackBufferTemp;
|
|
||||||
|
|
||||||
/* If the stack grows down then allocate the stack then the TCB so the stack
|
|
||||||
* does not grow into the TCB. Likewise if the stack grows up then allocate
|
|
||||||
* the TCB then the stack. */
|
|
||||||
#if (portSTACK_GROWTH > 0)
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
|
||||||
}
|
|
||||||
#else /* portSTACK_GROWTH */
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
}
|
|
||||||
#endif /* portSTACK_GROWTH */
|
|
||||||
|
|
||||||
assert(pxTCBBufferTemp != NULL);
|
|
||||||
assert(pxStackBufferTemp != NULL);
|
|
||||||
//Write back pointers
|
|
||||||
*ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
|
|
||||||
*ppxTimerTaskStackBuffer = pxStackBufferTemp;
|
|
||||||
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
|
||||||
}
|
|
||||||
#endif //( configSUPPORT_STATIC_ALLOCATION == 1 )
|
|
||||||
|
|
||||||
// ------------------------ Stack --------------------------
|
// ------------------------ Stack --------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -406,72 +406,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;
|
|
||||||
|
|
||||||
/* If the stack grows down then allocate the stack then the TCB so the stack
|
|
||||||
* does not grow into the TCB. Likewise if the stack grows up then allocate
|
|
||||||
* the TCB then the stack. */
|
|
||||||
#if (portSTACK_GROWTH > 0)
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
|
||||||
}
|
|
||||||
#else /* portSTACK_GROWTH */
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
}
|
|
||||||
#endif /* portSTACK_GROWTH */
|
|
||||||
|
|
||||||
assert(pxStackBufferTemp != NULL);
|
|
||||||
assert(pxTCBBufferTemp != NULL);
|
|
||||||
// Write back pointers
|
|
||||||
*ppxIdleTaskStackBuffer = pxStackBufferTemp;
|
|
||||||
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
|
|
||||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
|
|
||||||
StackType_t **ppxTimerTaskStackBuffer,
|
|
||||||
uint32_t *pulTimerTaskStackSize )
|
|
||||||
{
|
|
||||||
StaticTask_t *pxTCBBufferTemp;
|
|
||||||
StackType_t *pxStackBufferTemp;
|
|
||||||
|
|
||||||
/* If the stack grows down then allocate the stack then the TCB so the stack
|
|
||||||
* does not grow into the TCB. Likewise if the stack grows up then allocate
|
|
||||||
* the TCB then the stack. */
|
|
||||||
#if (portSTACK_GROWTH > 0)
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
|
||||||
}
|
|
||||||
#else /* portSTACK_GROWTH */
|
|
||||||
{
|
|
||||||
//Allocate TCB and stack buffer in internal memory
|
|
||||||
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
|
||||||
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
||||||
}
|
|
||||||
#endif /* portSTACK_GROWTH */
|
|
||||||
|
|
||||||
assert(pxTCBBufferTemp != NULL);
|
|
||||||
assert(pxStackBufferTemp != NULL);
|
|
||||||
//Write back pointers
|
|
||||||
*ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
|
|
||||||
*ppxTimerTaskStackBuffer = pxStackBufferTemp;
|
|
||||||
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
|
||||||
}
|
|
||||||
#endif //( configSUPPORT_STATIC_ALLOCATION == 1 )
|
|
||||||
|
|
||||||
// ------------------------ Stack --------------------------
|
// ------------------------ Stack --------------------------
|
||||||
|
|
||||||
// User exception dispatcher when exiting
|
// User exception dispatcher when exiting
|
||||||
|
@@ -95,6 +95,7 @@ void vApplicationTickHook( void )
|
|||||||
|
|
||||||
void vPortYieldOtherCore( BaseType_t coreid ) { } // trying to skip for now
|
void vPortYieldOtherCore( BaseType_t coreid ) { } // trying to skip for now
|
||||||
|
|
||||||
|
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||||
/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
|
/* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
|
||||||
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
|
* implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
|
||||||
* used by the Idle task. */
|
* used by the Idle task. */
|
||||||
@@ -120,8 +121,10 @@ void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
|
|||||||
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
|
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
|
||||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||||
}
|
}
|
||||||
|
#endif // configSUPPORT_STATIC_ALLOCATION == 1
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||||
/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
|
/* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
|
||||||
* application must provide an implementation of vApplicationGetTimerTaskMemory()
|
* application must provide an implementation of vApplicationGetTimerTaskMemory()
|
||||||
* to provide the memory that is used by the Timer service task. */
|
* to provide the memory that is used by the Timer service task. */
|
||||||
@@ -146,6 +149,7 @@ void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
|
|||||||
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
|
* configMINIMAL_STACK_SIZE is specified in words, not bytes. */
|
||||||
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
||||||
}
|
}
|
||||||
|
#endif // configSUPPORT_STATIC_ALLOCATION == 1
|
||||||
|
|
||||||
void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
void __attribute__((weak)) vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName)
|
||||||
{
|
{
|
||||||
|
@@ -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
|
||||||
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
#if CONFIG_FREERTOS_SMP // IDF-3997
|
||||||
pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
||||||
|
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
||||||
|
#else
|
||||||
|
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
||||||
|
pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_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
|
||||||
pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
|
#if CONFIG_FREERTOS_SMP // IDF-3997
|
||||||
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
||||||
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
||||||
|
#else
|
||||||
|
pxStackBufferTemp = pvPortMallocStackMem(configMINIMAL_STACK_SIZE);
|
||||||
|
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
||||||
|
#endif /* CONFIG_FREERTOS_SMP */
|
||||||
}
|
}
|
||||||
#endif /* portSTACK_GROWTH */
|
#endif /* portSTACK_GROWTH */
|
||||||
|
|
||||||
@@ -68,14 +86,6 @@ void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
|||||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
*pulIdleTaskStackSize = configMINIMAL_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,
|
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
|
||||||
StackType_t **ppxTimerTaskStackBuffer,
|
StackType_t **ppxTimerTaskStackBuffer,
|
||||||
uint32_t *pulTimerTaskStackSize )
|
uint32_t *pulTimerTaskStackSize )
|
||||||
@@ -89,14 +99,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
|
||||||
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
#if CONFIG_FREERTOS_SMP // IDF-3997
|
||||||
pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
||||||
|
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
||||||
|
#else
|
||||||
|
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
||||||
|
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
|
||||||
pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
|
#if CONFIG_FREERTOS_SMP // IDF-3997
|
||||||
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
||||||
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
||||||
|
#else
|
||||||
|
pxStackBufferTemp = pvPortMallocStackMem(configTIMER_TASK_STACK_DEPTH);
|
||||||
|
pxTCBBufferTemp = pvPortMallocTcbMem(sizeof(StaticTask_t));
|
||||||
|
#endif /* CONFIG_FREERTOS_SMP */
|
||||||
}
|
}
|
||||||
#endif /* portSTACK_GROWTH */
|
#endif /* portSTACK_GROWTH */
|
||||||
|
|
||||||
@@ -107,3 +127,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
|
Reference in New Issue
Block a user