diff options
| author | Felipe MartÃnez <felipe@pipe01.net> | 2024-12-09 01:10:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-09 00:10:09 +0000 |
| commit | b8c51abe691a2d0f6770f4bfef3574541f49d744 (patch) | |
| tree | 0e501734fed33451789943e30aad9be23d8eb3c6 /src/FreeRTOS | |
| parent | 2105a7b63da8d4065ebfc62e0057f225358eedfc (diff) | |
Use all free RAM for FreeRTOS heap
* Use all free RAM for FreeRTOS heap
* Wrap newlib malloc and related functions
* Implement calloc
Diffstat (limited to 'src/FreeRTOS')
| -rw-r--r-- | src/FreeRTOS/heap_4_infinitime.c | 28 | ||||
| -rw-r--r-- | src/FreeRTOS/portmacro_cmsis.h | 1 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/FreeRTOS/heap_4_infinitime.c b/src/FreeRTOS/heap_4_infinitime.c index 14708471..bf649254 100644 --- a/src/FreeRTOS/heap_4_infinitime.c +++ b/src/FreeRTOS/heap_4_infinitime.c @@ -60,15 +60,6 @@ task.h is included from an application file. */ /* Assumes 8bit bytes! */ #define heapBITS_PER_BYTE ( ( size_t ) 8 ) -/* Allocate the memory for the heap. */ -#if( configAPPLICATION_ALLOCATED_HEAP == 1 ) -/* The application writer has already defined the array used for the RTOS -heap - probably so it can be placed in a special segment or address. */ -extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; -#else -static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ]; -#endif /* configAPPLICATION_ALLOCATED_HEAP */ - /* Define the linked list structure. This is used to link free blocks in order of their memory address. */ typedef struct A_BLOCK_LINK @@ -113,6 +104,8 @@ application. When the bit is free the block is still part of the free heap space. */ static size_t xBlockAllocatedBit = 0; +static size_t xHeapSize = 0; + /*-----------------------------------------------------------*/ void *pvPortMalloc( size_t xWantedSize ) @@ -332,27 +325,38 @@ size_t xPortGetMinimumEverFreeHeapSize( void ) } /*-----------------------------------------------------------*/ +size_t xPortGetHeapSize( void ) +{ + return xHeapSize; +} +/*-----------------------------------------------------------*/ + void vPortInitialiseBlocks( void ) { /* This just exists to keep the linker quiet. */ } /*-----------------------------------------------------------*/ +extern uint8_t *__HeapLimit; // Defined by nrf_common.ld + static void prvHeapInit( void ) { BlockLink_t *pxFirstFreeBlock; uint8_t *pucAlignedHeap; size_t uxAddress; - size_t xTotalHeapSize = configTOTAL_HEAP_SIZE; + size_t xTotalHeapSize = ( size_t ) &__StackLimit - ( size_t ) &__HeapLimit; + uint8_t *pucHeap = ( uint8_t * ) &__HeapLimit; + + xHeapSize = xTotalHeapSize; /* Ensure the heap starts on a correctly aligned boundary. */ - uxAddress = ( size_t ) ucHeap; + uxAddress = ( size_t ) pucHeap; if( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 ) { uxAddress += ( portBYTE_ALIGNMENT - 1 ); uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK ); - xTotalHeapSize -= uxAddress - ( size_t ) ucHeap; + xTotalHeapSize -= uxAddress - ( size_t ) pucHeap; } pucAlignedHeap = ( uint8_t * ) uxAddress; diff --git a/src/FreeRTOS/portmacro_cmsis.h b/src/FreeRTOS/portmacro_cmsis.h index e6e09158..d165d171 100644 --- a/src/FreeRTOS/portmacro_cmsis.h +++ b/src/FreeRTOS/portmacro_cmsis.h @@ -180,6 +180,7 @@ __STATIC_INLINE uint32_t ulPortRaiseBASEPRI( void ) /*-----------------------------------------------------------*/ +size_t xPortGetHeapSize(void); #ifdef __cplusplus } |
