]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/MemMang/heap_5.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / portable / MemMang / heap_5.c
index c01205e878fad7d057f1df984ad03e5aed724aef..a2dcd1fb3e15ca60c69d638641ce94fe45ddabd6 100644 (file)
@@ -1,60 +1,64 @@
 /*\r
-    FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+    FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
     All rights reserved\r
 \r
     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
 \r
-    ***************************************************************************\r
-     *                                                                       *\r
-     *    FreeRTOS provides completely free yet professionally developed,    *\r
-     *    robust, strictly quality controlled, supported, and cross          *\r
-     *    platform software that has become a de facto standard.             *\r
-     *                                                                       *\r
-     *    Help yourself get started quickly and support the FreeRTOS         *\r
-     *    project by purchasing a FreeRTOS tutorial book, reference          *\r
-     *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
-     *                                                                       *\r
-     *    Thank you!                                                         *\r
-     *                                                                       *\r
-    ***************************************************************************\r
-\r
     This file is part of the FreeRTOS distribution.\r
 \r
     FreeRTOS is free software; you can redistribute it and/or modify it under\r
     the terms of the GNU General Public License (version 2) as published by the\r
-    Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
+    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
 \r
+    ***************************************************************************\r
     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
     >>!   obliged to provide the source code for proprietary components     !<<\r
     >>!   outside of the FreeRTOS kernel.                                   !<<\r
+    ***************************************************************************\r
 \r
     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
-    FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
+    FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
     link: http://www.freertos.org/a00114.html\r
 \r
-    1 tab == 4 spaces!\r
-\r
     ***************************************************************************\r
      *                                                                       *\r
-     *    Having a problem?  Start by reading the FAQ "My application does   *\r
-     *    not run, what could be wrong?"                                     *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
      *                                                                       *\r
-     *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
      *                                                                       *\r
     ***************************************************************************\r
 \r
-    http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
-    license and Real Time Engineers Ltd. contact details.\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
 \r
     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
 \r
-    http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
-    Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
-    licenses offer ticketed support, indemnification and middleware.\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\r
 \r
     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
     engineered and independently SIL3 certified version for use in safety and\r
@@ -95,8 +99,8 @@
  *\r
  * HeapRegion_t xHeapRegions[] =\r
  * {\r
- *     { 0x80000000UL, 0x10000 }, << Defines a block of 0x10000 bytes starting at address 0x80000000\r
- *     { 0x90000000UL, 0xa0000 }, << Defines a block of 0xa0000 bytes starting at address of 0x90000000\r
+ *     { ( uint8_t * ) 0x80000000UL, 0x10000 }, << Defines a block of 0x10000 bytes starting at address 0x80000000\r
+ *     { ( uint8_t * ) 0x90000000UL, 0xa0000 }, << Defines a block of 0xa0000 bytes starting at address of 0x90000000\r
  *     { NULL, 0 }                << Terminates the array.\r
  * };\r
  *\r
@@ -117,8 +121,12 @@ task.h is included from an application file. */
 \r
 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
 \r
+#if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )\r
+       #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0\r
+#endif\r
+\r
 /* Block sizes must not get too small. */\r
-#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( uxHeapStructSize << 1 ) )\r
+#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize << 1 ) )\r
 \r
 /* Assumes 8bit bytes! */\r
 #define heapBITS_PER_BYTE              ( ( size_t ) 8 )\r
@@ -145,15 +153,15 @@ static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert );
 \r
 /* The size of the structure placed at the beginning of each allocated memory\r
 block must by correctly byte aligned. */\r
