Choco OS  V.0.16.9.0
Join to the chocolate world
(MemMan) Memory Manager

Module for manage memory space. More...

Data Structures

struct  oC_MemMan_AllocatorsStats_t
 
struct  oC_MemMan_AllocationStats_t
 

Typedefs

typedef void(* oC_MemMan_DumpFunction_t) (oC_UInt_t Data)
 stores pointer to function for dumping data
 

Functions

oC_ErrorCode_t oC_MemMan_TurnOn (void)
 turns on memory manager More...
 
oC_ErrorCode_t oC_MemMan_TurnOff (void)
 turns off the module More...
 
void oC_MemMan_CheckOverflow (void)
 scan each block to check if the overflow event not occurs. More...
 
void oC_MemMan_CheckMemoryExhausted (void)
 checks if memory exhausted event not occurs. More...
 
void oC_MemMan_CheckMemoryLeak (void)
 checks if memory is not leaking More...
 
oC_ErrorCode_t oC_MemMan_TestAndRepairMainHeap (oC_MemMan_DumpFunction_t DumpFunction)
 diagnoses main heap More...
 
oC_HeapMap_t oC_MemMan_AllocateHeapMap (oC_UInt_t Size, Allocator_t Allocator, const char *Function, uint32_t LineNumber, AllocationFlags_t Flags)
 allocates memory for new heap map More...
 
bool oC_MemMan_FreeHeapMap (oC_HeapMap_t *MapPointer, AllocationFlags_t Flags)
 release heap map More...
 
void * oC_MemMan_RawAllocate (oC_HeapMap_t Map, oC_UInt_t Size, const char *Function, uint32_t LineNumber, AllocationFlags_t Flags)
 allow to allocate memory in heap map More...
 
bool oC_MemMan_RawFree (oC_HeapMap_t Map, void *Address, oC_UInt_t Size)
 release memory in heap map More...
 
void * oC_MemMan_Allocate (oC_UInt_t Size, Allocator_t Allocator, const char *Function, uint32_t LineNumber, AllocationFlags_t Flags, oC_UInt_t Alignment)
 allocates memory on heap More...
 
bool oC_MemMan_Free (void *Address, AllocationFlags_t Flags)
 release allocated memory More...
 
bool oC_MemMan_FreeAllMemoryOfAllocator (Allocator_t Allocator)
 release all memory of allocator More...
 
oC_ErrorCode_t oC_MemMan_SetEventHandler (MemoryEventHandler_t EventHandler)
 sets event handler function More...
 
Allocator_t oC_MemMan_GetAllocatorOfAddress (const void *Address)
 returns allocator of address More...
 
oC_UInt_t oC_MemMan_GetSizeOfAllocation (const void *Address)
 returns size of allocation More...
 
void * oC_MemMan_AlignAddress (const void *Address)
 returns address aligned to the machine alignment. More...
 
void * oC_MemMan_AlignAddressTo (const void *Address, oC_UInt_t Alignment)
 returns address aligned to the given alignment. More...
 
bool oC_MemMan_IsAddressAligned (const void *Address)
 checks if address is aligned More...
 
bool oC_MemMan_IsAddressAlignedTo (const void *Address, oC_UInt_t Alignment)
 checks if address is aligned to given alignment More...
 
oC_UInt_t oC_MemMan_AlignSize (oC_UInt_t Size)
 returns size aligned to the machine alignment More...
 
oC_UInt_t oC_MemMan_AlignSizeTo (oC_UInt_t Size, oC_UInt_t Alignment)
 returns size aligned to the given alignment More...
 
bool oC_MemMan_IsSizeAligned (oC_UInt_t Size)
 checks if a size is aligned More...
 
oC_UInt_t oC_MemMan_GetMaximumAllocationSize (void)
 returns maximum size of allocation More...
 
oC_UInt_t oC_MemMan_GetFlashSize (void)
 returns size of the machine flash More...
 
oC_UInt_t oC_MemMan_GetRamSize (void)
 returns size of the machine ram More...
 
