ChibiOS  21.6.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...
 
#define chCoreAllocAlignedWithOffsetI   chCoreAllocFromTopI
 Allocates a memory block. More...
 
#define chCoreAllocAlignedWithOffset   chCoreAllocFromTop
 Allocates a memory block. 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 * chCoreAllocFromBaseI (size_t size, unsigned align, size_t offset)
 Allocates a memory block starting from the lowest address upward. More...
 
void * chCoreAllocFromTopI (size_t size, unsigned align, size_t offset)
 Allocates a memory block starting from the top address downward. More...
 
void * chCoreAllocFromBase (size_t size, unsigned align, size_t offset)
 Allocates a memory block starting from the lowest address upward. More...
 
void * chCoreAllocFromTop (size_t size, unsigned align, size_t offset)
 Allocates a memory block starting from the top address downward. 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

◆ CH_CFG_MEMCORE_SIZE

#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 53 of file chmemcore.h.

◆ chCoreAllocAlignedWithOffsetI

#define chCoreAllocAlignedWithOffsetI   chCoreAllocFromTopI

Allocates a memory block.

Note
This is a generic form with unspecified allocation position.
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 102 of file chmemcore.h.

◆ chCoreAllocAlignedWithOffset

#define chCoreAllocAlignedWithOffset   chCoreAllocFromTop

Allocates a memory block.

Note
This is a generic form with unspecified allocation position.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 110 of file chmemcore.h.

Typedef Documentation

◆ memgetfunc_t

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

Memory get function.

Definition at line 71 of file chmemcore.h.

◆ memgetfunc2_t

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

Enhanced memory get function.

Definition at line 76 of file chmemcore.h.

Function Documentation

◆ __core_init()

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 memcore_t::basemem, CH_CFG_MEMCORE_SIZE, ch_memcore, and memcore_t::topmem.

Referenced by __oslib_init().

◆ chCoreAllocFromBaseI()

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

Allocates a memory block starting from the lowest address upward.

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.

Referenced by chCoreAllocFromBase().

◆ chCoreAllocFromTopI()

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

Allocates a memory block starting from the top address downward.

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

Referenced by chCoreAllocFromTop().

◆ chCoreAllocFromBase()

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

Allocates a memory block starting from the lowest address upward.

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

References chCoreAllocFromBaseI(), chSysLock, and chSysUnlock.

Here is the call graph for this function:

◆ chCoreAllocFromTop()

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

Allocates a memory block starting from the top address downward.

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

References chCoreAllocFromTopI(), chSysLock, and chSysUnlock.

Here is the call graph for this function:

◆ chCoreGetStatusX()

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

References memcore_t::basemem, ch_memcore, and memcore_t::topmem.

◆ chCoreAllocAlignedI()

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.

Note
This is a generic form with unspecified allocation position.
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 150 of file chmemcore.h.

References chCoreAllocAlignedWithOffsetI.

◆ chCoreAllocAligned()

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.

Note
This is a generic form with unspecified allocation position.
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 168 of file chmemcore.h.

References chCoreAllocAlignedWithOffset.

◆ chCoreAllocI()

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.

Note
This is a generic form with unspecified allocation position.
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 185 of file chmemcore.h.

References chCoreAllocAlignedWithOffsetI, and PORT_NATURAL_ALIGN.

◆ chCoreAlloc()

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.

Note
This is a generic form with unspecified allocation position.
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 202 of file chmemcore.h.

References chCoreAllocAlignedWithOffset, and PORT_NATURAL_ALIGN.

Variable Documentation

◆ ch_memcore

memcore_t ch_memcore

Memory core descriptor.

Definition at line 58 of file chmemcore.c.

Referenced by __core_init(), and chCoreGetStatusX().