]> git.sur5r.net Git - freertos/blobdiff - Source/portable/MemMang/heap_2.c
Add xPortGetFreeHeapSize() function.
[freertos] / Source / portable / MemMang / heap_2.c
index e1f22dcaaf1ab124026e9af53b835bfdcb4b4702..1f81a08a5b3b7e2da937d7d2ae3871d7c14cb324 100644 (file)
@@ -93,6 +93,10 @@ static const unsigned short  heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE
 /* Create a couple of list links to mark the start and end of the list. */\r
 static xBlockLink xStart, xEnd;\r
 \r
+/* Keeps track of the number of free bytes remaining, but says nothing about\r
+fragmentation. */\r
+static size_t xFreeBytesRemaining = configTOTAL_HEAP_SIZE;\r
+\r
 /* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */\r
 \r
 /*\r
@@ -211,6 +215,8 @@ void *pvReturn = NULL;
                                        /* Insert the new block into the list of free blocks. */\r
                                        prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );\r
                                }\r
+                               \r
+                               xFreeBytesRemaining -= xWantedSize;\r
                        }\r
                }\r
        }\r
@@ -248,9 +254,16 @@ xBlockLink *pxLink;
                {\r
                        /* Add this block to the list of free blocks. */\r
                        prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );\r
+                       xFreeBytesRemaining += pxLink->xBlockSize;\r
                }\r
                xTaskResumeAll();\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+size_t xPortGetFreeHeapSize( void )\r
+{\r
+       return xFreeBytesRemaining;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r