Interface: tos.chips.at45db.At45db
interface At45db
HAL for Atmel's AT45DB family of serial dataflash chips. This provides
reasonably high-level operations on AT45DB pages, including automatic
buffer management. Writes are only guaranteed to happen after a flush,
flushAll, sync or syncAll.
When buffers are flushed to the flash (either explicitly or implicitly),
their contents are checked to ensure the write was succesful. If this
check fails, the flush is retried some number of times. If this fails
more than some number of times, all access to the flash is disabled
(all requests will report FAIL in their completion event).
This interface only supports one operation at a time - components offering
At45db should use the Resource interface for resource sharing.
- Author:
-
David Gay
Commands
command void computeCrc(at45page_t page, at45pageoffset_t offset, at45pageoffset_t n, uint16_t baseCrc)
command void copyPage(at45page_t from, at45page_t to)
command void erase(at45page_t page, uint8_t eraseKind)
command void flush(at45page_t page)
command void flushAll()
command void read(at45page_t page, at45pageoffset_t offset, void *data, at45pageoffset_t n)
command void sync(at45page_t page)
command void syncAll()
command void write(at45page_t page, at45pageoffset_t offset, void *data, at45pageoffset_t n)
Events
event void computeCrcDone(error_t error, uint16_t crc)
event void copyPageDone(error_t error)
event void eraseDone(error_t error)
event void flushDone(error_t error)
event void readDone(error_t error)
event void syncDone(error_t error)
event void writeDone(error_t error)
Commands - Details
computeCrc
command void computeCrc(at45page_t page, at45pageoffset_t offset, at45pageoffset_t n, uint16_t baseCrc)
- Parameters:
-
page - Flash page to read from. Must be less than AT45_MAX_PAGES.
-
offset - Offset in page at which to start reading - must be between
0 and AT45_PAGE_SIZE - 1
-
n - Number of bytes to read (> 0). offset + n must be <=
AT45_PAGE_SIZE
-
baseCrc - initial CRC value - use 0 if computing a "standalone"
CRC, or a previous computeCrc result if computing a CRC over several
flash pages
copyPage
command void copyPage(at45page_t from, at45page_t to)
- Parameters:
-
from - Flash page to copy. Must be less than AT45_MAX_PAGES.
-
to - Flash page to overwrite. Must be less than AT45_MAX_PAGES.
erase
command void erase(at45page_t page, uint8_t eraseKind)
- Parameters:
-
page - Flash page to erase. Must be less than AT45_MAX_PAGES.
-
eraseKind - How to handle the erase:
AT45_ERASE: actually erase the page in the flash chip
AT45_DONT_ERASE: don't erase the page in the flash
chip, but reserve a buffer for this page - subsequent writes to this
page will be faster because the old contents need not be read
AT45_PREVIOUSLY_ERASED: assume the page was previously
erased in the flash and reserve a buffer for this page - subsequent
writes to page will be faster because the old contents need not be
read and the write itself will be faster
flush
command void flush(at45page_t page)
- Parameters:
-
page - Flash page to sync. Must be less than AT45_MAX_PAGES.
flushAll
command void flushAll()
read
command void read(at45page_t page, at45pageoffset_t offset, void *data, at45pageoffset_t n)
- Parameters:
-
page - Flash page to read from. Must be less than AT45_MAX_PAGES.
-
offset - Offset in page at which to start reading - must be between
0 and AT45_PAGE_SIZE - 1
-
data - Buffer in which to place read data. The buffer is "returned"
at readDone time.
-
n - Number of bytes to read (> 0). offset + n must be <=
AT45_PAGE_SIZE
sync
command void sync(at45page_t page)
- Parameters:
-
page - Flash page to sync. Must be less than AT45_MAX_PAGES.
syncAll
command void syncAll()
write
command void write(at45page_t page, at45pageoffset_t offset, void *data, at45pageoffset_t n)
- Parameters:
-
page - Flash page to write to. Must be less than AT45_MAX_PAGES.
-
offset - Offset in page at which to start writing - must be between
0 and AT45_PAGE_SIZE - 1
-
data - Data to write. The buffer is "returned" at writeDone time.
-
n - Number of bytes to write (> 0). offset + n must be <=
AT45_PAGE_SIZE
Events - Details
computeCrcDone
event void computeCrcDone(error_t error, uint16_t crc)
- Parameters:
-
error - SUCCESS if the CRC was successfully computed, FAIL otherwise
-
crc - CRC value (valid only if error == SUCCESS)
copyPageDone
event void copyPageDone(error_t error)
- Parameters:
-
error - SUCCESS if the copy was successful, FAIL otherwise
eraseDone
event void eraseDone(error_t error)
- Parameters:
-
error - SUCCESS if the erase was successful, FAIL otherwise
flushDone
event void flushDone(error_t error)
- Parameters:
-
error - SUCCESS if the flush was successful, FAIL otherwise
readDone
event void readDone(error_t error)
- Parameters:
-
error - SUCCESS for a successful read, FAIL otherwise
syncDone
event void syncDone(error_t error)
- Parameters:
-
error - SUCCESS if the sync was successful, FAIL otherwise
writeDone
event void writeDone(error_t error)
- Parameters:
-
error - SUCCESS for a successful write, FAIL otherwise