oC_UInt_t oC_MemMan_GetFreeFlashSize (void)
 returns size of the machine not used flash More...
 
oC_UInt_t oC_MemMan_GetFreeRamSize (void)
 returns size of free ram More...
 
oC_UInt_t oC_MemMan_GetExternalHeapSize (void)
 returns size of external ram More...
 
oC_UInt_t oC_MemMan_GetDmaRamHeapSize (void)
 returns size of external ram More...
 
oC_UInt_t oC_MemMan_GetMemoryOfAllocatorSize (Allocator_t Allocator)
 returns size of allocations per allocator More...
 
oC_UInt_t oC_MemMan_GetAllocationBlockSize (void)
 returns size of block needed for allocation More...
 
oC_UInt_t oC_MemMan_GetHeapMapSize (oC_HeapMap_t Map)
 returns size of heap map More...
 
oC_UInt_t oC_MemMan_GetFreeHeapMapSize (oC_HeapMap_t Map)
 returns size of free memory in heap map More...
 
bool oC_MemMan_IsFlashAddress (const void *Address)
 checks if address is placed in the flash section
 
bool oC_MemMan_IsUsedFlashAddress (const void *Address)
 checks if address is in used flash section
 
bool oC_MemMan_IsRamAddress (const void *Address)
 checks if address is in ram section
 
bool oC_MemMan_IsDynamicAllocatedAddress (const void *Address)
 checks if address is in dynamic allocated section
 
bool oC_MemMan_IsStaticRamAddress (const void *Address)
 checks if address is in static used ram section (data section)
 
bool oC_MemMan_IsAddressCorrect (const void *Address)
 checks if address is correct - in RAM or in FLASH
 
bool oC_MemMan_IsAllocatorCorrect (Allocator_t Allocator)
 checks if allocator is correct
 
oC_ErrorCode_t oC_MemMan_ReadAllocatorsStats (oC_MemMan_AllocatorsStats_t *outAllocatorsArray, oC_UInt_t *Size)
 Reads allocators statistics array. More...
 
oC_ErrorCode_t oC_MemMan_ReadAllocationsStats (Allocator_t Allocator, oC_MemMan_AllocationStats_t *outAllocationsArray, oC_UInt_t *Size, bool JoinSimilar)
 Reads allocations statistics of the allocator. More...
 
bool oC_MemMan_FindOverflowedAllocation (Allocator_t Allocator, oC_MemMan_AllocationStats_t *outAllocationStat)
 searches for a overflowed buffer More...
 
oC_ErrorCode_t oC_MemMan_ConfigureExternalHeapMap (void *StartAddress, oC_UInt_t Size)
 prepares HeapMap stored in external RAM More...
 
oC_ErrorCode_t oC_MemMan_UnconfigureExternalHeapMap (void)
 unconfigures external heap More...
 
float oC_MemMan_GetMemoryExhaustedLimit (void)
 
float oC_MemMan_GetPanicMemoryExhaustedLimit (void)
 
oC_ErrorCode_t oC_MemMan_SetMemoryExhaustedLimit (float LimitPercent)
 
oC_ErrorCode_t oC_MemMan_SetPanicMemoryExhaustedLimit (float LimitPercent)
 

Detailed Description

Introduction

