ChronOS Memory Management

Aus ProjectWiki
Wechseln zu:Navigation, Suche

Common Settings

Allocation Algorithm

You can choose between two allocation algorithms. System default is the static algorithm.

Const Os_malloc_policy = Os_malloc_policy_static

To use the dynamic TLSF algorithm:

Const Os_malloc_policy = Os_malloc_policy_tlsf

Free RAM start address

Because the start address cannot be calculated with some constants, you have to set this yourself. To do this, check "Show internal variables" in Options->Compiler->Output, look into the compiler report and search for the address of the first byte not occupied by a variable. Obviously this is a very important step, otherwise the values of global variables would be overwritten.

Const Free_ram_start = [address]

Optional: Free RAM End

It is also possible to set the end address of the free memory area yourself, system default is below the stack area.

Const Free_ram_end = [address]

Compiler Report Example

Here is a (shortened) example of a compiler report, and where the address could be found. In this example, the RAM start address should be set to at least 169 dec.

Report       : chronos
Date         : 05-20-2013
Time         : 01:54:06

Processor    : M32
SRAM         : 800 hex
EEPROM       : 400 hex
ROMSIZE      : 8000 hex


Variable                         Type            Address(hex)   Address(dec)


OS_CRITICAL_NESTING_LEVEL        Byte              0060          96
OS_EVENT_TASK                    Word              0061          97
MALLOC_FREE_POINTER              Word              0063          99
OS_SCHED_RUNNING_WEIGHT          Byte              0065          101
OS_SCHED_LIST_HEAD               Word              0066          102
OS_SCHED_PREEMPTED_TASK          Word              0068          104
OS_TASK_ACTIVE                   Word              006A          106
OS_TASK_TEMPBYTE_ISR             Byte              006C          108
OS_TASK_TEMPWORD_ISR             Word              006D          109
OS_TASK_TEMPWORD2_ISR            Word              006F          111
OS_TIMER_SYSTEMTIME              Dword             0071          113
OS_TIMER_LISTHEAD                Word              0075          117
OS_TIMER_NEXT_EVENT              Word              0077          119
OS_TIMER_ELAPSED_TIME            Word              0079          121
OS_TIMER_ENABLE_KERNEL           Byte              007B          123
OS_INT_TABLE                     Word (20)         007C          124
TASKOBJECT                       Word              00A4          164
TASK_1_COUNTER                   Byte              00A6          166
TASK_2_COUNTER                   Byte              00A7          167
___LCDCOUNTER                    Byte              00A8          168     <---

Constant                         Value
SREG                             &H3F
SPH                              &H3E
SPL                              &H3D


Programming Interface

Malloc: Request memory from free memory pool

Dim Object As Word
Object = Malloc(Byval Size As Word)

If there is a risk running out of memory (always be aware of that when using a dynamic allocation algorithm), a check if Malloc() returns 0 and a proper error handling is important.

Free: Return memory to the pool

Free Object