The introduced Heap-manager requires on administration of <=64kB 2(3)bytes and up to 4GB 4(5)bytes overhead per entry (depends on linked with MEM_CleanUp).
Additional he can administer RAM and EE-PROM parallel and gives HW-indepenend tools for write accesses to the EE-PROM memory over the port.
User-Functions:
Memory-Manager: | |
MEM_Init | Initialization of the Heap-Manager |
MEM_Alloc | Allocation of storage |
MEM_Free | release allocated storage |
MEM_Resize | Size of allocated storage alters |
Heap_Write_EE | on allocated EEPROM-heap write |
Heap_Fill_EE | allocated EEPROM-heap fill |
optional |
|
MEM_CleanUp | release all allocated storage-elements of a task |
Error-Codes:
|
Name |
Decimal_Value |
Description |
MEM_NO_ERR | 0 | no error |
MEM_WR_PTR | 120 | Pointer is not in the storage area or not allocated or no valid entry into this address |
MEM_OVF | 121 | memory pool fully |
MEM_ERR | 122 | error in the memory management |
If initializes the heap-manager. If the EE-heap should be recognized as unformatted, so this is executed.
This function must be called before all other heap services at the system initialization once.
With utilization of the Linux-HOSTs, an existing heap-IMAGE is tried before the EE-formattest to load for the EE-simulation from a Linux-file.
none
MEM_NO_ERR
initializes successfully
MEM_ERR
Mistakes in the memory management
MEM_INVALID
EE-IMAGE invalid (only with Linux-HOST)
void main(void) { U08 returnOk; . returnOk=MEM_Init(); . . }
Only with utilization of the Linux_HOST.
It saves the EE-heap as image into a Linux-file.
none
MEM_NO_ERR
secured successfully
...
...
void main(void) { U08 returnOk; . returnOk=MEM_Init(); . . returnOk=MEM_Flush(); }
Allocate the stated storage in the demanded memory type (RAM/EE) and returns the start address.
size
size of array in bytes
type
type of Memory (0=RAM / 1=EE)
If the returned address equally ZERO, so you get the following error-codes from MEM_GetErrNo()
MEM_OVF
Store fully
MEM_ERR
Mistakes in the memory management
void main(void) { U08 returnOk; U08 OS_HUGE *ptr; . returnOk=MEM_Init(); . ptr=MEM_Alloc(100, MEM_RAM); if(ptr==NULL) { returnOk=MEM_GetErrno(); } . . }
If releases the allocated storage again. The type of memory (RAM/EE) is determined on that occasion itself.
It becomes tried this freely storage area directly at a free storage behind it to the decontrol and if directly existing, at a free storage before it, to hang. (defragmentation)
*ptr
pointer of array (from MEM_Alloc)
MEM_NO_ERR
Store released
MEM_WR_PTR
Pointer is not in the storage area or not allocated or no valid entry into this address
MEM_ERR
Mistakes in the memory management
void main(void) { U08 returnOk; U08 OS_HUGE *ptr; . returnOk=MEM_Init(); . ptr=MEM_Alloc(100, 0); if(ptr==NULL) { returnOk=MEM_GetErrno(); } else { . . returnOk=MEM_Free(ptr); } . . }
If releases all allocated storage from the task with the priority prio again. The types of memory (RAM/EE) is determined on that occasion itself.
prio
priority of task to free
MEM_NO_ERR
Stores released
MEM_ERR
Mistakes in the memory management
OS_PRIO_INVALID
the priority is bigger OS_MAX_TASK
OS_TASK_SUSP_PRIO
under this priority, no Task is registered
void OS_TaskDelete(void) { U08 returnOk, prio; OS_Lock(); prio = OSTCBCur->OSTCBPrio; returnOk=MEM_CleanUp(prio); OS_ENTER_CRITICAL(); OS_Unlock(); . . }
Resize the allocated storage and returns the new start address.
It will try on that occasion when increasing, a possible free storage directly behind this entry, and if this is not yet enough to use a possible free storage exactly before this entry. (defragmentation)
Only if this is not enough, a new area becomes allocated by means of MEM_Alloc and the old one released after taken place copy of data by means of MEM_Free.
*ptr
pointer of array (from MEM_Alloc)
newsize
new size of array in bytes
If the returned address equally ZERO, so you get the following error-codes from MEM_GetErrNo()
MEM_OVF
Store fully
MEM_WR_PTR
Pointer is not in the storage area or not allocated or no valid entry into this address
MEM_ERR
Mistakes in the memory management
void main(void) { U08 returnOk; U08 OS_HUGE *ptr; U08 OS_HUGE *ptr_new; . returnOk=MEM_Init(); . ptr=MEM_Alloc(100, 0); if(ptr==NULL) { returnOk=MEM_GetErrno(); } else { ptr_new=MEM_Resize(ptr, 150); if(ptr_new==NULL) { returnOk=MEM_GetErrno(); . returnOk=MEM_Free(ptr); } else { . . returnOk=MEM_Free(ptr_new); } } . . }
Write length bytes from *source to *dest into the EE-PROM under observation of the HW-spezifica.
*source
source pointer (not in EE-PROM)
*dest
destination pointer into EE-PROM
length
bytes to write
MEM_NO_ERR
Store written
MEM_WR_PTR
source-pointer shows into the EE-PROM
MEM_ERR
Mistakes in the memory management
void main(void) { U08 returnOk; U16 var1; U08 OS_HUGE *ptr; . returnOk=MEM_Init(); . ptr=MEM_Alloc(sizeof(U16), MEM_EE); // alloc EE-PROM if(ptr==NULL) { returnOk=MEM_GetErrno(); } else { var1 = 4125; returnOk=Heap_Write_EE(&var1, ptr, sizeof(U16)); } . . }
Fills the area into the EE-PROM with value under observation of the HW-spezifica.
*dest
destination pointer into EE-PROM
length
bytes to fill
value
byte to fill with it
MEM_NO_ERR
Store written
MEM_WR_PTR
dest-pointer doesn't show into the EE-PROM
MEM_ERR
Mistakes in the memory management
void main(void) { U08 returnOk; U08 OS_HUGE *ptr; . returnOk=MEM_Init(); . ptr=MEM_Alloc(20, MEM_EE); // alloc EE-PROM if(ptr==NULL) { returnOk=MEM_GetErrno(); } else { returnOk=Heap_Fill_EE(ptr, 20, 0x55); . . } . }