]> git.sur5r.net Git - freertos/commitdiff
Add xPortGetFreeHeapSize() function.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 5 Oct 2009 11:16:38 +0000 (11:16 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 5 Oct 2009 11:16:38 +0000 (11:16 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@907 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

Source/include/mpu_wrappers.h
Source/include/portable.h
Source/portable/GCC/ARM_CM3_MPU/port.c
Source/portable/MemMang/heap_1.c
Source/portable/MemMang/heap_2.c

index e6621330d0ad60aaa709873dd8872368744a42e9..49bf7a183ef43a41a526475405193367e29ab979 100644 (file)
@@ -99,6 +99,8 @@ only for ports that are using the MPU. */
 \r
                #define pvPortMalloc                                    MPU_pvPortMalloc\r
                #define vPortFree                                               MPU_vPortFree\r
+               #define xPortGetFreeHeapSize                    MPU_xPortGetFreeHeapSize\r
+               #define vPortInitialiseBlocks                   MPU_vPortInitialiseBlocks\r
 \r
                /* Remove the privileged function macro. */\r
                #define PRIVILEGED_FUNCTION\r
index 67275c8ad7dffb14d2ad5675b38cf29b963762d2..369573b170187d427ca61e45da137eba22448f07 100644 (file)
@@ -350,6 +350,7 @@ extern "C" {
 void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;\r
 void vPortFree( void *pv ) PRIVILEGED_FUNCTION;\r
 void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;\r
+size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Setup the hardware ready for the scheduler to take control.  This generally\r
index 731dd1583a45bf440eb5cfe9058a828eb5252bf1..155eb2708e33bd5b0ff66a0d8c373feeb59a7ec4 100644 (file)
@@ -1025,3 +1025,27 @@ portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
 \r
        portRESET_PRIVILEGE( xRunningPrivileged );\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+void MPU_vPortInitialiseBlocks( void )\r
+{\r
+portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();\r
+\r
+       vPortInitialiseBlocks();\r
+\r
+       portRESET_PRIVILEGE( xRunningPrivileged );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+size_t MPU_xPortGetFreeHeapSize( void )\r
+{\r
+size_t xReturn;\r
+portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();\r
+\r
+       xReturn = xPortGetFreeHeapSize();\r
+\r
+       portRESET_PRIVILEGE( xRunningPrivileged );\r
+       \r
+       return xReturn;\r
+}\r
+\r
index 27582c17f9eea03f33f64c737b4f8d476784472d..f81ce116eb3d8374a8b8d3cd13f4394449556b5a 100644 (file)
@@ -136,5 +136,12 @@ void vPortInitialiseBlocks( void )
        /* Only required when static memory is not cleared. */\r
        xNextFreeByte = ( size_t ) 0;\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+size_t xPortGetFreeHeapSize( void )\r
+{\r
+       return ( configTOTAL_HEAP_SIZE - xNextFreeByte );\r
+}\r
+\r
 \r
 \r
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