2021-09-24 04:56:45 -04:00
|
|
|
/*
|
2021-06-07 15:54:09 -04:00
|
|
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
2021-09-24 04:56:45 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2020-11-05 23:03:21 -05:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
#include "esp_system.h"
|
2022-03-31 03:07:51 -04:00
|
|
|
#include "esp_memory_utils.h"
|
2020-11-05 23:03:21 -05:00
|
|
|
#include "sdkconfig.h"
|
2021-09-24 04:56:45 -04:00
|
|
|
|
2022-11-24 09:28:13 -05:00
|
|
|
/* ----------------------------------------- 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).
|
|
|
|
* ------------------------------------------------------------------------------------------------------------------ */
|
|
|
|
|
2021-10-15 13:08:46 -04:00
|
|
|
// ------------- FreeRTOS Static Allocation ----------------
|
|
|
|
|
|
|
|
/*
|
2022-11-24 09:28:13 -05:00
|
|
|
These function are required by FreeRTOS when configSUPPORT_STATIC_ALLOCATION is
|
|
|
|
enabled and is used by FreeRTOS to obtain memory for its IDLE/Timer tasks.
|
2021-10-15 13:08:46 -04:00
|
|
|
|
2023-03-01 06:06:10 -05:00
|
|
|
We simply allocate the IDLE/Timer tasks memory from the FreeRTOS heap.
|
2021-10-15 13:08:46 -04:00
|
|
|
*/
|
2022-11-24 09:28:13 -05:00
|
|
|
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
2021-10-15 13:08:46 -04:00
|
|
|
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
|
|
|
StackType_t **ppxIdleTaskStackBuffer,
|
|
|
|
uint32_t *pulIdleTaskStackSize )
|
|
|
|
{
|
|
|
|
StaticTask_t *pxTCBBufferTemp;
|
|
|
|
StackType_t *pxStackBufferTemp;
|
2022-05-09 06:15:38 -04:00
|
|
|
|
2023-03-01 06:06:10 -05:00
|
|
|
/* Allocate TCB and stack buffer from the FreeRTOS heap
|
|
|
|
*
|
|
|
|
* If the stack grows down then allocate the stack then the TCB so the stack
|
2022-05-09 06:15:38 -04:00
|
|
|
* does not grow into the TCB. Likewise if the stack grows up then allocate
|
|
|
|
* the TCB then the stack. */
|
|
|
|
#if (portSTACK_GROWTH > 0)
|
|
|
|
{
|
2023-03-01 06:06:10 -05:00
|
|
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
|
|
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
2022-05-09 06:15:38 -04:00
|
|
|
}
|
|
|
|
#else /* portSTACK_GROWTH */
|
|
|
|
{
|
2023-03-01 06:06:10 -05:00
|
|
|
pxStackBufferTemp = pvPortMalloc(configMINIMAL_STACK_SIZE);
|
|
|
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
2022-05-09 06:15:38 -04:00
|
|
|
}
|
|
|
|
#endif /* portSTACK_GROWTH */
|
|
|
|
|
2021-10-15 13:08:46 -04:00
|
|
|
assert(pxTCBBufferTemp != NULL);
|
|
|
|
assert(pxStackBufferTemp != NULL);
|
|
|
|
//Write back pointers
|
|
|
|
*ppxIdleTaskTCBBuffer = pxTCBBufferTemp;
|
|
|
|
*ppxIdleTaskStackBuffer = pxStackBufferTemp;
|
2022-11-03 08:56:19 -04:00
|
|
|
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
2021-10-15 13:08:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void vApplicationGetTimerTaskMemory(StaticTask_t **ppxTimerTaskTCBBuffer,
|
|
|
|
StackType_t **ppxTimerTaskStackBuffer,
|
|
|
|
uint32_t *pulTimerTaskStackSize )
|
|
|
|
{
|
|
|
|
StaticTask_t *pxTCBBufferTemp;
|
|
|
|
StackType_t *pxStackBufferTemp;
|
2022-05-09 06:15:38 -04:00
|
|
|
|
2023-03-01 06:06:10 -05:00
|
|
|
/* Allocate TCB and stack buffer from the FreeRTOS heap
|
|
|
|
*
|
|
|
|
* If the stack grows down then allocate the stack then the TCB so the stack
|
2022-05-09 06:15:38 -04:00
|
|
|
* does not grow into the TCB. Likewise if the stack grows up then allocate
|
|
|
|
* the TCB then the stack. */
|
|
|
|
#if (portSTACK_GROWTH > 0)
|
|
|
|
{
|
2023-03-01 06:06:10 -05:00
|
|
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
|
|
|
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
2022-05-09 06:15:38 -04:00
|
|
|
}
|
|
|
|
#else /* portSTACK_GROWTH */
|
|
|
|
{
|
2023-03-01 06:06:10 -05:00
|
|
|
pxStackBufferTemp = pvPortMalloc(configTIMER_TASK_STACK_DEPTH);
|
|
|
|
pxTCBBufferTemp = pvPortMalloc(sizeof(StaticTask_t));
|
2022-05-09 06:15:38 -04:00
|
|
|
}
|
|
|
|
#endif /* portSTACK_GROWTH */
|
|
|
|
|
2021-10-15 13:08:46 -04:00
|
|
|
assert(pxTCBBufferTemp != NULL);
|
|
|
|
assert(pxStackBufferTemp != NULL);
|
|
|
|
//Write back pointers
|
|
|
|
*ppxTimerTaskTCBBuffer = pxTCBBufferTemp;
|
|
|
|
*ppxTimerTaskStackBuffer = pxStackBufferTemp;
|
|
|
|
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
|
|
|
|
}
|
2022-11-24 09:28:13 -05:00
|
|
|
#endif // configSUPPORT_STATIC_ALLOCATION == 1
|