User`s manual

332 digi.com Hints and Tips
Battery-Backed RAM - Storing data here is as easy as assigning values to global variables or local
static variables. The file system can also be configured to use RAM.
The life of a battery on a Rabbit board is specified in the users manual for that board; some boards have
batteries that last several years, most board have batteries that come close to or surpass the shelf-life of
the battery. If it is important that battery-backed data not be lost during a battery failure, know how long
your battery will last and plan accordingly.
17.3.1 User Block
The User block is an area near the top of flash reserved for run-time storage of persistent data and calibra-
tion constants. The size of the User block can be read in the global structure member
SysIDBlock.userBlockSize. The functions readUserBlock() and writeUserBlock()
are used to access the User block. These function take an offset into the block as a parameter. The highest
offset available to the user in the User block will be
SysIDBlock.userBlockSize-1
if there are no calibration constants, or
DAC_CALIB_ADDR-1
if there are.
See the Rabbit designers handbook for more details about the User block.
17.3.2 Flash File System
For a complete discussion of the file system, please see Chapter 10, “File Systems.”
17.3.3 WriteFlash2
See the Dynamic C Function Reference Manual for a complete description.
NOTE: There is a WriteFlash() function available for writing to the first flash,
but its use is highly discouraged for reasons of forward source and binary compatibil-
ity should flash sector configuration change drastically in a product. For more infor-
mation on flash compatibility issues, see technical notes TN216 “Is your Application
Ready for Large Sector Flash?” and TN217 “Binary and Source Compatibility Issues
for 4K Flash Sector Sizes” at Digi’s website: www.digi.com/support/.
17.3.4 Battery-Backed RAM
Static variables and global variables will always be located at the same addresses between power cycles
and can only change locations via recompilation. The file system can be configured to use RAM also.
While there may be applications where storing persistent data in RAM is acceptable, for example a data
logger where the data gets retrieved and the battery checked periodically, keep in mind that a programming
error such as an uninitialized pointer could cause RAM data to be corrupted.
xalloc() will allocate blocks of RAM in extended memory. It will allocate the blocks consistently from
the same physical address if done at the beginning of the program and the program is not recompiled.