The Memory Manager module is for operations based on the machine memory. It is part of the core space and require the MEM-LLD to work. It is important, that it also manage the power of this module. The MemMan must be turned on before usage, using function oC_MemMan_TurnOn. It initialize pointers, and submodules to work with it. When the Memory Manager is not needed anymore (it is not recommended but possible) it can be turned off using oC_MemMan_TurnOff function. Note, that this function release all allocated memory, and if there is some still used pointers it can cause some bugs.
Note
When the MemMan module is turned off, the #oC_MemMan_EventFlags_ModuleTurningOff event is called
When the module is turned on, it is possible to set the module event handler. This is a pointer to a function, that will be executed, when some of module events occurs. This pointer can be set only once until turning off the module by function oC_MemMan_SetEventHandler. Look at #oC_MemMan_EventFlags_t for list of available events.
The main purpose of this is managing the memory allocations. It helps to reserve memory on the machine heap, but it also protects this memory. The first of all, to allocate, it is required to create the special structure, named as Allocator, that is represented by the type #oC_MemMan_Allocator_t. Thanks to this type, none of allocations is anonymous. The Allocator should be created per module as static constant definition, and the pointer to it should be given in each allocation in the module. The Memory Manager provide the interface to get size of all memory allocated for the allocator, and release it all by functions oC_MemMan_GetMemoryOfAllocatorSize and oC_MemMan_FreeAllMemoryOfAllocator. There are also some events Allocator specific. It is possible to set event handler and choose events per allocator in the #oC_MemMan_Allocator_t struct. Some example of usage is given below:
static void EventHandlerFunction( void * Address , oC_MemMan_EventFlags_t Flags , const char * Function, uint32_t LineNumber )
{
// handling of events
}
static const oC_MemMan_Allocator_t Allocator = {
.Name = "Example allocator" ,
.EventHandler = EventHandlerFunction ,
.EventFlags = oC_MemMan_EventFlags_BufferOverflow | oC_MemMan_EventFlags_PossibleMemoryLeak
};
void main()
{
uint32_t * Buffer = oC_MemMan_Allocate( sizeof(uint32_t) * 10 , &Allocator , __LINE__ , oC_MemMan_AllocationFlags_Default);
for(int i = 0; i <= 10 ; i++)
{
// This loop overwrite the buffer.
Buffer[i] = 0;
}
// When this function is called, the overflow will be detected, and EventHandlerFunction function will be called.
oC_MemMan_Free( Buffer );
}
As in the example above, standard allocation of memory is possible by using the function oC_MemMan_Allocate. It is standard, and the most comfortable way, but it require a lot of memory for managing it (something about 20 bytes per each allocation). Because of that, the module supports some alternative way for memory allocation, that is designed for taking minimum additional memory (only 1 bit for 1 memory word). This way is better for cases, when some module needs a lot of little allocations with always known sizes (for example for the same structures), and it is called raw allocation. It can be handled by functions oC_MemMan_RawAllocate and oC_MemMan_RawFree. To allocate a memory in the raw way the heap map must be created. It can be done by function oC_MemMan_AllocateHeapMap. It is a special memory block, where your raw allocations will be placed. It is designed as follows:
Start address of the memory block _ _ +-----------------------------------+
| | Bit map - each bit in this section is reserved for one word (oC_UInt_t)
| BIT MAP | in HEAP section. If bit is set, then the word is used (allocated)
| |
+-----------------------------------+
| | Heap - memory for allocations (this stores your data)
| HEAP |
| |
End address of the memory block _ _ +-----------------------------------+
So the part of the heap map memory will be reserved for the bit map. Each bit in this map is for 1 word of the heap, and when it is set to 1, then the word is already allocated. It is recommended to allocate just something about 3% more memory as needed. Here some example of usage:
static const oC_MemMan_Allocator_t Allocator = {"Example memory heap"};
int main()
{
// It allocates 100 bytes for this heap map, so if machine will be 32 bit, 3 bytes (it will be aligned to the word size) will be reserved for memory managing.
// 3 bytes = 8 bits * 3 = 24 bits. It is enough for 24 words.
oC_HeapMap_t HeapMap = oC_MemMan_AllocateHeapMap( sizeof(uint8_t) * 100, &Allocator , __FUNCTION__, __LINE__ , oC_MemMan_AllocationFlags_Default);
// Now raw allocate 10 bytes
uint8_t * buffer= oC_MemMan_RawAllocate( &HeapMap , 10 * sizeof(uint8_t) , __FUNCTION__, __LINE__ , oC_MemMan_AllocationFlags_Default);
// Now release 10 bytes
oC_MemMan_RawFree( &HeapMap, buffer , 10 * sizeof(uint8_t));
}
The next feature of this module is diagnostic. It helps to check if some error occurs. The diagnostic functions should be called periodically. Each of them checks one problem, and generate events for it. For example, the oC_MemMan_CheckOverflow function checks, if the memory overflow problem is not occurring, and when it is, the event is generated. Moreover there is one function, called oC_MemMan_TestAndRepairMainHeap that tries to repair the module without loosing of data. Note, that this way is not safe. The module can only try to restore stability of work, but it does not provide, that data in allocated memory is correct. It is recommended to use it only for some special cases, when the machine cannot be restarted.

