R_RTOS  0.1
DistributedRealTimeOperatingSystemfortheARMCortexMArchitecture
R_RTOS_memMngr.c File Reference
#include "R_RTOS_memMngr.h"
#include "R_RTOS_BitMagic.h"

Functions

RetCode initMEM (void)
 Initialize the memory manager. More...
 
static void delMemBlck (MemMngrHead *const blckToDelete)
 Delete a block from the list it is contained in. More...
 
static MemMngrHeadgetAdjacentPrevBlck (MemMngrHead *const curBlck)
 Calculate and return the block prior to the given block. More...
 
static MemMngrHeadgetAdjacentNxtBlck (MemMngrHead *const curBlck)
 Calculate and return the block next to the given block. More...
 
static MemMngrHeadgetBuddyBlck (MemMngrHead *const curBlck)
 Calculate and return the buddy block to the given block. More...
 
static void fitBlckBackIntoFreeLst (MemMngrHead *const curBlck)
 Put the given block back into the free memory blocks list according to its address. More...
 
static uint8_t mergeMemBlck (MemMngrHead **blckToMerge)
 The given memory block is merged with its buddy block if it is free and not cached. More...
 
static void reMergeMemBlck (MemMngrHead **blckToMerge)
 The given memory block is merged continuously with its buddy blocks as long as these are neither taken nor cached. More...
 
static void splitMemBlck (MemMngrHead **const blckToSplit)
 The given memory block is split into two equally sized buddies. More...
 
static void unMergeUnevenBlcks (MemMngrHead *const blckToUnMerge)
 The given memory block is split into the unequal buddy blocks it consisted of. More...
 
static void mergeUnevenBlocks (MemMngrHead *const basis, MemMngrHead *const added)
 The two given memory blocks of unequal size are merged into one memory block. More...
 
static void shrinkCacheFIFO (void)
 Remove the last element out of the cache. More...
 
static void addBlckToCache (MemMngrHead *const blckToAdd)
 Add the given block to the objCache. More...
 
void * rMalloc (MemSize desiredSize)
 Allocate a block of memory satisfying the desiredSize property. More...
 
void * rCalloc (const MemSize desiredSize)
 
void * rRealloc (void *ptrToExistingMem, MemSize desiredSize)
 Allocate a block of memory satisfying the desiredSize property. More...
 
void rFree (void *pToBeFreed)
 The provided block of memory will be added to the memory block cache. More...
 
void rFullyFree (MemMngrHead *blckToFullyFree)
 Free a block of memory previously allocated with either rMalloc, rCalloc or rRealloc. More...
 
RetCode memMngr_CreateMemPool (const MemSize sizeOfElements, const uint8_t elements, MemPoolID *const memPoolID)
 Creates a memory pool with the given MemPoolID. More...
 
RetCode memMngr_DeleteMemPool (const MemPoolID memPoolID)
 Delete a previously created memory pool linked to the provided MemPoolID. More...
 
RetCode memMngr_MemPoolMalloc (void **ptrToMem, const MemPoolID memPoolID)
 Allocate an element from the memory pool specified by the provided MemPoolID. More...
 
RetCode memMngr_MemPoolFree (void *ptrToMem, const MemPoolID memPoolID)
 Free a previously allocated block of memory from a memory pool and put it back into the memory pool. More...
 

Variables

static MemMngrHeadfreeMemLst = (MemMngrHead *) NULL
 List of free blocks of memory. More...
 
static MemMngrHeadobjCache = (MemMngrHead *) NULL
 List of free cached blocks of memory. More...
 
static MemMngrHeadobjCacheEnd = (MemMngrHead *) NULL
 End of the objCache List. More...
 
static uint8_t buddyOffset = (uint8_t) 0x0u
 Memory address offset of buddy blocks. More...
 
static uint8_t cacheSize = (uint8_t) 0x0u
 Counter for the current size of the objCache. More...
 

Detailed Description