453
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
File-based and Direct Sector Access Coexistence
and
access methods can be used at the same time,
as long as you understand how direct access may affect (and possibly screw up)
the flash disk.
explains that working with flash sectors is done through
two RAM buffers numbered #0 and #1. Flash disk operation depends on these
buffers as well.
Buffer #0 is used for processing housekeeping data and stores no valuable content
that must be preserved past the end of a certain disk-related method execution.
That is, once the method such as the
has executed, buffer #0 has no
valuable data in it.
Buffer #1 is used to load and store the contents of the most recently loaded (and
possibly changed) data sector. So, if fd.setdata was recently called, this buffer may
still hold new data, and this data may not be saved to flash yet. Corrupting the
data would have unpleasant consequences for the file. To prevent this, the fd.
object automatically dismounts the disk (sets the
= 0- NO) if your
or
while the
= 1
and while this buffer was loaded with new and as yet unsaved sector data.
Preventing disk dismounting is easy. You can opt to work on the RAM buffer #0
(set fd.buffernum= 0), or flush the unsaved data by invoking the
or
method.
The fd.setsector method will cause disk dismounting if the destination was within
the disk area (0 - fd.totalsize-1). Writing outside the disk area will not interfere
with the flash disk operation.
method does not cause any interference with the flash disk, so
it can be used freely.
will write to the RAM buffer (when in the
"PL_FD_CSUM_MODE_CALCULATE" mode), but the checksum calculation method is
the same as the one used by the disk itself, so setting this checksum will never be
wrong.
Note, finally, that any file-related method will affect the value of the fd.buffernum.
Never assume that you know what this property is set to. Always set it explicitly.
Prolonging Flash Memory Life
Flash memory has a huge limitation -- the number of times you can rewrite each of
its sectors is limited to around 100'000 times. At first this may seem like a
virtually unreachable limit, but in reality you can "get there" quite fast, which is
not a good thing. Once the flash wears down, you will start having data errors,
data corruption, failed sectors, etc. This topic explains what you can do to prolong
the life of the flash memory used in your device. This is generally achieved by (1)
reducing the number of writes to the flash memory, and (2) using sector leveling,
i.e. spreading sector writes, as evenly as possible, between the sectors.
File-based access
, the fd. object does the bulk of work for you. We have
already
that the file record table (FRT) and the file allocation table
(FAT) -- the most heavily written to areas of the disk -- occupy at least double the
space needed to store their data. They also have the minimum number of sectors
they will take, regardless of what is necessary. This ensures that at any given
time, the FRT and the FAT have spare sectors. These spare sectors, as well as
occupied sectors, are in constant rotation. For example, every time you create a
file, a change is made to one of the sectors of the FRT. This change requires
436
448
448
480
476
479
472
458
466
460
468
459
436
437