+/*-----------------------------------------------------------*/\r
+\r
+void vPortGetHeapStats( HeapStats_t *pxHeapStats )\r
+{\r
+ BlockLink_t *pxBlock;\r
+ size_t xBlocks = 0, xMaxSize = 0, xMinSize = 0;\r
+\r
+ vTaskSuspendAll();\r
+ {\r
+ pxBlock = xStart.pxNextFreeBlock;\r
+\r
+ /* pxBlock will be NULL if the heap has not been initialised. The heap\r
+ is initialised automatically when the first allocation is made. */\r
+ if( pxBlock != NULL )\r
+ {\r
+ do\r
+ {\r
+ /* Increment the number of blocks and record the largest block seen\r
+ so far. */\r
+ xBlocks++;\r
+\r
+ if( pxBlock->xBlockSize > xMaxSize )\r
+ {\r
+ xMaxSize = pxBlock->xBlockSize;\r
+ }\r
+\r
+ if( pxBlock->xBlockSize < xMinSize )\r
+ {\r
+ xMinSize = pxBlock->xBlockSize;\r
+ }\r
+\r
+ /* Move to the next block in the chain until the last block is\r
+ reached. */\r
+ pxBlock = pxBlock->pxNextFreeBlock;\r
+ } while( pxBlock != pxEnd );\r
+ }\r
+ }\r
+ xTaskResumeAll();\r
+\r
+ pxHeapStats->xSizeOfLargestFreeBlockInBytes = xMaxSize;\r
+ pxHeapStats->xSizeOfSmallestFreeBlockInBytes = xMinSize;\r
+ pxHeapStats->xNumberOfFreeBlocks = xBlocks;\r
+\r
+ taskENTER_CRITICAL();\r
+ {\r
+ pxHeapStats->xAvailableHeapSpaceInBytes = xFreeBytesRemaining;\r
+ pxHeapStats->xNumberOfSuccessfulAllocations = xNumberOfSuccessfulAllocations;\r
+ pxHeapStats->xNumberOfSuccessfulFrees = xNumberOfSuccessfulFrees;\r
+ pxHeapStats->xMinimumEverFreeBytesRemaining = xMinimumEverFreeBytesRemaining;\r
+ }\r
+ taskEXIT_CRITICAL();\r
+}\r