ChronOS Memory Management: Unterschied zwischen den Versionen

Aus ProjectWiki
Wechseln zu:Navigation, Suche
K (Segments)
K (Free RAM start address)
 
(3 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
== Pipes ==
+
== Common Settings ==
Pipes are simple LIFO buffers, so data will be written on the top of the stack and read from the bottom.
+
 
They are available for byte and word values. Each pipe is stored in an own segment. If you store a pointer in the pipe, it has to be registered.
+
=== Allocation Algorithm ===
 +
 
 +
You can choose between two allocation algorithms.
 +
System default is the static algorithm.
 +
<pre>
 +
Const Os_malloc_policy = Os_malloc_policy_static
 +
</pre>
 +
To use the dynamic TLSF algorithm:
 +
<pre>
 +
Const Os_malloc_policy = Os_malloc_policy_tlsf
 +
</pre>
 +
 
 +
=== 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.
 +
<pre>
 +
Const Free_ram_start = [address]
 +
</pre>
 +
 
 +
=== 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.
 +
<pre>
 +
Const Free_ram_end = [address]
 +
</pre>
 +
 
 +
=== 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.
 +
<pre>
 +
Report      : chronos
 +
Date        : 05-20-2013
 +
Time        : 01:54:06
 +
 
 +
Compiler    : BASCOM-AVR LIBRARY V 2.0.7.6
 +
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
 +
 
 +
...
 +
</pre>
 +
 
 +
 
 +
== Programming Interface ==
 +
 
 +
=== Malloc: Request memory from free memory pool ===
 +
<pre>
 +
Dim Object As Word
 +
Object = Malloc(Byval Size As Word)
 +
</pre>
 +
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 ===
 +
<pre>
 +
Free Object
 +
</pre>
 +
 
 +
[[Category:ChronOS]]

Aktuelle Version vom 21. Mai 2013, 23:21 Uhr

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

Compiler     : BASCOM-AVR LIBRARY V 2.0.7.6
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