Choco OS
V.0.16.9.0
Join to the chocolate world
|
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) |
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.
Address | Address 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.
Address | Address to align |
Alignment | Alignment 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.
Size | Size to align |
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.
Size | Size to align |
Alignment | Alignment to align the 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.
Example of usage:
Size | Size of the memory that is required | ||||||||||||
Allocator | Pointer to the allocator structure | ||||||||||||
LineNumber | Number of line where the function is called (it should be set to LINE value ) | ||||||||||||
Flags | Additional flags of allocation. It can be set to #AllocationFlags_Default if it is not important to you. List of flags:
| ||||||||||||
Alignment | Alignment 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) |
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.
Size | Size 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. |
Allocator | Pointer to the allocator structure. It cannot be set to NULL! |
LineNumber | Number of line, where the function is called. It is recommended to set it to LINE |
Flags | Flags of this allocation. |
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.
StartAddress | Address of the external RAM |
Size | Size of the external RAM |
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
Allocator | Allocator to filter the results (or NULL if not used) |
outAllocationStat | Destination for a data of allocation |
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.
Address | Address from the oC_MemMan_Allocate function to release. | ||||||||||
Flags | Additional flags of allocation. It can be set to #AllocationFlags_Default if it is not important to you. List of flags:
|
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.
Allocator | Pointer to the allocator structure, that memory should be released |
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.
MapPointer | Pointer to the heap map | ||||||||||
Flags | Additional flags of allocation. It can be set to #AllocationFlags_Default if it is not important to you. List of flags:
|
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.
Example of usage:
Address | Address to find allocator |
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.
Map | Pointer 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.
Map | Pointer 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.
Definition at line 1269 of file oc_memman.c.
float oC_MemMan_GetMemoryExhaustedLimit | ( | void | ) |
The function returns current percent limit of exhausted memory
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
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.
Address | Allocated address from the oC_MemMan_Allocate function. |
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.
Address | Address to check |
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.
Address | Address to check |
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.
Size | The size to check |
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.
Map | Pointer to the heap map created by function oC_MemMan_AllocateHeapMap |
Size | Size of the memory to allocate. |
LineNumber | Number of line, where this function is called, it should be set to LINE value |
Flags | Flags of allocation |
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.
Map | Pointer to the heap map created by function oC_MemMan_AllocateHeapMap |
Address | Address received from the oC_MemMan_RawAllocate function |
Size | Size of the allocated memory. |
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
Allocator | Allocator to read allocations |
outAllocationsArray | Array for statistics |
Size | Size of the array |
JoinSimilar | Set it to true if it should join similar allocations into 1 entry |
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
AllocatorsArray | Array for statistics |
Size | Size of the array |
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.
EventHandler | Pointer to the function, that should be called, when some module event occurs. |
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
LimitPercent | Limit in percent |
Definition at line 1865 of file oc_memman.c.
oC_ErrorCode_t oC_MemMan_SetPanicMemoryExhaustedLimit | ( | float | LimitPercent | ) |
Configures limit of memory exhausted event
LimitPercent | Limit in percent |
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.
DumpFunction | [optional - NULL if not used] Pointer to the function for dumping data |
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.
Code | Description |
---|---|
oC_ErrorCode_None | There is no error |
oC_ErrorCode_ModuleNotStartedYet | The MemMan was not enabled before |
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.
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
Definition at line 1809 of file oc_memman.c.