@@ -60,15 +60,6 @@ task.h is included from an application file. */
6060/* Assumes 8bit bytes! */
6161#define heapBITS_PER_BYTE ( ( size_t ) 8 )
6262
63- /* Allocate the memory for the heap. */
64- #if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
65- /* The application writer has already defined the array used for the RTOS
66- heap - probably so it can be placed in a special segment or address. */
67- extern uint8_t ucHeap [ configTOTAL_HEAP_SIZE ];
68- #else
69- static uint8_t ucHeap [ configTOTAL_HEAP_SIZE ];
70- #endif /* configAPPLICATION_ALLOCATED_HEAP */
71-
7263/* Define the linked list structure. This is used to link free blocks in order
7364of their memory address. */
7465typedef struct A_BLOCK_LINK
@@ -113,6 +104,8 @@ application. When the bit is free the block is still part of the free heap
113104space. */
114105static size_t xBlockAllocatedBit = 0 ;
115106
107+ static size_t xHeapSize = 0 ;
108+
116109/*-----------------------------------------------------------*/
117110
118111void * pvPortMalloc ( size_t xWantedSize )
@@ -332,27 +325,38 @@ size_t xPortGetMinimumEverFreeHeapSize( void )
332325}
333326/*-----------------------------------------------------------*/
334327
328+ size_t xPortGetHeapSize ( void )
329+ {
330+ return xHeapSize ;
331+ }
332+ /*-----------------------------------------------------------*/
333+
335334void vPortInitialiseBlocks ( void )
336335{
337336 /* This just exists to keep the linker quiet. */
338337}
339338/*-----------------------------------------------------------*/
340339
340+ extern uint8_t * __HeapLimit ; // Defined by nrf_common.ld
341+
341342static void prvHeapInit ( void )
342343{
343344 BlockLink_t * pxFirstFreeBlock ;
344345 uint8_t * pucAlignedHeap ;
345346 size_t uxAddress ;
346- size_t xTotalHeapSize = configTOTAL_HEAP_SIZE ;
347+ size_t xTotalHeapSize = ( size_t ) & __StackLimit - ( size_t ) & __HeapLimit ;
348+ uint8_t * pucHeap = ( uint8_t * ) & __HeapLimit ;
349+
350+ xHeapSize = xTotalHeapSize ;
347351
348352 /* Ensure the heap starts on a correctly aligned boundary. */
349- uxAddress = ( size_t ) ucHeap ;
353+ uxAddress = ( size_t ) pucHeap ;
350354
351355 if ( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
352356 {
353357 uxAddress += ( portBYTE_ALIGNMENT - 1 );
354358 uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
355- xTotalHeapSize -= uxAddress - ( size_t ) ucHeap ;
359+ xTotalHeapSize -= uxAddress - ( size_t ) pucHeap ;
356360 }
357361
358362 pucAlignedHeap = ( uint8_t * ) uxAddress ;
0 commit comments