32 #include <oc_memory_cfg.h> 46 #define _________________________________________LOCAL_DEFINITIONS_SECTION_________________________________________________________________ 54 #define OVERFLOW_PROTECTION_MAGIC_NUMBER ((oC_UInt_t)0xfeedface) 76 #define foreach_block(block) for(Block_t * block = BlockListHead; (block != NULL); block = block->Next) 95 #define LAST_WORD_OF_BUFFER(Buffer,Size) ((oC_UInt_t*)Buffer)[ALIGN_SIZE(Size,oC_MEM_LLD_MEMORY_ALIGNMENT)/sizeof(oC_UInt_t)] 102 #define ALIGN_SIZE(SIZE,ALIGNMENT) ((((oC_UInt_t)SIZE) + ALIGNMENT - 1) & ~(ALIGNMENT-1)) 104 #undef _________________________________________LOCAL_DEFINITIONS_SECTION_________________________________________________________________ 111 #define _________________________________________LOCAL_TYPES_SECTION________________________________________________________________________ 118 typedef struct _Block_t
120 struct _Block_t * Next;
124 const char * Function;
126 AllocationFlags_t AllocationFlags;
155 typedef struct _HeapMap_t
157 struct _HeapMap_t * Self;
158 uint8_t * BitMapStart;
160 oC_UInt_t * HeapStart;
164 #undef _________________________________________LOCAL_TYPES_SECTION________________________________________________________________________ 171 #define _________________________________________LOCAL_FUNCTIONS_PROTOTYPES_SECTION_________________________________________________________ 173 static bool BlockModule ( AllocationFlags_t Flags );
175 static bool WaitForMemory (
HeapMap_t * Map , oC_UInt_t Size , oC_UInt_t Alignment , AllocationFlags_t Flags );
177 static oC_ErrorCode_t
InitializeHeapMap (
HeapMap_t * Map ,
void * HeapStartPointer ,
void * HeapEndPointer , oC_UInt_t HeapSize ,
bool FillZero );
193 static void *
RawAlloc (
HeapMap_t * Map , oC_UInt_t Size , oC_UInt_t Alignment );
197 static void CallEvent (
void * Address , MemoryEventFlags_t EventFlags ,
const char * Function, uint32_t LineNumber );
202 #undef _________________________________________LOCAL_FUNCTIONS_PROTOTYPES_SECTION_________________________________________________________ 208 #define _________________________________________LOCAL_VARIABLES_SECTION____________________________________________________________________ 221 static float PanicMemoryExhaustedLimit = CFG_PERCENT_PANIC_MEMORY_EXHAUSTED_LIMIT;
222 static float DefaultMemoryExhaustedLimit = CFG_PERCENT_DEFAULT_MEMORY_EXHAUSTED_LIMIT;
224 #undef _________________________________________LOCAL_VARIABLES_SECTION____________________________________________________________________ 231 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 253 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
261 if(errorCode == oC_ErrorCode_None || errorCode == oC_ErrorCode_ModuleIsTurnedOn)
276 errorCode = oC_ErrorCode_None;
282 errorCode = oC_ErrorCode_ModuleIsTestedAlready;
287 errorCode = oC_ErrorCode_ModuleIsTurnedOn;
315 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
325 CallAllocatorEvent(block->Allocator, block->Address, MemoryEventFlags_MemoryReleased, block->Function, block->LineNumber);
335 errorCode = oC_ErrorCode_ModuleIsTestedAlready;
340 errorCode = oC_ErrorCode_ModuleNotStartedYet;
369 CallAllocatorEvent(block->Allocator,block->Address,MemoryEventFlags_BufferOverflow,block->Function,block->LineNumber);
370 CallEvent(block->Address,MemoryEventFlags_BufferOverflow,block->Function,block->LineNumber);
392 if((freeSize/size) < PanicMemoryExhaustedLimit)
396 else if((freeSize/size) < DefaultMemoryExhaustedLimit)
405 if((externalFreeSize/externalSize) < PanicMemoryExhaustedLimit)
407 CallEvent(
NULL,MemoryEventFlags_PanicExternalMemoryExhausted,
"",0);
409 else if((externalFreeSize/externalSize) < DefaultMemoryExhaustedLimit)
411 CallEvent(
NULL,MemoryEventFlags_ExternalMemoryExhausted,
"",0);
451 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
461 if(errorCode == oC_ErrorCode_None)
481 errorCode = oC_ErrorCode_SomeDataLost;
482 CallAllocatorEvent(block->Allocator, block->Address, MemoryEventFlags_MemoryFault,block->Function, block->LineNumber);
483 CallAllocatorEvent(block->Allocator, block->Address, MemoryEventFlags_MemoryReleased, block->Function, block->LineNumber);
488 if( errorCode == oC_ErrorCode_ModuleNeedRestart || errorCode == oC_ErrorCode_SomeDataLost )
493 if ( errorCode == oC_ErrorCode_None || errorCode == oC_ErrorCode_SomeDataLost)
495 for(uint8_t * bitMapPointer =
HeapMap.BitMapStart;bitMapPointer<
HeapMap.BitMapEnd;bitMapPointer++)
517 errorCode = oC_ErrorCode_ModuleNotStartedYet;
545 oC_HeapMap_t heapMap =
NULL;
551 if(heapBuffer !=
NULL)
554 void * heapBufferEnd = heapBuffer + Size;
558 if(oC_ErrorOccur(
InitializeHeapMap(heapMap , heapBuffer , heapBufferEnd , Size ,
true) ))
598 bool allMemoryReleased =
false;
604 void * heapBuffer = HeapMap->BitMapStart;
606 allMemoryReleased =
true;
610 allMemoryReleased =
false;
615 allMemoryReleased =
false;
620 return allMemoryReleased;
643 void *
oC_MemMan_RawAllocate( oC_HeapMap_t Map , oC_UInt_t Size ,
const char * Function, uint32_t LineNumber , AllocationFlags_t Flags )
645 void * Address =
NULL;
658 block->AllocationFlags = Flags;
660 CallAllocatorEvent( block->Allocator,Address , MemoryEventFlags_RawMemoryAllocated, Function, LineNumber );
664 CallAllocatorEvent( block->Allocator,Address , MemoryEventFlags_AllocationError , Function, LineNumber );
704 if(
RawFree( Map , Address , Size))
707 CallAllocatorEvent(block->Allocator,Address , MemoryEventFlags_RawMemoryReleased , block->Function, block->LineNumber);
711 CallAllocatorEvent(block->Allocator,Address , MemoryEventFlags_ReleaseError , block->Function, block->LineNumber);
770 void *
oC_MemMan_Allocate( oC_UInt_t Size ,
Allocator_t Allocator ,
const char * Function, uint32_t LineNumber , AllocationFlags_t Flags , oC_UInt_t Alignment )
772 void * Address =
NULL;
784 ifnot(Flags & (AllocationFlags_UseExternalRam | AllocationFlags_UseInternalRam | AllocationFlags_UseDmaRam))
786 Flags |= AllocationFlags_UseExternalRam | AllocationFlags_UseInternalRam;
795 kdebuglog(oC_LogType_Error,
"MemMan::Allocate - Allocator named '%s' has exhausted the limit\n", Allocator->
Name);
838 Address =
RawAlloc(heapMap , Size +
sizeof(oC_UInt_t) , Alignment );
846 block->Address = Address;
848 block->Function = Function;
849 block->LineNumber = LineNumber;
852 block->AllocationFlags = Flags;
854 if(Flags & AllocationFlags_ZeroFill)
856 for(oC_UInt_t BufferIndex = 0 ; BufferIndex < Size ; BufferIndex++ )
858 ((uint8_t*)Address)[BufferIndex] = 0;
910 bool memoryReleased =
false;
921 CallAllocatorEvent(block->Allocator , Address , MemoryEventFlags_MemoryReleased , block->Function, block->LineNumber );
926 previousBlock->Next = block->Next;
946 memoryReleased =
true;
948 if(!
RawFree(heapMap , Address , block->Size +
sizeof(oC_UInt_t)))
950 memoryReleased =
false;
955 memoryReleased =
false;
958 if(memoryReleased ==
false)
960 CallAllocatorEvent(block->Allocator, Address, MemoryEventFlags_ReleaseError, block->Function, block->LineNumber);
965 previousBlock = block;
970 return memoryReleased;
1001 if(block->Allocator == Allocator)
1005 if(!
oC_MemMan_Free(block->Address,AllocationFlags_CanWaitForever))
1012 }
while(found_block);
1037 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1040 oC_AssignErrorCodeIfFalse(&errorCode,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet) &&
1043 oC_AssignErrorCodeIfFalse(&errorCode,
ModuleEventHandler ==
NULL , oC_ErrorCode_InterruptHandlerAlreadySet)
1047 errorCode = oC_ErrorCode_None;
1113 allocator = block->Allocator;
1208 return ((
void*)
ALIGN_SIZE(Address,Alignment) == Address);
1271 oC_UInt_t maximumAllocationSize = 0;
1275 oC_UInt_t * heapPointer =
HeapMap.HeapStart;
1283 oC_ARRAY_FOREACH_IN_ARRAY(heapMaps,heapMap)
1295 for(;(heapPointer < (*heapMap)->HeapEnd) && !
IsHeapUsed(*heapMap,heapPointer);heapPointer++)
1297 size +=
sizeof(oC_UInt_t);
1304 if(size > maximumAllocationSize)
1306 maximumAllocationSize = size;
1309 }
while(heapPointer < (*heapMap)->HeapEnd);
1313 return maximumAllocationSize;
1373 oC_UInt_t freeRamSize = 0;
1402 oC_UInt_t externalSize = 0;
1409 return externalSize;
1421 oC_UInt_t dmaSize = 0;
1447 if(block->Allocator == Allocator)
1449 size +=
sizeof(
Block_t) + block->Size;
1559 return dynamicAllocatedAddress;
1606 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1609 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet) &&
1610 oC_AssignErrorCodeIfFalse(&errorCode ,
oC_MemMan_IsRamAddress(outAllocatorsArray) , oC_ErrorCode_OutputAddressNotInRAM) &&
1611 oC_AssignErrorCodeIfFalse(&errorCode , isram(Size) , oC_ErrorCode_AddressNotInRam) &&
1612 oC_AssignErrorCodeIfFalse(&errorCode , (*Size) > 0 , oC_ErrorCode_SizeNotCorrect)
1615 oC_UInt_t arrayIndex = 0;
1619 errorCode = oC_ErrorCode_None;
1623 bool existOnArray =
false;
1625 oC_ARRAY_FOREACH_IN_ARRAY_WITH_SIZE(outAllocatorsArray,arrayIndex,stats)
1627 if(stats->Allocator == block->Allocator)
1629 existOnArray =
true;
1636 if(arrayIndex < *Size)
1638 outAllocatorsArray[arrayIndex].Allocator = block->Allocator;
1644 errorCode = oC_ErrorCode_OutputArrayToSmall;
1673 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1676 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet) &&
1677 oC_AssignErrorCodeIfFalse(&errorCode ,
oC_MemMan_IsRamAddress(outAllocationsArray) , oC_ErrorCode_OutputAddressNotInRAM) &&
1678 oC_AssignErrorCodeIfFalse(&errorCode , isram(Size) , oC_ErrorCode_AddressNotInRam) &&
1679 oC_AssignErrorCodeIfFalse(&errorCode , (*Size) > 0 , oC_ErrorCode_SizeNotCorrect)
1682 oC_UInt_t arrayIndex = 0;
1686 errorCode = oC_ErrorCode_None;
1690 if(block->Allocator == Allocator)
1694 if(JoinSimilar ==
true)
1696 oC_ARRAY_FOREACH_IN_ARRAY_WITH_SIZE(outAllocationsArray,arrayIndex,stat)
1698 if(stat->Function == block->Function && stat->LineNumber == block->LineNumber)
1700 stat->Size += block->Size;
1707 outAllocationsArray[arrayIndex].Address = block->Address;
1708 outAllocationsArray[arrayIndex].Function = block->Function;
1709 outAllocationsArray[arrayIndex].LineNumber = block->LineNumber;
1710 outAllocationsArray[arrayIndex].Size = block->Size;
1716 if(arrayIndex >= (*Size))
1751 if(block->Allocator == Allocator || Allocator ==
NULL)
1755 outAllocationStat->Address = block->Address;
1756 outAllocationStat->Function = block->Function;
1757 outAllocationStat->LineNumber = block->LineNumber;
1758 outAllocationStat->Overflowed =
true;
1759 outAllocationStat->Size = block->Size;
1784 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1787 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet ) &&
1789 oC_AssignErrorCodeIfFalse(&errorCode , Size > 0 , oC_ErrorCode_SizeNotCorrect ) &&
1791 oC_AssignErrorCodeIfFalse(&errorCode ,
IsMemoryValid(StartAddress,Size) , oC_ErrorCode_CannotAccessMemory )
1811 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1814 oC_AssignErrorCodeIfFalse(&errorCode ,
ModuleEnabledFlag , oC_ErrorCode_ModuleNotStartedYet ) &&
1818 errorCode = oC_ErrorCode_None;
1824 ErrorCondition(
oC_MemMan_Free(block->Address,AllocationFlags_CanWaitForever),oC_ErrorCode_ReleaseError);
1842 return DefaultMemoryExhaustedLimit * 100;
1853 return PanicMemoryExhaustedLimit * 100;
1867 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1871 ErrorCondition(LimitPercent >= 0 && LimitPercent <= 100 , oC_ErrorCode_WrongParameters)
1874 DefaultMemoryExhaustedLimit = LimitPercent / 100;
1875 errorCode = oC_ErrorCode_None;
1892 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
1896 ErrorCondition(LimitPercent >= 0 && LimitPercent <= 100 , oC_ErrorCode_WrongParameters)
1899 PanicMemoryExhaustedLimit = LimitPercent / 100;
1900 errorCode = oC_ErrorCode_None;
1906 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 1914 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ 1925 bool success =
false;
1927 if(Flags & AllocationFlags_ForceBlock)
1929 oC_IntMan_EnterCriticalSection();
1932 oC_IntMan_ExitCriticalSection();
1934 else if(Flags & AllocationFlags_NoWait)
1936 oC_IntMan_EnterCriticalSection();
1942 oC_IntMan_ExitCriticalSection();
1946 oC_IntMan_EnterCriticalSection();
1949 oC_IntMan_ExitCriticalSection();
1951 oC_Thread_t currentThread = oC_ThreadMan_GetCurrentThread();
1955 oC_Time_t timeout = 0;
1957 if(Flags & AllocationFlags_CanWaitForever)
1959 timeout = oC_hour(1);
1961 else if(Flags & AllocationFlags_CanWait1Second)
1967 timeout = oC_ms(500);
1970 if(oC_Thread_SetBlocked(currentThread,(uint32_t*)&
ModuleBusyFlag,oC_Thread_Unblock_WhenEqual,
false,oC_Thread_UnblockMask_All,timeout))
1972 while(oC_Thread_IsBlocked(currentThread));
1974 oC_Thread_SetUnblocked(currentThread);
1976 oC_IntMan_EnterCriticalSection();
1979 oC_IntMan_ExitCriticalSection();
1988 oC_IntMan_ExitCriticalSection();
2004 bool success =
false;
2006 oC_IntMan_EnterCriticalSection();
2012 oC_IntMan_ExitCriticalSection();
2024 bool memoryAvailable =
false;
2025 oC_Thread_t thread = oC_ThreadMan_GetCurrentThread();
2029 oC_Time_t timeout = 0;
2030 oC_Time_t checkingTimeStep = 0;
2031 oC_Time_t startTime = oC_KTime_GetTimestamp();
2032 oC_Time_t currentTime = startTime;
2034 if(Flags & AllocationFlags_CanWaitForever)
2036 timeout = startTime + oC_hour(1);
2037 checkingTimeStep = oC_min(1);
2039 else if(Flags & AllocationFlags_CanWait1Second)
2041 timeout = startTime + oC_s(1);
2042 checkingTimeStep = oC_ms(100);
2044 else if(Flags & AllocationFlags_NoWait)
2046 timeout = startTime;
2047 checkingTimeStep = 0;
2051 timeout = startTime + oC_ms(500);
2052 checkingTimeStep = oC_ms(100);
2059 if(!memoryAvailable)
2061 oC_Thread_Sleep(thread,checkingTimeStep);
2064 currentTime = oC_KTime_GetTimestamp();
2065 }
while(currentTime < timeout && memoryAvailable ==
false);
2072 return memoryAvailable;
2086 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
2097 heapPointer +=
sizeof(uint32_t);
2105 if(dmaRamStart ==
NULL)
2107 errorCode = oC_ErrorCode_None;
2111 && ErrorCondition( dmaRamSize > 0 , oC_ErrorCode_SizeNotCorrect )
2135 static oC_ErrorCode_t
InitializeHeapMap(
HeapMap_t * Map ,
void * HeapStartPointer ,
void * HeapEndPointer , oC_UInt_t HeapSize ,
bool FillZero )
2137 oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
2142 Map->BitMapStart = HeapStartPointer;
2144 Map->HeapStart = (oC_UInt_t*)Map->BitMapEnd;
2145 Map->HeapEnd = HeapEndPointer;
2148 for(uint8_t * heapPointer = Map->BitMapStart; heapPointer < (uint8_t*)Map->BitMapEnd;heapPointer++)
2155 for(uint8_t * heapPointer = HeapStartPointer;heapPointer < (uint8_t*)HeapEndPointer; heapPointer++)
2161 errorCode = oC_ErrorCode_None;
2165 errorCode = oC_ErrorCode_MachineHeapError;
2184 oC_IntMan_EnterCriticalSection();
2188 if(block->Address == Address)
2190 blockToReturn = block;
2195 oC_IntMan_ExitCriticalSection();
2197 return blockToReturn;
2215 if( (Address >= block->Address) && (Address < (block->Address + block->Size)))
2217 blockToReturn = block;
2222 return blockToReturn;
2237 oC_ASSERT(Map->HeapStart <= HeapPointer);
2238 return (oC_UInt_t)(HeapPointer - Map->HeapStart);
2253 return (Address >= ((
void*)Map->HeapStart)) && (Address < ((
void*)Map->HeapEnd));
2277 oC_UInt_t bitMapIndex= heapIndex / 8;
2278 oC_UInt_t bitIndex = heapIndex % 8;
2288 return (Map->Self == Map );
2300 for(oC_UInt_t * heapPointer = Map->HeapStart ; heapPointer < Map->HeapEnd ; heapPointer++ )
2302 DumpFunction(*heapPointer);
2315 oC_UInt_t bitMapIndex= heapIndex / 8;
2316 oC_UInt_t bitIndex = heapIndex % 8;
2335 bool stateCorrect =
true;
2337 for(oC_UInt_t * heapPointer = HeapFrom; heapPointer < HeapTo ; heapPointer++)
2341 stateCorrect =
false;
2346 return stateCorrect;
2356 for(oC_UInt_t * heapPointer = HeapFrom; (heapPointer < HeapTo) && (heapPointer < Map->HeapEnd) ; heapPointer++)
2369 if(HeapEndLimit ==
NULL)
2371 HeapEndLimit = Map->HeapEnd;
2374 while((HeapPointer < Map->HeapEnd) && (HeapPointer < HeapEndLimit) && (HeapState !=
IsHeapUsed( Map , HeapPointer)))
2391 for(oC_UInt_t * heapPointer = Map->HeapStart;heapPointer<Map->HeapEnd;heapPointer++)
2395 size +=
sizeof(oC_UInt_t);
2409 return ((oC_UInt_t)Map->HeapEnd) - ((oC_UInt_t)Map->HeapStart);
2419 void * address =
NULL;
2420 void * heapFrom = Map->HeapStart;
2421 void * heapTo =
NULL;
2422 void * heapToLimit =
NULL;
2423 oC_UInt_t foundSize = 0;
2425 while((heapFrom < ((
void*)Map->HeapEnd)) && (heapToLimit < ((
void*)Map->HeapEnd)) && (address ==
NULL))
2431 heapToLimit = heapFrom +
ALIGN_SIZE(Size,Alignment) +
sizeof(oC_UInt_t);
2435 if(heapTo == Map->HeapEnd || heapTo == heapToLimit)
2437 heapTo-=
sizeof(oC_UInt_t);
2440 foundSize = (oC_UInt_t)(heapTo - heapFrom);
2454 heapFrom +=
sizeof(oC_UInt_t);
2469 void * heapFrom = address;
2470 void * heapTo = address +
ALIGN_SIZE(Size,Alignment);
2487 bool memoryReleased =
false;
2496 memoryReleased =
true;
2500 return memoryReleased;
2510 bool memoryOk =
true;
2511 uint8_t* memoryArray = Start;
2512 oC_UInt_t sizeStepIndex = 0;
2513 uint8_t valueToWrite = 0;
2514 bool writeFF =
false;
2515 oC_UInt_t sizeSteps[] = {
2526 for(uint32_t i = 0 ; i < Size ; i+= sizeSteps[sizeStepIndex++])
2528 valueToWrite = writeFF ? 0xFF : (uint8_t)(i & 0xFF);
2529 memoryArray[i] = valueToWrite;
2541 for(uint32_t i = 0 ; i < Size ; i+= sizeSteps[sizeStepIndex++])
2543 valueToWrite = writeFF ? 0xFF : (uint8_t)(i & 0xFF);
2545 if(memoryArray[i] != valueToWrite)
2547 kdebuglog(oC_LogType_Error,
"MemMan: External memory access error - (%p) %u != %u\n", &memoryArray[i] , (
unsigned int)memoryArray[i] , valueToWrite );
2575 Allocator->
EventHandler( Address, EventFlags ,Function ,LineNumber );
2584 static void CallEvent(
void * Address , MemoryEventFlags_t EventFlags ,
const char * Function, uint32_t LineNumber)
2619 bool releaseAllowed =
false;
2621 if(Block->AllocationFlags & AllocationFlags_ReleaseOnlyInCore)
2627 releaseAllowed =
true;
2630 return releaseAllowed;
2634 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________ bool oC_MemMan_IsAllocatorCorrect(Allocator_t Allocator)
checks if allocator is correct
#define ALIGN_SIZE(SIZE, ALIGNMENT)
static bool oC_Bits_AreBitsSetU32(uint32_t BitMask, uint32_t BitsToCheck)
checks if all bits in field are set
static bool ModuleEnabledFlag
bool oC_MEM_LLD_IsUsedFlashAddress(const void *Address)
checks if the pointer is in used flash section
static bool WaitForMemory(HeapMap_t *Map, oC_UInt_t Size, oC_UInt_t Alignment, AllocationFlags_t Flags)
#define oC_ARRAY_SIZE(ARRAY)
returns size of static array
static void * RawAlloc(HeapMap_t *Map, oC_UInt_t Size, oC_UInt_t Alignment)
bool oC_MemMan_FreeHeapMap(oC_HeapMap_t *Map, AllocationFlags_t Flags)
release heap map
void(* oC_MemMan_DumpFunction_t)(oC_UInt_t Data)
stores pointer to function for dumping data
void * oC_MemMan_AlignAddressTo(const void *Address, oC_UInt_t Alignment)
returns address aligned to the given alignment.
oC_ErrorCode_t oC_MemMan_TurnOff(void)
turns off the module
void * oC_MEM_LLD_GetDataEndAddress(void)
returns end address of the data section
static HeapMap_t ExternalHeapMap
struct _HeapMap_t HeapMap_t
oC_ErrorCode_t oC_MEM_LLD_SetBusFaultInterrupt(oC_MEM_LLD_Interrupt_t Interrupt)
sets interrupt handler for bus fault
float oC_MemMan_GetPanicMemoryExhaustedLimit(void)
oC_UInt_t oC_MemMan_GetFreeFlashSize(void)
returns size of the machine not used flash
bool oC_MemMan_IsRamAddress(const void *Address)
checks if address is in ram section
identifier for allocations
oC_ErrorCode_t oC_MemMan_UnconfigureExternalHeapMap(void)
unconfigures external heap
#define LAST_WORD_OF_BUFFER(Buffer, Size)
oC_UInt_t oC_MemMan_AlignSizeTo(oC_UInt_t Size, oC_UInt_t Alignment)
returns size aligned to the given alignment
oC_UInt_t oC_MemMan_GetMaximumAllocationSize(void)
returns maximum size of allocation
static void DumpHeapMap(HeapMap_t *Map, oC_MemMan_DumpFunction_t DumpFunction)
static uint32_t ModuleBusyFlag
bool oC_MemMan_FreeAllMemoryOfAllocator(Allocator_t Allocator)
release all memory of allocator
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
#define foreach_block(block)
bool oC_MemMan_IsStaticRamAddress(const void *Address)
checks if address is in static used ram section (data section)
oC_ErrorCode_t oC_MEM_LLD_TurnOffDriver(void)
release the driver
static void SetHeapState(HeapMap_t *Map, oC_UInt_t *HeapPointer, HeapState_t HeapState)
#define OVERFLOW_PROTECTION_MAGIC_NUMBER
oC_UInt_t oC_MemMan_GetSizeOfAllocation(const void *Address)
returns size of allocation
static oC_UInt_t GetSizeOfHeapInState(HeapMap_t *Map, HeapState_t HeapState)
bool oC_MEM_LLD_IsExternalAddress(const void *Address)
checks if the pointer is in external section
oC_ErrorCode_t oC_MemMan_SetPanicMemoryExhaustedLimit(float LimitPercent)
void * oC_MEM_LLD_GetDmaRamStartAddress(void)
returns start address of the DMA RAM
float oC_MemMan_GetMemoryExhaustedLimit(void)
bool oC_MemMan_RawFree(oC_HeapMap_t Map, void *Address, oC_UInt_t Size)
release memory in heap map
oC_UInt_t oC_MemMan_GetHeapMapSize(oC_HeapMap_t Map)
returns size of heap map
static void SetHeapStateInRange(HeapMap_t *Map, oC_UInt_t *HeapFrom, oC_UInt_t *HeapTo, HeapState_t HeapState)
static bool IsAddressOfHeapMap(HeapMap_t *Map, const void *Address)
oC_UInt_t oC_MemMan_GetExternalHeapSize(void)
returns size of external ram
static bool UnblockModule(void)
bool oC_MEM_LLD_IsFlashAddress(const void *Address)
checks if the pointer is in flash section
#define B(Bytes)
Number of bytes.
oC_ErrorCode_t oC_MEM_LLD_TurnOnBusFaultInterrupt(void)
turns on bus fault interrupt
The file with LLD interface for the MEM driver.
static uint8_t oC_Bits_ClearBitU8(uint8_t *outVariable, uint8_t BitIndex)
clear selected bit
static oC_UInt_t GetSizeOfHeap(HeapMap_t *Map)
MemoryEventHandler_t EventHandler
oC_ErrorCode_t oC_MEM_LLD_TurnOnDriver(void)
initializes the driver to work
static void CallAllocatorEvent(Allocator_t Allocator, void *Address, MemoryEventFlags_t EventFlags, const char *Function, uint32_t LineNumber)
void * oC_MEM_LLD_GetHeapEndAddress(void)
returns end address of the heap
oC_UInt_t oC_MemMan_GetFreeHeapMapSize(oC_HeapMap_t Map)
returns size of free memory in heap map
static bool BlockModule(AllocationFlags_t Flags)
static bool oC_Bits_IsBitSetU8(uint8_t BitMask, uint8_t BitIndex)
checks if bit is set
oC_ErrorCode_t oC_MemMan_TurnOn(void)
turns on memory manager
oC_ErrorCode_t oC_MemMan_ConfigureExternalHeapMap(void *StartAddress, oC_UInt_t Size)
prepares HeapMap stored in external RAM
oC_MEM_LLD_Size_t oC_MEM_LLD_GetUsedFlashSize(void)
returns size of the used flash section
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
oC_MEM_LLD_Size_t oC_MEM_LLD_GetDmaRamSize(void)
returns size of the DMA ram
oC_UInt_t oC_MemMan_GetAllocationBlockSize(void)
returns size of block needed for allocation
bool oC_MemMan_IsDynamicAllocatedAddress(const void *Address)
checks if address is in dynamic allocated section
bool oC_MemMan_IsAddressCorrect(const void *Address)
checks if address is correct - in RAM or in FLASH
oC_UInt_t oC_MemMan_GetFlashSize(void)
returns size of the machine flash
bool oC_MemMan_IsAddressAlignedTo(const void *Address, oC_UInt_t Alignment)
checks if address is aligned to given alignment
oC_ErrorCode_t oC_MemMan_ReadAllocatorsStats(oC_MemMan_AllocatorsStats_t *outAllocatorsArray, oC_UInt_t *Size)
Reads allocators statistics array.
static bool IsHeapUsed(HeapMap_t *Map, oC_UInt_t *HeapPointer)
Allocator_t oC_MemMan_GetAllocatorOfAddress(const void *Address)
returns allocator of address
static bool ModuleTestModeEnabledFlag
Memory controller is configured to allow for memory access for regions that can be accessible by a pr...
bool oC_MemMan_IsAddressAligned(const void *Address)
checks if address is aligned
bool oC_MEM_LLD_IsHeapAddress(const void *Address)
checks if the pointer is in heap section
bool oC_MemMan_FindOverflowedAllocation(Allocator_t Allocator, oC_MemMan_AllocationStats_t *outAllocationStat)
searches for a overflowed buffer
static MemoryEventHandler_t ModuleEventHandler
The file with interface for interrupt manager.
void oC_MemMan_CheckMemoryLeak(void)
checks if memory is not leaking
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.
oC_UInt_t oC_MemMan_GetFreeRamSize(void)
returns size of free ram
static uint32_t * DataOverflowProtection
oC_UInt_t oC_MemMan_AlignSize(oC_UInt_t Size)
returns size aligned to the machine alignment
static bool IsBlockCorrect(Block_t *Block)
oC_UInt_t oC_MemMan_GetMemoryOfAllocatorSize(Allocator_t Allocator)
returns size of allocations per allocator
bool oC_MemMan_Free(void *Address, AllocationFlags_t Flags)
release allocated memory
oC_UInt_t oC_MemMan_GetDmaRamHeapSize(void)
returns size of external ram
static void * FindFreeHeap(HeapMap_t *Map, oC_UInt_t Size, oC_UInt_t Alignment)
static Block_t * BlockListHead
oC_MEM_LLD_Size_t oC_MEM_LLD_GetRamSize(void)
returns size of the ram
oC_MEM_LLD_Size_t oC_MEM_LLD_GetHeapSize(void)
returns size of the heap
oC_MEM_LLD_Size_t oC_MEM_LLD_GetFlashSize(void)
returns size of the flash section
The file with functions for the bits operation.
oC_ErrorCode_t oC_MemMan_SetMemoryExhaustedLimit(float LimitPercent)
oC_UInt_t oC_MemMan_GetRamSize(void)
returns size of the machine ram
static oC_ErrorCode_t InitializePointers(bool FillZero)
static oC_UInt_t GetIndexOfHeapPointer(HeapMap_t *Map, oC_UInt_t *HeapPointer)
bool oC_MemMan_IsUsedFlashAddress(const void *Address)
checks if address is in used flash section
Static array definitions.
oC_ErrorCode_t oC_MemMan_TestAndRepairMainHeap(oC_MemMan_DumpFunction_t DumpFunction)
diagnoses main heap
#define oC_MEM_LLD_MEMORY_ALIGNMENT
number of bytes in memory alignment
static Block_t * FindBlockContainsAddress(const void *Address)
void * oC_MEM_LLD_GetHeapStartAddress(void)
returns start address of the heap
The file with memory manager interface.
bool oC_MemMan_IsSizeAligned(oC_UInt_t Size)
checks if a size is aligned
void * oC_MemMan_AlignAddress(const void *Address)
returns address aligned to the machine alignment.
static void CallEvent(void *Address, MemoryEventFlags_t EventFlags, const char *Function, uint32_t LineNumber)
oC_MEM_LLD_MemoryAccessMode_t oC_MEM_LLD_GetMemoryAccessMode(void)
returns currently configured memory access mode
static void BusFaultInterrupt(void)
Definition of the null pointer.
static const oC_Allocator_t Allocator
oC_ErrorCode_t oC_MEM_LLD_SetMemoryFaultInterrupt(oC_MEM_LLD_Interrupt_t Interrupt)
sets interrupt handler for memory fault
static bool RawFree(HeapMap_t *Map, void *Address, oC_UInt_t Size)
bool oC_MEM_LLD_IsDmaRamAddress(const void *Address)
checks if the pointer is in DMA RAM section
MemoryEventFlags_t EventFlags
The file with LLD interface for the SYS driver.
oC_ErrorCode_t oC_MEM_LLD_TurnOnMemoryFaultInterrupt(void)
turns on memory fault interrupt
static bool IsHeapMapInitialized(HeapMap_t *Map)
void oC_MemMan_CheckMemoryExhausted(void)
checks if memory exhausted event not occurs.
#define kB(kBytes)
Number of kB.
void * oC_MEM_LLD_GetDmaRamEndAddress(void)
returns end address of the DMA RAM
oC_ErrorCode_t oC_MemMan_SetEventHandler(MemoryEventHandler_t EventHandler)
sets event handler function
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
static HeapMap_t DmaHeapMap
The file with interface for Thread Manager.
bool oC_MemMan_IsFlashAddress(const void *Address)
checks if address is placed in the flash section
void oC_MemMan_CheckOverflow(void)
scan each block to check if the overflow event not occurs.
static Block_t * FindBlockOfAddress(const void *Address)
static oC_ErrorCode_t InitializeHeapMap(HeapMap_t *Map, void *HeapStartPointer, void *HeapEndPointer, oC_UInt_t HeapSize, bool FillZero)
static bool CheckIfHeapInRangeIsInState(HeapMap_t *Map, oC_UInt_t *HeapFrom, oC_UInt_t *HeapTo, HeapState_t HeapState)
static bool IsMemoryValid(void *Start, oC_UInt_t Size)
tests memory for the heap usage
static void MemoryFaultInterrupt(void)
static Block_t * BlockListTail
static bool CanReleaseMemory(Block_t *Block)
static uint8_t oC_Bits_SetBitU8(uint8_t *outVariable, uint8_t BitIndex)
sets bit in the variable
The file with interface of kernel time module.
bool oC_MEM_LLD_IsRamAddress(const void *Address)
checks if the pointer is in ram section
#define NULL
pointer to a zero
static oC_UInt_t * FindNextHeapPointerInState(HeapMap_t *Map, oC_UInt_t *HeapPointer, oC_UInt_t *HeapEndLimit, HeapState_t HeapState)
void * oC_MEM_LLD_GetDataStartAddress(void)
returns start address of the data section