00001 /** 00002 * @file IHeap.h 00003 * 00004 * @brief Defines Heap based memory allocator. 00005 * 00006 * Heap implementation that manages fixed size buffers that can be 00007 * used in a multiprocessor system with shared memory. 00008 * 00009 * The Heap manager provides functions to allocate and free storage 00010 * from a heap of type Heap which inherits from IHeap. Heap manages 00011 * a single fixed-size buffer, split into equally sized allocable 00012 * blocks. 00013 * 00014 * The Heap manager is intended as a very fast memory 00015 * manager which can only allocate blocks of a single size. It is 00016 * ideal for managing a heap that is only used for allocating a 00017 * single type of object, or for objects that have very similar 00018 * sizes. 00019 * 00020 * This module is instance based. Each instance requires shared 00021 * memory (for the buffers and other internal state). This is 00022 * specified via the sharedAddr parameter to the create. The proper 00023 * sharedAddrSize parameter can be determined via the 00024 * sharedMemReq call. Note: the parameters to this 00025 * function must be the same that will used to create the instance. 00026 * 00027 * The Heap module uses a NameServer instance to 00028 * store instance information when an instance is created and the 00029 * name parameter is non-NULL. If a name is supplied, it must be 00030 * unique for all Heap instances. 00031 * 00032 * The create initializes the shared memory as needed. The shared 00033 * memory must be initialized to 0 before the Heap instance is 00034 * created or opened. 00035 * 00036 * Once an instance is created, an open can be performed. The 00037 * open is used to gain access to the same Heap instance. 00038 * Generally an instance is created on one processor and opened 00039 * on the other processor(s). 00040 * 00041 * The open returns a Heap instance handle like the create, 00042 * however the open does not modify the shared memory. 00043 * 00044 * There are two options when opening the instance: 00045 * -Supply the same name as specified in the create. The Heap 00046 * module queries the NameServer to get the needed information. 00047 * -Supply the same sharedAddr value as specified in the create. 00048 * 00049 * If the open is called before the instance is created, open 00050 * returns NULL. 00051 * 00052 * Constraints: 00053 * -Align parameter must be a power of 2. 00054 * -The buffer passed to dynamically create a Heap must be aligned 00055 * according to the alignment parameter, and must be large enough 00056 * to account for the actual block size after it has been rounded 00057 * up to a multiple of the alignment. 00058 * 00059 * 00060 * @ver 02.00.00.68_beta1 00061 * 00062 * ============================================================================ 00063 * 00064 * Copyright (c) 2008-2009, Texas Instruments Incorporated 00065 * 00066 * Redistribution and use in source and binary forms, with or without 00067 * modification, are permitted provided that the following conditions 00068 * are met: 00069 * 00070 * * Redistributions of source code must retain the above copyright 00071 * notice, this list of conditions and the following disclaimer. 00072 * 00073 * * Redistributions in binary form must reproduce the above copyright 00074 * notice, this list of conditions and the following disclaimer in the 00075 * documentation and/or other materials provided with the distribution. 00076 * 00077 * * Neither the name of Texas Instruments Incorporated nor the names of 00078 * its contributors may be used to endorse or promote products derived 00079 * from this software without specific prior written permission. 00080 * 00081 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00082 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 00083 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00084 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00085 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00086 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00087 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 00088 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00089 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 00090 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00091 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00092 * Contact information for paper mail: 00093 * Texas Instruments 00094 * Post Office Box 655303 00095 * Dallas, Texas 75265 00096 * Contact information: 00097 * http://www-k.ext.ti.com/sc/technical-support/product-information-centers.htm? 00098 * DCMP=TIHomeTracking&HQS=Other+OT+home_d_contact 00099 * ============================================================================ 00100 * 00101 */ 00102 00103 00104 #ifndef HEAP_H_0x7033 00105 #define HEAP_H_0x7033 00106 00107 00108 /* OSAL and utils */ 00109 #include <ti/syslink/utils/MemoryDefs.h> 00110 #include <ti/syslink/utils/Trace.h> 00111 00112 00113 #if defined (__cplusplus) 00114 extern "C" { 00115 #endif 00116 00117 00118 /* ============================================================================= 00119 * Forward declarations 00120 * ============================================================================= 00121 */ 00122 /*! @brief Forward declaration of structure defining object for the 00123 * Heap module 00124 */ 00125 typedef struct IHeap_Object_tag IHeap_Object; 00126 00127 /*! 00128 * @brief Handle for the Heap Buf. 00129 */ 00130 typedef struct IHeap_Object * IHeap_Handle; 00131 00132 00133 /* ============================================================================= 00134 * Function pointer types for heap operations 00135 * ============================================================================= 00136 */ 00137 /*! @brief Type for function pointer to allocate a memory block */ 00138 typedef Ptr (*IHeap_allocFxn) (IHeap_Handle handle, 00139 SizeT size, 00140 SizeT align); 00141 00142 /*! @brief Type for function pointer to free a memory block */ 00143 typedef Void (*IHeap_freeFxn) (IHeap_Handle handle, 00144 Ptr block, 00145 SizeT size); 00146 00147 /*! @brief Type for function pointer to get memory related statistics */ 00148 typedef Void (*IHeap_getStatsFxn) (IHeap_Handle handle, 00149 Memory_Stats * stats); 00150 00151 /* 00152 * ! @brief Type for function pointer to indicate whether the heap may block 00153 * during an alloc or free call 00154 */ 00155 typedef Bool (*IHeap_isBlockingFxn) (IHeap_Handle handle); 00156 00157 /*! @brief Type for function pointer to get handle to kernel object */ 00158 typedef Ptr (*IHeap_getKnlHandleFxn) (IHeap_Handle handle); 00159 00160 00161 /* ============================================================================= 00162 * Structures & Enums 00163 * ============================================================================= 00164 */ 00165 /*! 00166 * @brief Structure for the Handle for the Heap. 00167 */ 00168 struct IHeap_Object_tag { 00169 IHeap_allocFxn alloc; 00170 /*!< Allocate a block */ 00171 IHeap_freeFxn free; 00172 /*!< Free a block */ 00173 IHeap_getStatsFxn getStats; 00174 /*!< Get statistics */ 00175 IHeap_isBlockingFxn isBlocking; 00176 /*!< Does the Heap block during alloc/free? */ 00177 IHeap_getKnlHandleFxn getKnlHandle; 00178 /*!< Get kernel object handle */ 00179 Ptr obj; 00180 /*!< Actual Heap Handle */ 00181 }; 00182 00183 00184 /* ============================================================================= 00185 * APIs 00186 * ============================================================================= 00187 */ 00188 /*! 00189 * @brief Allocate a block of memory of specified size. 00190 * 00191 * @param handle Handle to previously created/opened instance. 00192 * @param size Size to be allocated (in bytes) 00193 * @param align Alignment for allocation (power of 2) 00194 * 00195 * @retval buffer Allocated buffer 00196 * 00197 * @sa IHeap_free 00198 */ 00199 static inline Ptr IHeap_alloc (IHeap_Handle handle, 00200 SizeT size, 00201 SizeT align) 00202 { 00203 Ptr buffer; 00204 00205 GT_assert (curTrace, (((IHeap_Object *) handle)->alloc != NULL)); 00206 buffer = ((IHeap_Object *) handle)->alloc (handle, size, align); 00207 return (buffer); 00208 } 00209 00210 00211 /*! 00212 * @brief Frees a block of memory. 00213 * 00214 * @param handle Handle to previously created/opened instance. 00215 * @param block Block of memory to be freed. 00216 * @param size Size to be freed (in bytes) 00217 * 00218 * @sa Heap_alloc 00219 */ 00220 static inline Void IHeap_free (IHeap_Handle handle, 00221 Ptr block, 00222 SizeT size) 00223 { 00224 GT_assert (curTrace, (((IHeap_Object *) handle)->free != NULL)); 00225 ((IHeap_Object *) handle)->free (handle, block, size); 00226 } 00227 00228 00229 /*! 00230 * @brief Get memory statistics 00231 * 00232 * @param handle Handle to previously created/opened instance. 00233 * @params stats Memory statistics structure 00234 * 00235 * @sa 00236 */ 00237 static inline Void IHeap_getStats (IHeap_Handle handle, 00238 Memory_Stats * stats) 00239 { 00240 GT_assert (curTrace, (((IHeap_Object *) handle)->getStats != NULL)); 00241 ((IHeap_Object *) handle)->getStats (handle, stats); 00242 } 00243 00244 00245 /*! 00246 * @brief Indicate whether the heap may block during an alloc or free call 00247 * 00248 * @param handle Handle to previously created/opened instance. 00249 * 00250 * @retval TRUE Heap is blocking 00251 * @retval FALSE Heap is non-blocking 00252 * 00253 * @sa 00254 */ 00255 static inline Bool IHeap_isBlocking (IHeap_Handle handle) 00256 { 00257 Bool isBlocking; 00258 GT_assert (curTrace, (((IHeap_Object *) handle)->isBlocking != NULL)); 00259 isBlocking = ((IHeap_Object *) handle)->isBlocking (handle); 00260 return (isBlocking); 00261 } 00262 00263 00264 /*! 00265 * @brief Function to get the kernel object pointer embedded in userspace heap. 00266 * Some Heap implementations return the kernel object handle. 00267 * Heaps which do not have kernel object pointer embedded return NULL. 00268 * 00269 * @params handle handle to a heap instance 00270 * 00271 * @retval handle Handle to kernel object. 00272 * 00273 * @sa 00274 */ 00275 static inline Ptr IHeap_getKnlHandle (IHeap_Handle handle) 00276 { 00277 Ptr knlHandle; 00278 GT_assert (curTrace, (((IHeap_Object *) handle)->getKnlHandle != NULL)); 00279 knlHandle = ((IHeap_Object *) handle)->getKnlHandle (handle); 00280 return (knlHandle); 00281 } 00282 00283 00284 #if defined (__cplusplus) 00285 } 00286 #endif /* defined (__cplusplus) */ 00287 00288 00289 #endif /* HEAP_H_0x7033 */ 00290
1.4.4