Function Documentation

void * oC_MemMan_AlignAddress ( const void *  Address)

The function is for align the address to the machine alignment. It works also when the module is disabled.

Parameters
AddressAddress to align

Definition at line 1159 of file oc_memman.c.

void * oC_MemMan_AlignAddressTo ( const void *  Address,
oC_UInt_t  Alignment 
)

The function is for align the address to the given alignment. It works also when the module is disabled.

Parameters
AddressAddress to align
AlignmentAlignment to align the address

Definition at line 1174 of file oc_memman.c.

oC_UInt_t oC_MemMan_AlignSize ( oC_UInt_t  Size)

The function is for align the size to the machine alignment. It works also when the module is disabled.

Parameters
SizeSize to align
Returns
aligned size

Definition at line 1222 of file oc_memman.c.

oC_UInt_t oC_MemMan_AlignSizeTo ( oC_UInt_t  Size,
oC_UInt_t  Alignment 
)

The function is for align the size to the given alignment. It works also when the module is disabled.

Parameters
SizeSize to align
AlignmentAlignment to align the size
Returns
aligned size

Definition at line 1239 of file oc_memman.c.

void * oC_MemMan_Allocate ( oC_UInt_t  Size,
Allocator_t  Allocator,
const char *  Function,
uint32_t  LineNumber,
AllocationFlags_t  Flags,
oC_UInt_t  Alignment 
)

This is malloc() type function for allocation of memory on the machine heap. Note, that every allocation require some additional memory to handle it on a list. It is something about 4 words, and moreover each allocation is aligned to the machine alignment. If you want to allocate more memory with the same size, it is recommended to use oC_MemMan_RawAllocate. Thanks to that you can save some memory. To use this function, the MemMan module must be correctly turned on. Moreover you must to prepare an allocator, which should be given as the function argument, and it cannot be NULL. If you do not know, if your allocator is correct, you can use function oC_MemMan_IsAllocatorCorrect. A pointer to the allocator should be given as Allocator argument. Remember to release all memory allocated, when it is not needed anymore by using a function oC_MemMan_Free.

Note
It is possible to fill allocated buffer with 0 values, by setting the #AllocationFlags_ZeroFill flag

Example of usage:

static const oC_MemMan_Allocator_t Allocator = { .Name = "Example" };
void main()
{
uint8_t count = 100;
uint8_t * buffer = oC_MemMan_Allocate( sizeof(uint8_t) * count , &Allocator , __LINE__ , AllocationFlags_NoWait );
for(uint8_t i = 0; i < count ; i++)
{
buffer[i] = i;
}
}
Parameters
SizeSize of the memory that is required
AllocatorPointer to the allocator structure
LineNumberNumber of line where the function is called (it should be set to LINE value )
FlagsAdditional flags of allocation. It can be set to #AllocationFlags_Default if it is not important to you. List of flags:
Flag name Description
AllocationFlags_ZeroFill Allocated memory will be filled by 0
AllocationFlags_NoWait If cannot do it know, do not wait
AllocationFlags_CanWait500Msecond If cannot do it know, wait maximum 500 ms
AllocationFlags_CanWait1Second If cannot do it know, wait maximum 1 second
AllocationFlags_CanWaitForever If cannot do it know, wait as much as needed
AlignmentAlignment of the allocation. Can be set to 0 for default. Note, that this variable must be multiply of the memory alignment (for example multiply of 4 on 32-bits architectures)
Returns
address of allocated memory on success, or NULL, if there was some error.

Definition at line 770 of file oc_memman.c.

