MCUXpresso SDK API Reference Manual  Rev 2.12.7
NXP Semiconductors
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
MemManager

Overview

Data Structures

struct  mem_config_t
 Memory user config. More...
 
struct  memAreaCfg_t
 Memory user config. More...
 

Macros

#define MinimalHeapSize_c   (uint32_t)4
 Provide Minimal heap size for application to execute correctly. More...
 
#define gMemManagerLight   (1)
 Configures the memory manager light enable.
 
#define MEM_MANAGER_ENABLE_TRACE   (0)
 Configures the memory manager trace debug enable.
 
#define MEM_MANAGER_PRE_CONFIGURE   (1)
 Configures the memory manager pre configure.
 
#define MEM_BLOCK_DATA_BUFFER_DEFINE(name, numberOfBlocks, blockSize, id)
 Defines the memory buffer. More...
 
#define MEM_BLOCK_BUFFER(name)   (uint8_t *)&g_poolHeadBuffer##name
 \ More...
 

Enumerations

enum  mem_status_t
 Memory status.
 

Functions

mem_status_t MEM_Init (void)
 Initialises the Memory Manager.
 
void * MEM_BufferAllocWithId (uint32_t numBytes, uint8_t poolId)
 Allocate a block from the memory pools. More...
 
mem_status_t MEM_BufferFree (void *buffer)
 Memory buffer free . More...
 
uint16_t MEM_BufferGetSize (void *buffer)
 Returns the size of a given buffer. More...
 
mem_status_t MEM_BufferFreeAllWithId (uint8_t poolId)
 Frees all allocated blocks by selected source and in selected pool. More...
 
void * MEM_BufferRealloc (void *buffer, uint32_t new_size)
 Memory buffer realloc. More...
 
uint32_t MEM_GetHeapUpperLimit (void)
 Get the address after the last allocated block if MemManagerLight is used. More...
 
uint32_t MEM_GetHeapUpperLimitByAreaId (uint8_t id)
 Get the address after the last allocated block in area defined by id. More...
 
uint32_t MEM_GetFreeHeapSizeLowWaterMark (void)
 Get the free space low watermark. More...
 
uint32_t MEM_GetFreeHeapSizeLowWaterMarkByAreaId (uint8_t area_id)
 Get the free space low watermark. More...
 
uint32_t MEM_ResetFreeHeapSizeLowWaterMark (void)
 Reset the free space low watermark. More...
 
uint32_t MEM_ResetFreeHeapSizeLowWaterMarkByAreaId (uint8_t area_id)
 Reset the free space low watermark. More...
 
uint32_t MEM_GetFreeHeapSizeByAreaId (uint8_t area_id)
 Get the free space in the heap for a area id. More...
 
uint32_t MEM_GetFreeHeapSize (void)
 Get the free space in the heap. More...
 
void MEM_ReinitRamBank (uint32_t startAddress, uint32_t endAddress)
 Selective RAM bank reinit after low power, based on a requested address range Useful for ECC RAM banks Defined as weak and empty in fsl_component_mem_manager_light.c to be overloaded by user. More...
 
mem_status_t MEM_RegisterExtendedArea (memAreaCfg_t *area_desc, uint8_t *area_id, uint16_t flags)
 Function to register additional areas to allocate memory from. More...
 
mem_status_t MEM_UnRegisterExtendedArea (uint8_t area_id)
 Function to unregister an extended area. More...
 

Data Structure Documentation

struct mem_config_t
struct _mem_area_cfg_s

Macro Definition Documentation

#define MinimalHeapSize_c   (uint32_t)4

The application can define a minimal heap size for proper code exection at run time, This will issue a link error if the minimal heap size requirement is not fullfilled (not enough space in RAM) By Default, Minimal heap size is set to 4 bytes (unlikely enough to have application work correctly)

#define MEM_BLOCK_DATA_BUFFER_DEFINE (   name,
  numberOfBlocks,
  blockSize,
  id 
)
Value:
uint32_t \
g_poolBuffer##name[(MEM_POOL_SIZE + numberOfBlocks * MEM_BLOCK_SIZE + numberOfBlocks * blockSize + 3U) >> 2U];

This macro is used to define the shell memory buffer for memory manager. And then uses the macro MEM_BLOCK_BUFFER to get the memory buffer pointer. The macro should not be used in any function.

This is a example,

