User`s manual

130 digi.com File Systems
Increase the useful lifetime and performance of the flash by buffering data before writing it to the flash.
Accumulating 1000 single byte writes into one multi-byte write can extend the life of the flash by an aver-
age of 750 times. FS2 does not currently perform any in-memory buffering. If you write a single byte to a
file, that byte will cause write activity on the device. This ensures that data is written to non-volatile stor-
age as soon as possible. Buffering may be implemented within the application if possible loss of data is
tolerable.
10.1.1.1 Maximum File Size
The maximum file size for an individual file depends on the total file system size and the number of files
present. Each file requires at least two sectors: at least one for data and always one for metadata (for infor-
mation used internally). There also needs to be two free sectors per file to allow for moving data around.
Here is a formula you can use to determine how many bytes to allocate for the total file system (assuming
all files are the same size):
Bytes = (Nbr_of_files * file_size * 1.14 ) + (Nbr_of_files * 128) +
(2 * 128)
FS2 supports a total of 255 files, but storing a large number of small files is not recommended. It is much
more efficient to have a few large ones.
10.1.1.2 Two Flash Boards
By default, when a board has two flash devices, Dynamic C will use only the first flash for code. The sec-
ond flash is available for the file system unless the macro USE_2NDFLASH_CODE is defined in the appli-
cation by adding it to the Defines tab of the Project Options dialog box (for instructions see “Defines Tab”
on page 288). This macro allocates the second flash to hold program code. The use of
USE_2NDFLASH_CODE is not compatible with FS2.
10.1.1.3 Using SRAM
The flash file system can be used with battery-backed SRAM. Internally, RAM is treated like a flash
device, except that there is no write-cycle limitation, and access is much faster. The file system will work
without the battery backup, but would, of course, lose all data when the power went off.
Currently, the maximum size file system supported in RAM is about 200k. This limitation holds true even
on boards with a 512k RAM chip. The limitation involves the placement of BIOS control blocks in the
upper part of the lower 256k portion of RAM.
To obtain more RAM memory, xalloc() may be used. If xalloc() is called first thing in the pro-
gram, the same memory addresses will always be returned. This can be used to store non-volatile data is so
desired (if the RAM is battery-backed), however, it is not possible to manage this area using the file sys-
tem.
Using FS2 increases flexibility, with its capacity to use multiple device types simultaneously. Since RAM
is usually a scarce resource, it can be used together with flash memory devices to obtain the best balance of
speed, performance and capacity.