451
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
16-bit values for these calculations are little-endian. That is, offset 0 of the sector
is presumed to be the high byte of the first 16-bit value, offset 1 -- low byte of the
first 16-bit value, offset 2 -- high byte of the second 16-bit value, and so on.
, the fd. object automatically
calculates and/or verifies the checksum on all sectors it accesses. Should any
sector turn out to contain an invalid checksum, the 2-
PL_FD_STATUS_CHECKSUM_ERR
is generated.
Direct sector access is more primitive and it is your responsibility to maintain and
verify the integrity of data you store in the flash memory. To aid you in this, the
method that can be used to both verify and calculate the
checksum of the sector's data:
'Load sector #10, verify its checksum, alter some data, recalculate the
checksum, and save new data
Dim
i
As
word
...
'load the sector
If
fd.getsector(10)<>PL_FD_STATUS_OK
Then
'flash failure
End
If
'verify the checksum
If
fd.checksum(PL_FD_CSUM_MODE_VERIFY,i)<>OK
Then
'checksum error detected
End
If
fd.setbuffer("ABC",20)
'alter data at offset 20
fd.checksum(PL_FD_CSUM_MODE_CALCULATE,i)
'recalculate the checksum
'save back
If
fd.setsector(10)<>PL_FD_STATUS_OK
Then
'flash failure
End
If
Notice how the i variable in the example above is not doing anything useful. The
csum argument of the fd.checksum method exists to return the result of the
checksum verification or calculation. For example, it can allow you not only to set
correct checksum for the RAM buffer, but also find out what the checksum is. Who
knows... you might need it.
436
435
459