2 FreeRTOS.org V4.1.2 - Copyright (C) 2003-2006 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
36 * The simplest possible implementation of pvPortMalloc(). Note that this
\r
37 * implementation does NOT allow allocated memory to be freed again.
\r
39 * See heap_2.c and heap_3.c for alternative implementations, and the memory
\r
40 * management pages of http://www.FreeRTOS.org for more information.
\r
43 #include "FreeRTOS.h"
\r
46 /* Setup the correct byte alignment mask for the defined byte alignment. */
\r
47 #if portBYTE_ALIGNMENT == 4
\r
48 #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0003 )
\r
51 #if portBYTE_ALIGNMENT == 2
\r
52 #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0001 )
\r
55 #if portBYTE_ALIGNMENT == 1
\r
56 #define heapBYTE_ALIGNMENT_MASK ( ( size_t ) 0x0000 )
\r
59 #ifndef heapBYTE_ALIGNMENT_MASK
\r
60 #error "Invalid portBYTE_ALIGNMENT definition"
\r
63 /* Allocate the memory for the heap. The struct is used to force byte
\r
64 alignment without using any non-portable code. */
\r
65 extern struct xRTOS_HEAP
\r
67 unsigned portLONG ulDummy;
\r
68 unsigned portCHAR ucHeap[ configTOTAL_HEAP_SIZE ];
\r
71 static size_t xNextFreeByte = ( size_t ) 0;
\r
72 /*-----------------------------------------------------------*/
\r
74 void *pvPortMalloc( size_t xWantedSize )
\r
76 void *pvReturn = NULL;
\r
78 /* Ensure that blocks are always aligned to the required number of bytes. */
\r
79 #if portBYTE_ALIGNMENT != 1
\r
80 if( xWantedSize & heapBYTE_ALIGNMENT_MASK )
\r
82 /* Byte alignment required. */
\r
83 xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & heapBYTE_ALIGNMENT_MASK ) );
\r
89 /* Check there is enough room left for the allocation. */
\r
90 if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) &&
\r
91 ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */
\r
93 /* Return the next free byte then increment the index past this
\r
95 pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] );
\r
96 xNextFreeByte += xWantedSize;
\r
103 /*-----------------------------------------------------------*/
\r
105 void vPortFree( void *pv )
\r
107 /* Memory cannot be freed using this scheme. See heap_2.c and heap_3.c
\r
108 for alternative implementations, and the memory management pages of
\r
109 http://www.FreeRTOS.org for more information. */
\r
112 /*-----------------------------------------------------------*/
\r
114 void vPortInitialiseBlocks( void )
\r
116 /* Only required when static memory is not cleared. */
\r
117 xNextFreeByte = ( size_t ) 0;
\r