450
Platforms
©2000-2008 Tibbo Technology Inc.
Dim
s
As
String
...
'modify first 3 bytes of logical sector #5
If
fd.getsector(3)<>PL_FD_STATUS_OK
Then
'flash failure
End
If
fd.setbuffer("ABC",0)
'write "ABC" to the buffer at offset 0
If
fd.setsector(3)<>PL_FD_STATUS_OK
Then
'flash failure
End
If
Since there are two identical RAM buffers, you can load the contents of two
different sectors and work with the data concurrently, by switching between the
buffers.
Sharing Flash Between Your Application and Data
, logical
sector numbers for fd.getsector and fd.setsector are not actual physical sector
numbers of the flash IC. Logical sector #0 corresponds to the topmost physical
sector of the flash IC, so logical numbering is "in reverse".
You can only write to sectors that reside within the data area of your flash chip
(that is, logical sector numbers from 0 to
-1). This is done
to prevent your application from inadvertently damaging its own code or the
firmware. Trespassing the data area boundary will result in the 1-
PL_FD_STATUS_FAIL
. If you want to alter the data in the firmware/
Upgrading the Firmware/Application
topic.
If you are using direct sector access and
at the same time, be
sure to read about ensuring their proper
.
Using Checksums
When dealing with the flash memory, it is very often desirable to make sure that
the data stored in flash sectors is not corrupted. One way to do so is by calculating
the checksum on the sector data and storing this checksum together with the data.
Each 264-byte sector of the flash memory conveniently has 8 extra bytes of
memory on top of the "regular" 256 bytes existing to store actual data.
The fd. object uses first two of the 8 spare storage locations to keep the checksum
of the 256-byte data block residing in the same sector (see the drawing below).
The checksum is a 16-bit value. When the checksum is correct, a 16-bit sum of the
256-byte data block plus the checksum itself should be zero. Of course, this is an
arbitrary choice -- there is no special reason why the .fd object does it this way,
and not in any other way. We just decided to do it like that, and that was it!
434
457
435
452
436
453