Operation Details

Top  Previous  Next

STG library automatically allocates the storage for settings. That is, non-volatile and volatile memory addresses where individual settings are stored are calculated automatically.

When non-volatile settings are stored in the EEPROM (default configuration), they are located at the bottom of the EEPROM, right after the special configuration area.

When non-volatile settings are stored on a flash disk (Use Flash Disk option selected), they are stored in the file specified by the Filename option.

When the Custom RAM option is not selected, the volatile (RAM) settings are stored in an array which is maintained by the library (stg_ram_array variable).

When the Custom RAM option is checked, the volatile (RAM) settings are stored using callback_stg_vm_read() and callback-stg_vm_write(), which should contain custom code for accessing whatever memory you have decided to use for storing volatile settings (example: internal memory of a real-time clock IC).

 

When the Redundancy option is set to two copies for non-volatile settings, the library maintains a second copy of data for non-volatile settings (this doubles the required amount of non-volatile memory) and keeps a single copy for volatile settings. When the Redundancy option is set to two copies for ALL settings, even volatile settings are stored as two independent copies.

Two copies of setting data are stored like this:

 

Bottom of EEPROM (flash)

Data for all non-volatile settings (first copy)

Data for all non-volatile settings (second copy)

 

Bottom of RAM

Data for all volatile settings (first copy)

Data for all volatile settings (second copy)

 

Each setting is stored in the following format:

 

Setting storage

Setting data

Timestamp (7 bytes)*

Checksum byte

*Only when the Timestamp option is enabled.

 

The checksum is a 255 complement of the modulo 256 (8-bit) sum of all data bytes for the setting except the checksum itself. The amount of storage allocated for setting data depends on this setting's properties. The total amount of memory taken by the setting can't exceed 255 bytes.

Setting data includes one or more setting members depending on the number of members in this setting.

Setting data field for a setting with three members

Member0 data

Member1 data

Member2 data

 

Here is how member data for settings of different types is stored:

Byte settings require a single byte of storage for each member.

Word settings require two bytes of storage for each member, the data is stored like this:

HIGH byte

LOW byte

String and dot-decimal settings require the space equal to the P2 parameter (max length) plus one additional byte to store the current length of the data:

Current length (1 byte)

P2 number of bytes for data storage