* MEM_BLOCK_BUFFER_DEFINE(app64, 5, 64,0);
* MEM_BLOCK_BUFFER_DEFINE(app128, 6, 128,0);
* MEM_BLOCK_BUFFER_DEFINE(app256, 7, 256,0);
*
Parameters
nameThe name string of the memory buffer.
numberOfBlocksThe number Of Blocks.
blockSizeThe memory block size.
idThe id Of memory buffer.
#define MEM_BLOCK_BUFFER (   name)    (uint8_t *)&g_poolHeadBuffer##name

Gets the memory buffer pointer \ \ This macro is used to get the memory buffer pointer. The macro should \ not be used before the macro MEM_BLOCK_BUFFER_DEFINE is used. \ \

Parameters
nameThe memory name string of the buffer. \

Function Documentation

void* MEM_BufferAllocWithId ( uint32_t  numBytes,
uint8_t  poolId 
)

The function uses the numBytes argument to look up a pool with adequate block sizes.

Parameters
numBytesThe number of bytes will be allocated.
poolIdThe ID of the pool where to search for a free buffer.
Return values
Memorybuffer address when allocate success, NULL when allocate fail.
mem_status_t MEM_BufferFree ( void *  buffer)
Parameters
bufferThe memory buffer address will be free.
Return values
kStatus_MemSuccessMemory free succeed.
kStatus_MemFreeErrorMemory free error occurred.
uint16_t MEM_BufferGetSize ( void *  buffer)
Parameters
bufferThe memory buffer address will be get size.
Return values
Thesize of a given buffer.
mem_status_t MEM_BufferFreeAllWithId ( uint8_t  poolId)
Parameters
poolIdSelected pool Id (4 LSBs of poolId parameter) and selected source Id (4 MSBs of poolId parameter).
Return values
kStatus_MemSuccessMemory free succeed.
kStatus_MemFreeErrorMemory free error occurred.
void* MEM_BufferRealloc ( void *  buffer,
uint32_t  new_size 
)
Parameters
bufferThe memory buffer address will be reallocated.
new_sizeThe number of bytes will be reallocated
Return values
kStatus_MemSuccessMemory free succeed.
kStatus_MemFreeErrorMemory free error occurred.
uint32_t MEM_GetHeapUpperLimit ( void  )
Return values
UpperLimitReturn the address after the last allocated block if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_GetHeapUpperLimitByAreaId ( uint8_t  id)
Parameters
[in]id0 means memHeap, other values depend on number of registered areas
Return values
UpperLimitReturn the address after the last allocated block if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_GetFreeHeapSizeLowWaterMark ( void  )
Return values
FreeHeapSizeReturn the heap space low water mark free if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_GetFreeHeapSizeLowWaterMarkByAreaId ( uint8_t  area_id)
Parameters
area_idSelected area Id
Return values
Returnthe heap space low water mark free if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_ResetFreeHeapSizeLowWaterMark ( void  )
Return values
FreeHeapSizeReturn the heap space low water mark free at the time it was reset if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_ResetFreeHeapSizeLowWaterMarkByAreaId ( uint8_t  area_id)
Parameters
area_idSelected area Id
Return values
FreeHeapSizeReturn the heap space low water mark free at the time it was reset if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_GetFreeHeapSizeByAreaId ( uint8_t  area_id)
Parameters
area_idarea_id whose available size is requested (0 means generic pool)
Return values
FreeHeapSizeReturn the free space in the heap if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
uint32_t MEM_GetFreeHeapSize ( void  )
Return values
FreeHeapSizeReturn the free space in the heap if MemManagerLight is used.
0Return 0 in case of the legacy MemManager.
void MEM_ReinitRamBank ( uint32_t  startAddress,
uint32_t  endAddress 
)
Parameters
[in]startAddressStart address of the requested range
[in]endAddressEnd address of the requested range
mem_status_t MEM_RegisterExtendedArea ( memAreaCfg_t *  area_desc,
uint8_t *  area_id,
uint16_t  flags 
)
Parameters
[in]area_descmemAreaCfg_t structure defining start address and end address of area. This atructure may not be in rodata becasue the next field and internal private context are reserved in this structure. If NULL defines the default memHeap area.
[out]p_area_idpointer to return id of area. Required if allocation from specific pool is required.
[in]flagsBIT(0) means that allocations can be performed in pool only explicitly and it is not a member of the default pool (id 0). Invalid for initial registration call.
Returns
kStatus_MemSuccess if success, kStatus_MemInitError otherwise.
mem_status_t MEM_UnRegisterExtendedArea ( uint8_t  area_id)
Parameters
[in]area_idmust be different from 0 (main heap).
Returns
kStatus_MemSuccess if success, kStatus_MemFreeError if area_id is 0 or area not found or still has buffers in use.