NXP / fsl_phy_mcr20a

Fork of fsl_phy_mcr20a by Freescale

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MemManager.h Source File

MemManager.h

Go to the documentation of this file.
00001 /*!
00002 * Copyright (c) 2015, Freescale Semiconductor, Inc.
00003 * All rights reserved.
00004 *
00005 * \file MemManager.h
00006 * This is the header file for the Memory Manager interface.
00007 *
00008 * Redistribution and use in source and binary forms, with or without modification,
00009 * are permitted provided that the following conditions are met:
00010 *
00011 * o Redistributions of source code must retain the above copyright notice, this list
00012 *   of conditions and the following disclaimer.
00013 *
00014 * o Redistributions in binary form must reproduce the above copyright notice, this
00015 *   list of conditions and the following disclaimer in the documentation and/or
00016 *   other materials provided with the distribution.
00017 *
00018 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
00019 *   contributors may be used to endorse or promote products derived from this
00020 *   software without specific prior written permission.
00021 *
00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00023 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00024 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00026 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00027 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00029 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00031 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 */
00033 
00034 #ifndef _MEM_MANAGER_H_
00035 #define _MEM_MANAGER_H_
00036 
00037 /*! *********************************************************************************
00038 *************************************************************************************
00039 * Include
00040 *************************************************************************************
00041 ********************************************************************************** */
00042 #include "EmbeddedTypes.h "
00043 #include "GenericList.h "
00044 #include "MemManagerConfig.h "
00045 
00046 
00047 /*! *********************************************************************************
00048 *************************************************************************************
00049 * Public macros
00050 *************************************************************************************
00051 ********************************************************************************** */
00052 /*Defines pools by block size and number of blocks. Must be alligned to 4 bytes.*/     
00053 #ifndef PoolsDetails_c
00054 #define PoolsDetails_c \
00055          _block_size_  64  _number_of_blocks_    8 _eol_  \
00056          _block_size_ 128  _number_of_blocks_    2 _eol_  \
00057          _block_size_ 256  _number_of_blocks_    6 _eol_
00058 #endif
00059 
00060 
00061 /*! *********************************************************************************
00062 *************************************************************************************
00063 * Private type definitions
00064 *************************************************************************************
00065 ********************************************************************************** */
00066 /*Defines statuses used in MEM_BufferAlloc and MEM_BufferFree*/
00067 typedef enum
00068 {
00069   MEM_SUCCESS_c = 0,                    /* No error occurred */
00070   MEM_INIT_ERROR_c,                     /* Memory initialization error */
00071   MEM_ALLOC_ERROR_c,                    /* Memory allocation error */
00072   MEM_FREE_ERROR_c,                     /* Memory free error */
00073   MEM_UNKNOWN_ERROR_c                   /* something bad has happened... */
00074 }memStatus_t ;
00075 
00076 
00077 /*! *********************************************************************************
00078 *************************************************************************************
00079 * Public prototypes
00080 *************************************************************************************
00081 ********************************************************************************** */
00082 #ifdef __cplusplus
00083 extern "C" {
00084 #endif  
00085 /*Initialises the Memory Manager.*/
00086 memStatus_t  MEM_Init(void);
00087 /*Returns the number of available blocks that fit the given size.*/
00088 uint32_t MEM_GetAvailableBlocks(uint32_t size);
00089 /*Frees the givem buffer.*/
00090 memStatus_t  MEM_BufferFree(void* buffer);
00091 /*Returns the allocated buffer of the given size.*/
00092 void* MEM_BufferAlloc(uint32_t numBytes);
00093 /*Returns the size of a given buffer*/
00094 uint16_t MEM_BufferGetSize(void* buffer);
00095 /*Performs a write-read-verify test accross all pools*/
00096 uint32_t MEM_WriteReadTest(void);
00097 #ifdef __cplusplus
00098 }//extern "C" 
00099 #endif
00100 
00101 /*! *********************************************************************************
00102 *************************************************************************************
00103 * Private macros
00104 *************************************************************************************
00105 ********************************************************************************** */
00106 #if defined(MEM_TRACKING) && defined(DEBUG_ASSERT)
00107 #define MEM_ASSERT(condition) if(!(condition))while(1);
00108 #else
00109 #define MEM_ASSERT(condition) (void)(condition);
00110 #endif
00111 
00112 
00113 /*! *********************************************************************************
00114 *************************************************************************************
00115 * Private type definitions
00116 *************************************************************************************
00117 ********************************************************************************** */
00118 
00119 #ifdef MEM_STATISTICS
00120 /*Statistics structure definition. Used by pools.*/
00121 typedef struct poolStat_tag 
00122   {
00123   uint16_t numBlocks;
00124   uint16_t allocatedBlocks;
00125   uint16_t allocatedBlocksPeak;
00126   uint16_t allocationFailures;
00127   uint16_t freeFailures;
00128 #ifdef MEM_TRACKING
00129   uint16_t poolFragmentWaste;
00130   uint16_t poolFragmentWastePeak;
00131 #endif /*MEM_TRACKING*/
00132   } poolStat_t ;
00133 #endif /*MEM_STATISTICS*/
00134 
00135 #ifdef MEM_TRACKING
00136 /*Definition for alloc indicators. Used in buffer tracking.*/
00137 typedef enum
00138 {
00139   MEM_TRACKING_FREE_c = 0,
00140   MEM_TRACKING_ALLOC_c,
00141 }memTrackingStatus_t;
00142 
00143 /*Tracking structure definition.*/
00144 typedef struct BlockTracking_tag
00145 {
00146   void *blockAddr;                  /*Addr of Msg, not that this pointer is
00147                                      4 byte bigger than the addr in the pool
00148                                      has the header of the msg is 4 bytes */
00149   uint16_t blockSize;               /*Size of block in bytes.*/
00150   uint16_t fragmentWaste;           /*Size requested by allocator.*/
00151   void *allocAddr;                  /*Return address of last Alloc made */
00152   void *freeAddr;                   /*Return address of last Free made */
00153   uint16_t allocCounter;            /*No of time this msg has been allocated */
00154   uint16_t freeCounter;             /*No of time this msg has been freed */
00155   memTrackingStatus_t allocStatus;  /*1 if currently allocated, 0 if currently free */
00156   // uint8_t padding;
00157 }blockTracking_t;
00158 #endif /*MEM_TRACKING*/
00159 
00160 /*Header description for buffers.*/
00161 typedef struct listHeader_tag
00162 {
00163   listElement_t link;
00164   struct pools_tag *pParentPool;
00165 }listHeader_t;
00166 
00167 /*Buffer pools. Used by most functions*/
00168 typedef struct pools_tag
00169 {
00170   list_t anchor; /* MUST be first element in pools_t struct */
00171   uint16_t nextBlockSize;
00172   uint16_t blockSize;
00173 #ifdef MEM_STATISTICS
00174   poolStat_t  poolStatistics;
00175   uint8_t padding[2];
00176 #endif /*MEM_STATISTICS*/   
00177 }pools_t;
00178 
00179 /*Buffer pool description. Used by MM_Init() for creating the buffer pools. */
00180 typedef struct poolInfo_tag
00181 {
00182   uint16_t blockSize;
00183   uint16_t poolSize;
00184  /* uint8_t padding[2]; */
00185 }poolInfo_t;
00186 
00187 /*! *********************************************************************************
00188 *************************************************************************************
00189 * Private prototypes
00190 *************************************************************************************
00191 ********************************************************************************** */
00192 
00193 #ifdef MEM_TRACKING
00194 uint8_t MEM_Track(listHeader_t *block, memTrackingStatus_t alloc, uint32_t address, uint16_t requestedSize);
00195 uint8_t MEM_BufferCheck(uint8_t *p, uint32_t size);
00196 #endif /*MEM_TRACKING*/
00197 
00198 #endif /* _MEM_MANAGER_H_ */