FreeRTOS Real Time Operating System, Modified from Kenji Arai's initial port. See freertos.org for full documentation.
Fork of FreeRTOS_on_mbed_v1 by
heap_1.c
00001 /* 00002 FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd. 00003 00004 *************************************************************************** 00005 * * 00006 * If you are: * 00007 * * 00008 * + New to FreeRTOS, * 00009 * + Wanting to learn FreeRTOS or multitasking in general quickly * 00010 * + Looking for basic training, * 00011 * + Wanting to improve your FreeRTOS skills and productivity * 00012 * * 00013 * then take a look at the FreeRTOS eBook * 00014 * * 00015 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * 00016 * http://www.FreeRTOS.org/Documentation * 00017 * * 00018 * A pdf reference manual is also available. Both are usually delivered * 00019 * to your inbox within 20 minutes to two hours when purchased between 8am * 00020 * and 8pm GMT (although please allow up to 24 hours in case of * 00021 * exceptional circumstances). Thank you for your support! * 00022 * * 00023 *************************************************************************** 00024 00025 This file is part of the FreeRTOS distribution. 00026 00027 FreeRTOS is free software; you can redistribute it and/or modify it under 00028 the terms of the GNU General Public License (version 2) as published by the 00029 Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 00030 ***NOTE*** The exception to the GPL is included to allow you to distribute 00031 a combined work that includes FreeRTOS without being obliged to provide the 00032 source code for proprietary components outside of the FreeRTOS kernel. 00033 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 00034 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00035 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00036 more details. You should have received a copy of the GNU General Public 00037 License and the FreeRTOS license exception along with FreeRTOS; if not it 00038 can be viewed here: http://www.freertos.org/a00114.html and also obtained 00039 by writing to Richard Barry, contact details for whom are available on the 00040 FreeRTOS WEB site. 00041 00042 1 tab == 4 spaces! 00043 00044 http://www.FreeRTOS.org - Documentation, latest information, license and 00045 contact details. 00046 00047 http://www.SafeRTOS.com - A version that is certified for use in safety 00048 critical systems. 00049 00050 http://www.OpenRTOS.com - Commercial support, development, porting, 00051 licensing and training services. 00052 */ 00053 00054 00055 /* 00056 * The simplest possible implementation of pvPortMalloc(). Note that this 00057 * implementation does NOT allow allocated memory to be freed again. 00058 * 00059 * See heap_2.c and heap_3.c for alternative implementations, and the memory 00060 * management pages of http://www.FreeRTOS.org for more information. 00061 */ 00062 00063 #include <stdlib.h> 00064 00065 /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining 00066 all the API functions to use the MPU wrappers. That should only be done when 00067 task.h is included from an application file. */ 00068 #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE 00069 00070 #include "FreeRTOS.h" 00071 #include "task.h" 00072 00073 #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE 00074 00075 /* Allocate the memory for the heap. The struct is used to force byte 00076 alignment without using any non-portable code. */ 00077 static union xRTOS_HEAP 00078 { 00079 #if portBYTE_ALIGNMENT == 8 00080 volatile portDOUBLE dDummy; 00081 #else 00082 volatile unsigned long ulDummy; 00083 #endif 00084 unsigned char ucHeap[ configTOTAL_HEAP_SIZE ]; 00085 } xHeap; 00086 00087 static size_t xNextFreeByte = ( size_t ) 0; 00088 /*-----------------------------------------------------------*/ 00089 00090 void *pvPortMalloc( size_t xWantedSize ) 00091 { 00092 void *pvReturn = NULL; 00093 00094 /* Ensure that blocks are always aligned to the required number of bytes. */ 00095 #if portBYTE_ALIGNMENT != 1 00096 if( xWantedSize & portBYTE_ALIGNMENT_MASK ) 00097 { 00098 /* Byte alignment required. */ 00099 xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) ); 00100 } 00101 #endif 00102 00103 vTaskSuspendAll(); 00104 { 00105 /* Check there is enough room left for the allocation. */ 00106 if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) && 00107 ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */ 00108 { 00109 /* Return the next free byte then increment the index past this 00110 block. */ 00111 pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] ); 00112 xNextFreeByte += xWantedSize; 00113 } 00114 } 00115 xTaskResumeAll(); 00116 00117 #if( configUSE_MALLOC_FAILED_HOOK == 1 ) 00118 { 00119 if( pvReturn == NULL ) 00120 { 00121 extern void vApplicationMallocFailedHook( void ); 00122 vApplicationMallocFailedHook(); 00123 } 00124 } 00125 #endif 00126 00127 return pvReturn; 00128 } 00129 /*-----------------------------------------------------------*/ 00130 00131 void vPortFree( void *pv ) 00132 { 00133 /* Memory cannot be freed using this scheme. See heap_2.c and heap_3.c 00134 for alternative implementations, and the memory management pages of 00135 http://www.FreeRTOS.org for more information. */ 00136 ( void ) pv; 00137 } 00138 /*-----------------------------------------------------------*/ 00139 00140 void vPortInitialiseBlocks( void ) 00141 { 00142 /* Only required when static memory is not cleared. */ 00143 xNextFreeByte = ( size_t ) 0; 00144 } 00145 /*-----------------------------------------------------------*/ 00146 00147 size_t xPortGetFreeHeapSize( void ) 00148 { 00149 return ( configTOTAL_HEAP_SIZE - xNextFreeByte ); 00150 } 00151 00152 00153
Generated on Fri Jul 15 2022 10:21:25 by
1.7.2
