@@ -60,15 +60,6 @@ task.h is included from an application file. */
60
60
/* Assumes 8bit bytes! */
61
61
#define heapBITS_PER_BYTE ( ( size_t ) 8 )
62
62
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
-
72
63
/* Define the linked list structure. This is used to link free blocks in order
73
64
of their memory address. */
74
65
typedef struct A_BLOCK_LINK
@@ -113,6 +104,8 @@ application. When the bit is free the block is still part of the free heap
113
104
space. */
114
105
static size_t xBlockAllocatedBit = 0 ;
115
106
107
+ static size_t xHeapSize = 0 ;
108
+
116
109
/*-----------------------------------------------------------*/
117
110
118
111
void * pvPortMalloc ( size_t xWantedSize )
@@ -332,27 +325,38 @@ size_t xPortGetMinimumEverFreeHeapSize( void )
332
325
}
333
326
/*-----------------------------------------------------------*/
334
327
328
+ size_t xPortGetHeapSize ( void )
329
+ {
330
+ return xHeapSize ;
331
+ }
332
+ /*-----------------------------------------------------------*/
333
+
335
334
void vPortInitialiseBlocks ( void )
336
335
{
337
336
/* This just exists to keep the linker quiet. */
338
337
}
339
338
/*-----------------------------------------------------------*/
340
339
340
+ extern uint8_t * __HeapLimit ; // Defined by nrf_common.ld
341
+
341
342
static void prvHeapInit ( void )
342
343
{
343
344
BlockLink_t * pxFirstFreeBlock ;
344
345
uint8_t * pucAlignedHeap ;
345
346
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 ;
347
351
348
352
/* Ensure the heap starts on a correctly aligned boundary. */
349
- uxAddress = ( size_t ) ucHeap ;
353
+ uxAddress = ( size_t ) pucHeap ;
350
354
351
355
if ( ( uxAddress & portBYTE_ALIGNMENT_MASK ) != 0 )
352
356
{
353
357
uxAddress += ( portBYTE_ALIGNMENT - 1 );
354
358
uxAddress &= ~( ( size_t ) portBYTE_ALIGNMENT_MASK );
355
- xTotalHeapSize -= uxAddress - ( size_t ) ucHeap ;
359
+ xTotalHeapSize -= uxAddress - ( size_t ) pucHeap ;
356
360
}
357
361
358
362
pucAlignedHeap = ( uint8_t * ) uxAddress ;
0 commit comments