/*\r
- FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+ FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
All rights reserved\r
\r
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\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
\r
- >>! NOTE: The modification to the GPL is included to allow you to distribute\r
- >>! a combined work that includes FreeRTOS without being obliged to provide\r
- >>! the source code for proprietary components outside of the FreeRTOS\r
- >>! kernel.\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
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
#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE\r
\r
/* Block sizes must not get too small. */\r
-#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( heapSTRUCT_SIZE * 2 ) )\r
+#define heapMINIMUM_BLOCK_SIZE ( ( size_t ) ( xHeapStructSize * 2 ) )\r
\r
/* Assumes 8bit bytes! */\r
#define heapBITS_PER_BYTE ( ( size_t ) 8 )\r
\r
-/* A few bytes might be lost to byte aligning the heap start address. */\r
-#define heapADJUSTED_HEAP_SIZE ( configTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT )\r
-\r
/* Allocate the memory for the heap. */\r
static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];\r
\r
\r
/* The size of the structure placed at the beginning of each allocated memory\r
block must by correctly byte aligned. */\r
-static const uint16_t heapSTRUCT_SIZE = ( ( sizeof ( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~portBYTE_ALIGNMENT_MASK );\r
-\r
-/* Ensure the pxEnd pointer will end up on the correct byte alignment. */\r
-static const size_t xTotalHeapSize = ( ( size_t ) heapADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK );\r
+static const size_t xHeapStructSize = ( ( sizeof( BlockLink_t ) + ( portBYTE_ALIGNMENT - 1 ) ) & ~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 = ( ( size_t ) heapADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK );\r
-static size_t xMinimumEverFreeBytesRemaining = ( ( size_t ) heapADJUSTED_HEAP_SIZE ) & ( ( size_t ) ~portBYTE_ALIGNMENT_MASK );\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
structure in addition to the requested amount of bytes. */\r
if( xWantedSize > 0 )\r
{\r
- xWantedSize += heapSTRUCT_SIZE;\r
+ xWantedSize += xHeapStructSize;\r
\r
/* Ensure that blocks are always aligned to the required number\r
of bytes. */\r
{\r
/* Byte alignment required. */\r
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );\r
+ configASSERT( ( xWantedSize & portBYTE_ALIGNMENT_MASK ) == 0 );\r
}\r
else\r
{\r
{\r
/* Return the memory space pointed to - jumping over the\r
BlockLink_t structure at its start. */\r
- pvReturn = ( void * ) ( ( ( uint8_t * ) pxPreviousBlock->pxNextFreeBlock ) + heapSTRUCT_SIZE );\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
cast is used to prevent byte alignment warnings from the\r
compiler. */\r
pxNewBlockLink = ( void * ) ( ( ( uint8_t * ) pxBlock ) + xWantedSize );\r
+ configASSERT( ( ( ( uint32_t ) pxNewBlockLink ) & portBYTE_ALIGNMENT_MASK ) == 0 );\r
\r
/* Calculate the sizes of two blocks split from the\r
single block. */\r
\r
traceMALLOC( pvReturn, xWantedSize );\r
}\r
- xTaskResumeAll();\r
+ ( void ) xTaskResumeAll();\r
\r
#if( configUSE_MALLOC_FAILED_HOOK == 1 )\r
{\r
}\r
#endif\r
\r
+ configASSERT( ( ( ( uint32_t ) pvReturn ) & portBYTE_ALIGNMENT_MASK ) == 0 );\r
return pvReturn;\r
}\r
/*-----------------------------------------------------------*/\r
{\r
/* The memory being freed will have an BlockLink_t structure immediately\r
before it. */\r
- puc -= heapSTRUCT_SIZE;\r
+ puc -= xHeapStructSize;\r
\r
/* This casting is to keep the compiler from issuing warnings. */\r
pxLink = ( void * ) puc;\r
{\r
/* Add this block to the list of free blocks. */\r
xFreeBytesRemaining += pxLink->xBlockSize;\r
- prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );\r
traceFREE( pv, pxLink->xBlockSize );\r
+ prvInsertBlockIntoFreeList( ( ( BlockLink_t * ) pxLink ) );\r
}\r
- xTaskResumeAll();\r
+ ( void ) xTaskResumeAll();\r
}\r
else\r
{\r
static void prvHeapInit( void )\r
{\r
BlockLink_t *pxFirstFreeBlock;\r
-uint8_t *pucHeapEnd, *pucAlignedHeap;\r
+uint8_t *pucAlignedHeap;\r
+uint32_t ulAddress;\r
+size_t xTotalHeapSize = configTOTAL_HEAP_SIZE;\r
\r
/* Ensure the heap starts on a correctly aligned boundary. */\r
- pucAlignedHeap = ( uint8_t * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) );\r
+ ulAddress = ( uint32_t ) ucHeap;\r
+\r
+ if( ( ulAddress & portBYTE_ALIGNMENT_MASK ) != 0 )\r
+ {\r
+ ulAddress += ( portBYTE_ALIGNMENT - 1 );\r
+ ulAddress &= ~portBYTE_ALIGNMENT_MASK;\r
+ xTotalHeapSize -= ulAddress - ( uint32_t ) ucHeap;\r
+ }\r
+\r
+ pucAlignedHeap = ( uint8_t * ) ulAddress;\r
\r
/* xStart is used to hold a pointer to the first item in the list of free\r
blocks. The void cast is used to prevent compiler warnings. */\r
\r
/* pxEnd is used to mark the end of the list of free blocks and is inserted\r
at the end of the heap space. */\r
- pucHeapEnd = pucAlignedHeap + xTotalHeapSize;\r
- pucHeapEnd -= heapSTRUCT_SIZE;\r
- pxEnd = ( void * ) pucHeapEnd;\r
- configASSERT( ( ( ( uint32_t ) pxEnd ) & ( ( uint32_t ) portBYTE_ALIGNMENT_MASK ) ) == 0UL );\r
+ ulAddress = ( ( uint32_t ) pucAlignedHeap ) + xTotalHeapSize;\r
+ ulAddress -= xHeapStructSize;\r
+ ulAddress &= ~portBYTE_ALIGNMENT_MASK;\r
+ pxEnd = ( void * ) ulAddress;\r
pxEnd->xBlockSize = 0;\r
pxEnd->pxNextFreeBlock = NULL;\r
\r
/* To start with there is a single free block that is sized to take up the\r
entire heap space, minus the space taken by pxEnd. */\r
pxFirstFreeBlock = ( void * ) pucAlignedHeap;\r
- pxFirstFreeBlock->xBlockSize = xTotalHeapSize - heapSTRUCT_SIZE;\r
+ pxFirstFreeBlock->xBlockSize = ulAddress - ( uint32_t ) pxFirstFreeBlock;\r
pxFirstFreeBlock->pxNextFreeBlock = pxEnd;\r
\r
- /* The heap now contains pxEnd. */\r
- xFreeBytesRemaining -= heapSTRUCT_SIZE;\r
+ /* Only one block exists - and it covers the entire usable heap space. */\r
+ xMinimumEverFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;\r
+ xFreeBytesRemaining = pxFirstFreeBlock->xBlockSize;\r
\r
/* Work out the position of the top bit in a size_t variable. */\r
xBlockAllocatedBit = ( ( size_t ) 1 ) << ( ( sizeof( size_t ) * heapBITS_PER_BYTE ) - 1 );\r