ChibiOS/RT  5.1.0
Core Memory Manager
Collaboration diagram for Core Memory Manager:

Detailed Description

Core Memory Manager related APIs and services.

Operation mode

The core memory manager is a simplified allocator that only allows to allocate memory blocks without the possibility to free them.
This allocator is meant as a memory blocks provider for the other allocators such as:

By having a centralized memory provider the various allocators can coexist and share the main memory.
This allocator, alone, is also useful for very simple applications that just require a simple way to get memory blocks.

Precondition
In order to use the core memory manager APIs the CH_CFG_USE_MEMCORE option must be enabled in chconf.h.
Note
Compatible with RT and NIL.

Macros

#define CH_CFG_MEMCORE_SIZE   0
 Managed RAM size. More...
 

Typedefs

typedef void *(* memgetfunc_t) (size_t size, unsigned align)
 Memory get function. More...
 
typedef void *(* memgetfunc2_t) (size_t size, unsigned align, size_t offset)
 Enhanced memory get function. More...
 

Data Structures

struct  memcore_t
 Type of memory core object. More...
 

Functions

void _core_init (void)
 Low level memory manager initialization. More...
 
void * chCoreAllocAlignedWithOffsetI (size_t size, unsigned align, size_t offset)
 Allocates a memory block. More...
 
void * chCoreAllocAlignedWithOffset (size_t size, unsigned align, size_t offset)
 Allocates a memory block. More...
 
size_t chCoreGetStatusX (void)
 Core memory status. More...
 
static void * chCoreAllocAlignedI (size_t size, unsigned align)
 Allocates a memory block. More...
 
static void * chCoreAllocAligned (size_t size, unsigned align)
 Allocates a memory block. More...
 
static void * chCoreAllocI (size_t size)
 Allocates a memory block. More...
 
static void * chCoreAlloc (size_t size)
 Allocates a memory block. More...
 

Variables

memcore_t ch_memcore
 Memory core descriptor. More...
 

Macro Definition Documentation

#define CH_CFG_MEMCORE_SIZE   0

Managed RAM size.

Size of the RAM area to be managed by the OS. If set to zero then the whole available RAM is used. The core memory is made available to the heap allocator and/or can be used directly through the simplified core memory allocator.

Note
In order to let the OS manage the whole RAM the linker script must provide the heap_base and heap_end symbols.
Requires CH_CFG_USE_MEMCORE.

Definition at line 57 of file chmemcore.h.

Typedef Documentation

typedef void*(* memgetfunc_t) (size_t size, unsigned align)

Memory get function.

Definition at line 75 of file chmemcore.h.

typedef void*(* memgetfunc2_t) (size_t size, unsigned align, size_t offset)

Enhanced memory get function.

Definition at line 80 of file chmemcore.h.

Function Documentation

void _core_init ( void  )

Low level memory manager initialization.

Function Class:
Not an API, this function is for internal use only.

Definition at line 81 of file chmemcore.c.

References CH_CFG_MEMCORE_SIZE, memcore_t::endmem, and memcore_t::nextmem.

Referenced by chSysInit().

void * chCoreAllocAlignedWithOffsetI ( size_t  size,
unsigned  align,
size_t  offset 
)

Allocates a memory block.

This function allocates a block of offset + size bytes. The returned pointer has offset bytes before its address and size bytes after.

Parameters
[in]sizethe size of the block to be allocated.
[in]aligndesired memory alignment
[in]offsetaligned pointer offset
Returns
A pointer to the allocated memory block.
Return values
NULLallocation failed, core memory exhausted.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 112 of file chmemcore.c.

References chDbgCheck, chDbgCheckClassI(), memcore_t::endmem, MEM_ALIGN_NEXT, MEM_IS_VALID_ALIGNMENT, and memcore_t::nextmem.

Referenced by chCoreAllocAligned(), chCoreAllocAlignedI(), chCoreAllocAlignedWithOffset(), and chCoreAllocI().

Here is the call graph for this function:

void * chCoreAllocAlignedWithOffset ( size_t  size,
unsigned  align,
size_t  offset 
)

Allocates a memory block.

This function allocates a block of offset + size bytes. The returned pointer has offset bytes before its address and size bytes after.

Parameters
[in]sizethe size of the block to be allocated.
[in]aligndesired memory alignment
[in]offsetaligned pointer offset
Returns
A pointer to the allocated memory block.
Return values
NULLallocation failed, core memory exhausted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 148 of file chmemcore.c.

References chCoreAllocAlignedWithOffsetI(), chSysLock(), and chSysUnlock().

Referenced by _heap_init(), and chCoreAlloc().

Here is the call graph for this function:

size_t chCoreGetStatusX ( void  )

Core memory status.

Returns
The size, in bytes, of the free core memory.
Function Class:
This is an X-Class API, this function can be invoked from any context.

Definition at line 167 of file chmemcore.c.

References memcore_t::endmem, and memcore_t::nextmem.

static void* chCoreAllocAlignedI ( size_t  size,
unsigned  align 
)
inlinestatic

Allocates a memory block.

The allocated block is guaranteed to be properly aligned to the specified alignment.

Parameters
[in]sizethe size of the block to be allocated.
[in]aligndesired memory alignment
Returns
A pointer to the allocated memory block.
Return values
NULLallocation failed, core memory exhausted.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 139 of file chmemcore.h.

References chCoreAllocAlignedWithOffsetI().

Referenced by _factory_init().

Here is the call graph for this function:

static void* chCoreAllocAligned ( size_t  size,
unsigned  align 
)
inlinestatic

Allocates a memory block.

The allocated block is guaranteed to be properly aligned to the specified alignment.

Parameters
[in]sizethe size of the block to be allocated
[in]aligndesired memory alignment
Returns
A pointer to the allocated memory block.
Return values
NULLallocation failed, core memory exhausted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 156 of file chmemcore.h.

References chCoreAllocAlignedWithOffsetI(), chSysLock(), and chSysUnlock().

Here is the call graph for this function:

static void* chCoreAllocI ( size_t  size)
inlinestatic

Allocates a memory block.

The allocated block is guaranteed to be properly aligned for a pointer data type.

Parameters
[in]sizethe size of the block to be allocated.
Returns
A pointer to the allocated memory block.
Return values
NULLallocation failed, core memory exhausted.
Function Class:
This is an I-Class API, this function can be invoked from within a system lock zone by both threads and interrupt handlers.

Definition at line 177 of file chmemcore.h.

References chCoreAllocAlignedWithOffsetI().

Here is the call graph for this function:

static void* chCoreAlloc ( size_t  size)
inlinestatic

Allocates a memory block.

The allocated block is guaranteed to be properly aligned for a pointer data type.

Parameters
[in]sizethe size of the block to be allocated.
Returns
A pointer to the allocated memory block.
Return values
NULLallocation failed, core memory exhausted.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 193 of file chmemcore.h.

References chCoreAllocAlignedWithOffset().

Here is the call graph for this function:

Variable Documentation

memcore_t ch_memcore

Memory core descriptor.

Definition at line 58 of file chmemcore.c.