ChibiOS/RT
2.5.1
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_USE_MEMCORE option must be enabled in chconf.h.

Functions

void _core_init (void)
 Low level memory manager initialization.
void * chCoreAlloc (size_t size)
 Allocates a memory block.
void * chCoreAllocI (size_t size)
 Allocates a memory block.
size_t chCoreStatus (void)
 Core memory status.

Alignment support macros

#define MEM_ALIGN_SIZE   sizeof(stkalign_t)
 Alignment size constant.
#define MEM_ALIGN_MASK   (MEM_ALIGN_SIZE - 1)
 Alignment mask constant.
#define MEM_ALIGN_PREV(p)   ((size_t)(p) & ~MEM_ALIGN_MASK)
 Alignment helper macro.
#define MEM_ALIGN_NEXT(p)   MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK)
 Alignment helper macro.
#define MEM_IS_ALIGNED(p)   (((size_t)(p) & MEM_ALIGN_MASK) == 0)
 Returns whatever a pointer or memory size is aligned to the type align_t.

Typedefs

typedef void *(* memgetfunc_t )(size_t size)
 Memory get function.

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 59 of file chmemcore.c.

References CH_MEMCORE_SIZE, MEM_ALIGN_NEXT, MEM_ALIGN_PREV, and MEM_ALIGN_SIZE.

Referenced by chSysInit().

void * chCoreAlloc ( size_t  size)

Allocates a memory block.

The size of the returned block is aligned to the alignment type so it is not possible to allocate less than MEM_ALIGN_SIZE.

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 84 of file chmemcore.c.

References chCoreAllocI(), chSysLock, and chSysUnlock.

Referenced by _heap_init().

Here is the call graph for this function:

void * chCoreAllocI ( size_t  size)

Allocates a memory block.

The size of the returned block is aligned to the alignment type so it is not possible to allocate less than MEM_ALIGN_SIZE.

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 105 of file chmemcore.c.

References chDbgCheckClassI(), and MEM_ALIGN_NEXT.

Referenced by chCoreAlloc().

Here is the call graph for this function:

size_t chCoreStatus ( void  )

Core memory status.

Returns:
The size, in bytes, of the free core memory.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 125 of file chmemcore.c.


Define Documentation

#define MEM_ALIGN_SIZE   sizeof(stkalign_t)

Alignment size constant.

Definition at line 45 of file chmemcore.h.

Referenced by _core_init().

#define MEM_ALIGN_MASK   (MEM_ALIGN_SIZE - 1)

Alignment mask constant.

Definition at line 50 of file chmemcore.h.

#define MEM_ALIGN_PREV (   p)    ((size_t)(p) & ~MEM_ALIGN_MASK)

Alignment helper macro.

Definition at line 55 of file chmemcore.h.

Referenced by _core_init().

#define MEM_ALIGN_NEXT (   p)    MEM_ALIGN_PREV((size_t)(p) + MEM_ALIGN_MASK)

Alignment helper macro.

Definition at line 60 of file chmemcore.h.

Referenced by _core_init(), chCoreAllocI(), and chHeapAlloc().

#define MEM_IS_ALIGNED (   p)    (((size_t)(p) & MEM_ALIGN_MASK) == 0)

Returns whatever a pointer or memory size is aligned to the type align_t.

Definition at line 66 of file chmemcore.h.

Referenced by chHeapInit().


Typedef Documentation

typedef void*(* memgetfunc_t)(size_t size)

Memory get function.

Note:
This type must be assignment compatible with the chMemAlloc() function.

Definition at line 37 of file chmemcore.h.