oC_HeapMap_t oC_MemMan_AllocateHeapMap ( oC_UInt_t  Size,
Allocator_t  Allocator,
const char *  Function,
uint32_t  LineNumber,
AllocationFlags_t  Flags 
)

The function is for creating and initializing new heap map. The heap map can be used for saving memory in some cases (for example, when size of allocation is known every time during free'ing memory, and it is really small). This function reserve some heap space for future use in functions oC_MemMan_RawAllocate and oC_MemMan_RawFree. Note, that all memory in the heap map is allocated in the system for the Allocator given in this function. Look at description of the MemMan module for more informations. Remember, that each heap map, that was allocated using this function, must be free by oC_MemMan_FreeHeapMap when it is not needed anymore.

Parameters
SizeSize of the heap map to reserve. It must be more than 0. Remember, that some of this memory will be reserved for bit map, so you should set this to value (x + x/(8*sizeof(oC_UInt_t))) = Size, where the x is the size, that you will need for raw allocations.
AllocatorPointer to the allocator structure. It cannot be set to NULL!
LineNumberNumber of line, where the function is called. It is recommended to set it to LINE
FlagsFlags of this allocation.
Returns
address on heap to the heap map, when success, or NULL pointer, when there was some problem.

Definition at line 543 of file oc_memman.c.

void oC_MemMan_CheckMemoryExhausted ( void  )

The function is for checking and generating the memory exhausted event. It checks if size of free memory is greater than minimum. If not, the Memory Exhausted event is generated. Moreover, when the size of free memory is smaller than panic limit, then the #MemoryEventFlags_PanicMemoryExhausted event is generated. The function only works with enabled module.

Definition at line 385 of file oc_memman.c.

void oC_MemMan_CheckMemoryLeak ( void  )

The function is for checking and generating the memory leak fault. It try to find memory leakage, and generate a allocator event, when it suspects something.

Definition at line 425 of file oc_memman.c.

void oC_MemMan_CheckOverflow ( void  )

The function is for checking if there was an overflow event. It scans each allocated block in the memory to check if the overflow protection number was not overwritten. Of course it is not perfect way, but still better, than nothing. When the memory was overwritten, the protection magic number is written again, and buffer overflow event is generated for both: module and allocator handlers. The function only works with enabled module.

Definition at line 355 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_ConfigureExternalHeapMap ( void *  StartAddress,
oC_UInt_t  Size 
)

The function is for configuration of HeapMap that is stored in external RAM. It can be called only once after turning on module.

Parameters
StartAddressAddress of the external RAM
SizeSize of the external RAM
Returns
code of error or #oC_ErrorCode_None if success

Definition at line 1782 of file oc_memman.c.

bool oC_MemMan_FindOverflowedAllocation ( Allocator_t  Allocator,
oC_MemMan_AllocationStats_t outAllocationStat 
)

The function searches for a buffer that has been overflowed

Parameters
AllocatorAllocator to filter the results (or NULL if not used)
outAllocationStatDestination for a data of allocation
Returns
true if found

Definition at line 1743 of file oc_memman.c.

bool oC_MemMan_Free ( void *  Address,
AllocationFlags_t  Flags 
)

The function is for releasing memory that was allocated by function oC_MemMan_Allocate. The module must be enabled.

Parameters
AddressAddress from the oC_MemMan_Allocate function to release.
FlagsAdditional flags of allocation. It can be set to #AllocationFlags_Default if it is not important to you. List of flags:
Flag name Description
AllocationFlags_NoWait If cannot do it know, do not wait
AllocationFlags_CanWait500Msecond If cannot do it know, wait maximum 500 ms
AllocationFlags_CanWait1Second If cannot do it know, wait maximum 1 second
AllocationFlags_CanWaitForever If cannot do it know, wait as much as needed
Returns

Definition at line 908 of file oc_memman.c.

bool oC_MemMan_FreeAllMemoryOfAllocator ( Allocator_t  Allocator)

The function is for releasing all memory that was allocated for the Allocator. It is designed for situations, when for example some module will be turned off. It is not possible to stop this operation. It will be performed until all memory will be released.

Parameters
AllocatorPointer to the allocator structure, that memory should be released
Returns
true if success, false if there was some error while releasing memory.

Definition at line 985 of file oc_memman.c.

bool oC_MemMan_FreeHeapMap ( oC_HeapMap_t *  MapPointer,
AllocationFlags_t  Flags 
)

This is the function that should be called, when the heap map is not needed anymore. It release all memory allocated for the heap map. The module must be enabled for this function.

Parameters
MapPointerPointer to the heap map
FlagsAdditional flags of allocation. It can be set to #AllocationFlags_Default if it is not important to you. List of flags:
Flag name Description
AllocationFlags_NoWait If cannot do it know, do not wait
AllocationFlags_CanWait500Msecond If cannot do it know, wait maximum 500 ms
AllocationFlags_CanWait1Second If cannot do it know, wait maximum 1 second
AllocationFlags_CanWaitForever If cannot do it know, wait as much as needed
Returns
true if all memory allocated for the heap map was released.

Definition at line 596 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetAllocationBlockSize ( void  )

The function returns size of the block, that is needed for each allocation. It is important, that this size should be added to size of each allocation to get real size of the needed ram memory. This function can be useful to choose between allocation via standard allocation function or raw allocations (by using 'heap map').

Definition at line 1466 of file oc_memman.c.

Allocator_t oC_MemMan_GetAllocatorOfAddress ( const void *  Address)

The function is for getting information, about the Allocator that reserve the given address.

Note
The address must not be the start of the allocation. It also can be somewhere in the middle of the buffer

Example of usage:

const oC_MemMan_Allocator_t MyAllocator = {.Name = "MyAllocator"};
const oC_MemMan_Allocator_t YourAllocator = {.Name = "YourAllocator"};
bool IsMyBuffer( uint8_t * Address )
{
return oC_MemMan_GetAllocatorOfAddress( Address ) == &MyAllocator;
}
bool IsYourBuffer( uint8_t * Address )
{
return oC_MemMan_GetAllocatorOfAddress( Address ) == &YourAllocator;
}
void main()
{
uint8_t * myBuffer = oC_MemMan_Allocate( sizeof(uint8_t)*100,&MyAllocator,__LINE__,0);
uint8_t * yourBuffer = oC_MemMan_Allocate( sizeof(uint8_t)*100,&YourAllocator,__LINE__,0);
if(IsMyBuffer(&myBuffer[98]))
{
printf("This is my buffer!\n");
}
if(IsYourBuffer(&yourBuffer[98]))
{
printf("This is your buffer!\n");
}
}
Parameters
AddressAddress to find allocator
Returns
pointer to the allocator structure or NULL if not found (or module is not enabled)

Definition at line 1098 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetDmaRamHeapSize ( void  )

The function returns size of external ram or 0 if not connected

Definition at line 1419 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetExternalHeapSize ( void  )

The function returns size of external ram or 0 if not connected

Definition at line 1400 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetFlashSize ( void  )

The function returns size of the machine flash memory. It works also when the module is not enabled.

Definition at line 1323 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetFreeFlashSize ( void  )

The function returns size of the machine not used flash memory. It works also when the module is not enabled.

Definition at line 1359 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetFreeHeapMapSize ( oC_HeapMap_t  Map)

The function returns size of the free heap.

Parameters
MapPointer to the heap map created by function oC_MemMan_AllocateHeapMap

Definition at line 1504 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetFreeRamSize ( void  )

The function returns number of bytes that are already not used or 0 if module is not enabled.

Definition at line 1371 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetHeapMapSize ( oC_HeapMap_t  Map)

The function returns size of the heap map allocated by function oC_MemMan_AllocateHeapMap.

Parameters
MapPointer to the heap map created by function oC_MemMan_AllocateHeapMap

Definition at line 1482 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetMaximumAllocationSize ( void  )

The function returns maximum size that can be allocated by function oC_MemMan_Allocate. The module must be enabled to use this function.

Returns
size of maximum possible allocation in bytes.

Definition at line 1269 of file oc_memman.c.

float oC_MemMan_GetMemoryExhaustedLimit ( void  )

The function returns current percent limit of exhausted memory

Returns
percent value of limit

Definition at line 1840 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetMemoryOfAllocatorSize ( Allocator_t  Allocator)

The function is for reading size of memory that was allocated for the Allocator. Note, that each allocation require some additional bytes. This function returns real size of alloc

Definition at line 1439 of file oc_memman.c.

float oC_MemMan_GetPanicMemoryExhaustedLimit ( void  )

The function returns current percent panic limit of exhausted memory

Returns
percent value of panic limit

Definition at line 1851 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetRamSize ( void  )

The function returns size of the machine ram memory. It works also when the module is not enabled.

Definition at line 1335 of file oc_memman.c.

oC_UInt_t oC_MemMan_GetSizeOfAllocation ( const void *  Address)

The function returns size of memory, that was allocated at the given address. Note, that this function works only when memory was allocated by oC_MemMan_Allocate function, and there is not possible to get size of raw allocations from the oC_MemMan_RawAllocate function. Moreover, the address must point exactly to the start of the buffer.

Parameters
AddressAllocated address from the oC_MemMan_Allocate function.
Returns
size of allocation or 0 if not found or module is not turned on

Definition at line 1133 of file oc_memman.c.

bool oC_MemMan_IsAddressAligned ( const void *  Address)

Checks if the address given as argument is aligned to the machine alignment. It works also when the module is disabled.

Parameters
AddressAddress to check
Returns
true if aligned

Definition at line 1190 of file oc_memman.c.

bool oC_MemMan_IsAddressAlignedTo ( const void *  Address,
oC_UInt_t  Alignment 
)

Checks if the address given as argument is aligned to the given alignment. It works also when the module is disabled.

Parameters
AddressAddress to check
Returns
true if aligned

Definition at line 1206 of file oc_memman.c.

bool oC_MemMan_IsSizeAligned ( oC_UInt_t  Size)

The function is for checking if a size given as argument is aligned to the machine alignment. Works also with disabled module.

Parameters
SizeThe size to check
Returns
true if the Size is aligned to the machine alignment.

Definition at line 1255 of file oc_memman.c.

void * oC_MemMan_RawAllocate ( oC_HeapMap_t  Map,
oC_UInt_t  Size,
const char *  Function,
uint32_t  LineNumber,
AllocationFlags_t  Flags 
)

This function is for allocating a memory on the previously created by oC_MemMan_AllocateHeapMap function heap map. This allow to save some memory, that is needed for allocation handling, but it is less save than allocation by oC_MemMan_Allocate function. Moreover it is needed to give correct size of this allocation during releasing by oC_MemMan_RawFree. This function is recommended only in cases, when the memory allocation size is constant, and always known. The module must be enabled for this function.

See also
oC_MemMan_RawFree , oC_MemMan_AllocateHeapMap
Parameters
MapPointer to the heap map created by function oC_MemMan_AllocateHeapMap
SizeSize of the memory to allocate.
LineNumberNumber of line, where this function is called, it should be set to LINE value
FlagsFlags of allocation
Returns
pointer to the allocated memory from the Map heap.

Definition at line 643 of file oc_memman.c.

bool oC_MemMan_RawFree ( oC_HeapMap_t  Map,
void *  Address,
oC_UInt_t  Size 
)

The function is for releasing memory allocated on the heap map by function oC_MemMan_RawAllocate. Note, that raw allocations does not control the memory, so it is needed to give the correct size to release. If it will be not correct, there is a risk, that it the function release also the memory that is already taken by other allocation.

See also
oC_MemMan_AllocateHeapMap , oC_MemMan_RawAllocate
Parameters
MapPointer to the heap map created by function oC_MemMan_AllocateHeapMap
AddressAddress received from the oC_MemMan_RawAllocate function
SizeSize of the allocated memory.
Returns
true if all memory was released

Definition at line 692 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_ReadAllocationsStats ( Allocator_t  Allocator,
oC_MemMan_AllocationStats_t outAllocationsArray,
oC_UInt_t *  Size,
bool  JoinSimilar 
)

The function is for reading array of allocations for the given allocator

Parameters
AllocatorAllocator to read allocations
outAllocationsArrayArray for statistics
SizeSize of the array
JoinSimilarSet it to true if it should join similar allocations into 1 entry
Returns
code of error

Definition at line 1671 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_ReadAllocatorsStats ( oC_MemMan_AllocatorsStats_t outAllocatorsArray,
oC_UInt_t *  Size 
)

Reads statistics of memory

Parameters
AllocatorsArrayArray for statistics
SizeSize of the array
Returns
code of error

Definition at line 1604 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_SetEventHandler ( MemoryEventHandler_t  EventHandler)

The function is for setting the handler of events. It can be called only once after turning on the module.

Parameters
EventHandlerPointer to the function, that should be called, when some module event occurs.
Returns
One of following codes of errors:
Code Description
oC_ErrorCode_None There is no error
oC_ErrorCode_ModuleNotStartedYet The MemMan was not enabled before
oC_ErrorCode_WrongAddress Event handler pointer is not correct
oC_ErrorCode_InterruptHandlerAlreadySet The event handler is already set

Definition at line 1035 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_SetMemoryExhaustedLimit ( float  LimitPercent)

Configures limit of memory exhausted event

Parameters
LimitPercentLimit in percent
Returns
code of error

Definition at line 1865 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_SetPanicMemoryExhaustedLimit ( float  LimitPercent)

Configures limit of memory exhausted event

Parameters
LimitPercentLimit in percent
Returns
code of error

Definition at line 1890 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_TestAndRepairMainHeap ( oC_MemMan_DumpFunction_t  DumpFunction)

This function is created for special situations, when some error event occurs during work of module. It tests module state, and try to repair it, if it is possible. The function tests all pointers, checks ranges, and try to establish what is not correct. It try to repair module without loosing any data, but when it is not possible, the memory can be dumped using function given as argument DumpFunction. The function will return value oC_ErrorCode_None, when module is not damaged, or when the repair operation was successful without lost of any data. When during repair operation some data were lost, but module is repaired, the oC_ErrorCode_SomeDataLost code will be returned. When repair is not possible, then oC_ErrorCode_ModuleNeedRestart will be returned.

Parameters
DumpFunction[optional - NULL if not used] Pointer to the function for dumping data
Returns
code of error (look at description for more details)

Definition at line 449 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_TurnOff ( void  )

The function is for turning off the module. If the module is already not turned on, the oC_ErrorCode_ModuleNotStartedYet code will be returned. Note, that also in case of error, the module is treated as turned off. All allocated memory will be released, and the #MemoryEventFlags_MemoryReleased event will be called. While this function, also the #MemoryEventFlags_ModuleTurningOff event is generated to inform the system, that memory allocation is not possible anymore.

See also
oC_MemMan_TurnOn
Returns
one of following codes should be expected:
Code Description
oC_ErrorCode_None There is no error
oC_ErrorCode_ModuleNotStartedYet The MemMan was not enabled before
Other error codes are from the oC_MEM_LLD_TurnOffDriver function.

Definition at line 313 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_TurnOn ( void  )

The function is for turning on memory manager module. Note, that it also turns on #MEM-LLD module. The function protects before returning on this module. If module is already turned on, the oC_ErrorCode_ModuleIsTurnedOn will be returned. The module must be turned on before usage. It initialized pointers and interrupts that are assigned for the module.

Returns
one of following codes should be expected:
Code Description
oC_ErrorCode_None There is no error
oC_ErrorCode_ModuleIsTurnedOn The MemMan was enabled before
oC_ErrorCode_ModuleIsTestedAlready Tests of module are active now

Definition at line 251 of file oc_memman.c.

oC_ErrorCode_t oC_MemMan_UnconfigureExternalHeapMap ( void  )

The function is for deconfiguration of the external heap

Returns
code of error or #oC_ErrorCode_None if success

Definition at line 1809 of file oc_memman.c.