Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

Memory


Detailed Description

The MCU ATmega128 has three different types of memory:
  1. PROGMEM - program memory, flash technology, size 128KB
  2. RAM - 4KB
  3. EEPROM - 4KB

TODO see also protected memory, idle malloc

Some of the functions can access any of the memories.

mem.png

Memory model

For developer following functions simplify the memory access:

For wb() and ww() only the RAM or EEPROM makes sence.

Memory allocation

For RAM allocation you can use the standard malloc(), free() calls and
 #include <stdlib.h> 

To access EEPROM you must use emalloc(), efree() calls.

On PROGMEM

To insert some data into PROGMEM in compilation time you can use the attribute PROGMEM. Example:
u8 PROGMEM data[]={0,1,2,3};
includes {0,1,2,3} into PROGMEM.

To access such data you must use rb() or rw() calls.

u8 PROGMEM data[]={0,1,2,3};
u8 x;
u8 i;

for(i=0;i<sizeof(data);i++) x=rb(data+i);

Attention:
Because or very little RAM we suggest to put everything possible into PROGMEM, esp. strings.

There is a very little stack so use malloc()/free() rather than local arrays.

For details on PROGMEM please refer to AVR LIBC documentation.

Shared Memory

It is possible to share memory between application, i.e. one application may have access to some data of another application.

Shared memory is implemented by key to pointer association, where key is for simplicity one byte number. First application prepares memory and uses u8 shmem_reg_key(u8 key, void *pointer) to associate key<->pointer. Another application makes lookup on given key and pointer is returned by void * shmem_key(u8 key).

Defines

Typedefs

Functions


Define Documentation

#define MEM_D
 

Indicates memory card.

#define MEM_E
 

Indicates EEPROM.

#define MEM_P
 

Indicates PROGMEM (flash memory).

#define MEM_R
 

Indicates RAM.


Typedef Documentation

typedef short b16
 

signed 2bytes=16bits

typedef long b32
 

signed 4bytes=32bits

typedef char b8
 

signed 1byte=8bits

typedef unsigned short u16
 

unsigned 2bytes=16bits

typedef unsigned long u32
 

unsigned 4bytes=32bits

typedef unsigned char u8
 

unsigned 1byte=8bits


Function Documentation

void _init void   ) 
 

Copy data from PROGMEM to RAM and clear BSS.

void* app_data void   ) 
 

Return pointer on application persistent data.

Examples:
certs.c, and fake_sim.c.

u8* buf_A void   ) 
 

STK thread buffer. In this buffer STK command is composed, waits for FETCH and TERMINAL RESPONSE is stored.

Attention:
Can be used only in stk_thread().
Examples:
braled.c, braping.c, certs.c, mc.c, and stkcmd.c.

u8* buf_B void   ) 
 

General GSM buffer. All the ME<->TURBO<->SIM communication happens here.

Attention:
Can be modified only in stk_thread() and its content is not valid after STK command.
Examples:
adc.c, braping.c, calc.c, certs.c, fake_sim.c, mc.c, net.c, shmem.c, sysinfo.c, temperature.c, test_idle.c, and test_prot_mem.c.

void efree void *  ptr  ) 
 

Free emalloc'ed chunk.

Parameters:
ptr 
Examples:
certs.c, fake_sim.c, and tsmsacl.c.

void* emalloc u16  size  ) 
 

Same as malloc but in EEPROM.

Parameters:
size 
Examples:
certs.c, fake_sim.c, and tsmsacl.c.

u8 get_bit u8 buf,
u16  bit
 

Return value of bit in the array.

Parameters:
buf pointer on byte array (RAM only)
bit 
Returns:
0 or 1.
See also:
set_bit()

u8 rb const void *  addr  ) 
 

Read byte from memory.

Parameters:
addr EEPROM, PROGMEM, RAM memory address
Examples:
certs.c, fake_sim.c, and tsmsacl.c.

void reg_app_data void *  data  ) 
 

Store (in EEPROM) pointer on application persistent data.

Parameters:
data 
Examples:
certs.c, and fake_sim.c.

u16 rw const void *  addr  ) 
 

Read word from memory.

Parameters:
addr EEPROM, PROGMEM, RAM memory address
Examples:
certs.c, fake_sim.c, hello_world_ucs2.c, and tsmsacl.c.

void set_bit u8 buf,
u16  bit,
u8  val
 

Set bit in the array.

Parameters:
buf pointer on byte array (RAM only)
bit 
val 0 or 1
See also:
get_bit()

void* shmem_key u8  key  ) 
 

Find pointer associated with key.

Parameters:
key look for given key
Returns:
pointer or NULL
Examples:
shmem.c.

u8 shmem_reg_key u8  key,
void *  pointer
 

Register shared memory key - used for finding/denoting shared memory between application.

Parameters:
key number/byte denoting the shared memory
pointer store pointer to be associated with key
Returns:
NO_ERROR or ERR_UNKNOWN if cannot be created
Examples:
shmem.c.

u8 swap_nibble u8  x  ) 
 

Swap half-bytes, e.g. 0x10 = swap_nibble(0x01),

Parameters:
x 

void wb void *  addr,
u8  val
 

Write byte to memory.

Parameters:
addr EEPROM, RAM memory address
val value
Examples:
certs.c, fake_sim.c, and tsmsacl.c.

void ww void *  addr,
u16  val
 

Write word to memory.

Parameters:
addr EEPROM, RAM memory address
val value.
Examples:
certs.c, fake_sim.c, and tsmsacl.c.


Copyright © 2004-2006 BLADOX
Turbo version 1.2