-static const uint32_t uxHeapStructSize = ( ( sizeof ( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK );\r
+static const size_t xHeapStructSize    = ( sizeof( BlockLink_t ) + ( ( size_t ) ( portBYTE_ALIGNMENT - 1 ) ) ) & ~( ( size_t ) portBYTE_ALIGNMENT_MASK );\r
 \r
 /* Create a couple of list links to mark the start and end of the list. */\r
 static BlockLink_t xStart, *pxEnd = NULL;\r
 \r
 /* Keeps track of the number of free bytes remaining, but says nothing about\r
 fragmentation. */\r
-static size_t xFreeBytesRemaining = 0;\r
-static size_t xMinimumEverFreeBytesRemaining = 0;\r
+static size_t xFreeBytesRemaining = 0U;\r
+static size_t xMinimumEverFreeBytesRemaining = 0U;\r
 \r
 /* Gets set to the top bit of an size_t type.  When this bit in the xBlockSize\r
 member of an BlockLink_t structure is set then the block belongs to the\r
@@ -184,7 +192,7 @@ void *pvReturn = NULL;
                        structure in addition to the requested amount of bytes. */\r
                        if( xWantedSize > 0 )\r
                        {\r
-                               xWantedSize += uxHeapStructSize;\r
+                               xWantedSize += xHeapStructSize;\r
 \r
                                /* Ensure that blocks are always aligned to the required number\r
                                of bytes. */\r
@@ -221,7 +229,7 @@ void *pvReturn = NULL;
                                {\r
                                        /* Return the memory space pointed to - jumping over the\r
                                        BlockLink_t structure at its start. */\r
-                                       pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + uxHeapStructSize );\r
+                                       pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + xHeapStructSize );\r
 \r
                                        /* This block is being returned for use so must be taken out\r
                                        of the list of free blocks. */\r
@@ -312,7 +320,7 @@ BlockLink_t *pxLink;
        {\r
                /* The memory being freed will have an BlockLink_t structure immediately\r
                before it. */\r
-               puc -= uxHeapStructSize;\r
+               puc -= xHeapStructSize;\r
 \r
                /* This casting is to keep the compiler from issuing warnings. */\r
                pxLink = ( void * ) puc;\r
@@ -424,14 +432,14 @@ uint8_t *puc;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vPortDefineHeapRegions( HeapRegion_t *pxHeapRegions )\r
+void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions )\r
 {\r
 BlockLink_t *pxFirstFreeBlockInRegion = NULL, *pxPreviousFreeBlock;\r
-uint8_t *pucAlignedHeap;\r
+size_t xAlignedHeap;\r
 size_t xTotalRegionSize, xTotalHeapSize = 0;\r
 BaseType_t xDefinedRegions = 0;\r
-uint32_t ulAddress;\r
-HeapRegion_t *pxHeapRegion;\r
+size_t xAddress;\r
+const HeapRegion_t *pxHeapRegion;\r
 \r
        /* Can only call once! */\r
        configASSERT( pxEnd == NULL );\r
@@ -443,24 +451,24 @@ HeapRegion_t *pxHeapRegion;
                xTotalRegionSize = pxHeapRegion->xSizeInBytes;\r
 \r
                /* Ensure the heap region starts on a correctly aligned boundary. */\r
-               ulAddress = ( uint32_t ) pxHeapRegion->pucStartAddress;\r
-               if( ( ulAddress & portBYTE_ALIGNMENT_MASK ) != 0 )\r
+               xAddress = ( size_t ) pxHeapRegion->pucStartAddress;\r
+               if( ( xAddress & portBYTE_ALIGNMENT_MASK ) != 0 )\r
                {\r
-                       ulAddress += ( portBYTE_ALIGNMENT - 1 );\r
-                       ulAddress &= ~portBYTE_ALIGNMENT_MASK;\r
+                       xAddress += ( portBYTE_ALIGNMENT - 1 );\r
+                       xAddress &= ~portBYTE_ALIGNMENT_MASK;\r
 \r
                        /* Adjust the size for the bytes lost to alignment. */\r
-                       xTotalRegionSize -= ulAddress - ( uint32_t ) pxHeapRegion->pucStartAddress;\r
+                       xTotalRegionSize -= xAddress - ( size_t ) pxHeapRegion->pucStartAddress;\r
                }\r
 \r
-               pucAlignedHeap = ( uint8_t * ) ulAddress;\r
+               xAlignedHeap = xAddress;\r
 \r
                /* Set xStart if it has not already been set. */\r
                if( xDefinedRegions == 0 )\r
                {\r
                        /* xStart is used to hold a pointer to the first item in the list of\r
                        free blocks.  The void cast is used to prevent compiler warnings. */\r
-                       xStart.pxNextFreeBlock = ( BlockLink_t * ) pucAlignedHeap;\r
+                       xStart.pxNextFreeBlock = ( BlockLink_t * ) xAlignedHeap;\r
                        xStart.xBlockSize = ( size_t ) 0;\r
                }\r
                else\r
@@ -470,7 +478,7 @@ HeapRegion_t *pxHeapRegion;
                        configASSERT( pxEnd != NULL );\r
 \r
                        /* Check blocks are passed in with increasing start addresses. */\r
-                       configASSERT( ulAddress > ( uint32_t ) pxEnd );\r
+                       configASSERT( xAddress > ( size_t ) pxEnd );\r
                }\r
 \r
                /* Remember the location of the end marker in the previous region, if\r
@@ -479,18 +487,18 @@ HeapRegion_t *pxHeapRegion;
 \r
                /* pxEnd is used to mark the end of the list of free blocks and is\r
                inserted at the end of the region space. */\r
-               ulAddress = ( ( uint32_t ) pucAlignedHeap ) + xTotalRegionSize;\r
-               ulAddress -= uxHeapStructSize;\r
-               ulAddress &= ~portBYTE_ALIGNMENT_MASK;\r
-               pxEnd = ( BlockLink_t * ) ulAddress;\r
+               xAddress = xAlignedHeap + xTotalRegionSize;\r
+               xAddress -= xHeapStructSize;\r
+               xAddress &= ~portBYTE_ALIGNMENT_MASK;\r
+               pxEnd = ( BlockLink_t * ) xAddress;\r
                pxEnd->xBlockSize = 0;\r
                pxEnd->pxNextFreeBlock = NULL;\r
 \r
                /* To start with there is a single free block in this region that is\r
                sized to take up the entire heap region minus the space taken by the\r
                free block structure. */\r
-               pxFirstFreeBlockInRegion = ( BlockLink_t * ) pucAlignedHeap;\r
-               pxFirstFreeBlockInRegion->xBlockSize = ulAddress - ( uint32_t ) pxFirstFreeBlockInRegion;\r
+               pxFirstFreeBlockInRegion = ( BlockLink_t * ) xAlignedHeap;\r
+               pxFirstFreeBlockInRegion->xBlockSize = xAddress - ( size_t ) pxFirstFreeBlockInRegion;\r
                pxFirstFreeBlockInRegion->pxNextFreeBlock = pxEnd;\r
 \r
                /* If this is not the first region that makes up the entire heap space\r