Interface: tos.chips.at45db.HplAt45db

interface HplAt45db

HPL for Atmel's AT45DB family of serial dataflash chips. Provides access to all basic AT45DB operations plus operations to wait for the flash to go idle or finish a comparison. See the AT45DB family datasheets for full details on these operations.

This interface only supports one operation at a time.

Author:
David Gay

Commands
command void compare(uint8_t cmd, at45page_t page) Compare a page from flash with a buffer.
command void crc(uint8_t cmd, at45page_t page, at45pageoffset_t offset, at45pageoffset_t n, uint16_t baseCrc) Compute CRC of data in a flash buffer (using the CRC function from crc.h).
command void erase(uint8_t cmd, at45page_t page) Erase a flash page.
command void fill(uint8_t cmd, at45page_t page) Read a page from flash into a buffer.
command void flush(uint8_t cmd, at45page_t page) Write a buffer to a flash page.
command void read(uint8_t cmd, at45page_t page, at45pageoffset_t offset, uint8_t *data, at45pageoffset_t n) Read directly from flash.
command void readBuffer(uint8_t cmd, at45pageoffset_t offset, uint8_t *data, uint16_t n) Read from a flash buffer.
command void waitCompare() Wait for a buffer-flash comparison to complete.
command void waitIdle() Wait for a "Group A" operation to complete (essentially all non-buffer operations).
command void write(uint8_t cmd, at45page_t page, at45pageoffset_t offset, uint8_t *data, at45pageoffset_t n) Write some data to a flash buffer, and optionally the flash itself.

Events
event void compareDone() Signaled when compare command sent (use waitCompare to detect when compare command completes and find out comparison result)
event void crcDone(uint16_t computedCrc) Signaled when CRC has been computed.
event void eraseDone() Signaled when erase command sent (use waitIdle to detect when erase command completes)
event void fillDone() Signaled when fill command sent (use waitIdle to detect when fill command completes)
event void flushDone() Signaled when flush command sent (use waitIdle to detect when flush command completes)
event void readDone() Signaled when data has been read from the buffer.
event void waitCompareDone(bool compareOk) Signaled when the buffer-flash comparison is complete.
event void waitIdleDone() Signaled when the flash is idle.
event void writeDone() Signaled when data has been written to the buffer.

Commands - Details

compare

command void compare(uint8_t cmd, at45page_t page)

Compare a page from flash with a buffer. compareDone will be signaled.

Parameters:
cmd - AT45_C_COMPARE_BUFFER1 to compare buffer 1, AT45_C_COMPARE_BUFFER2 to compare buffer 2
page - Page to compare with (must be less than AT45_MAX_PAGES)

crc

command void crc(uint8_t cmd, at45page_t page, at45pageoffset_t offset, at45pageoffset_t n, uint16_t baseCrc)

Compute CRC of data in a flash buffer (using the CRC function from crc.h). crcDone will be signaled.

Parameters:
cmd - AT45_C_READ_BUFFER1 to compute CRC from buffer 1, AT45_C_READ_BUFFER2 to compute CRC from buffer 2
page - ignored (reserved for future use)
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 crc result if computing a CRC over several flash pages

erase

command void erase(uint8_t cmd, at45page_t page)

Erase a flash page. eraseDone will be signaled.

Parameters:
cmd - must be AT45_C_ERASE_PAGE
page - Page to compare with (must be less than AT45_MAX_PAGES)

fill

command void fill(uint8_t cmd, at45page_t page)

Read a page from flash into a buffer. fillDone will be signaled.

Parameters:
cmd - AT45_C_FILL_BUFFER1 to read into buffer 1, AT45_C_FILL_BUFFER2 to read into buffer 2
page - Page to read (must be less than AT45_MAX_PAGES)

flush

command void flush(uint8_t cmd, at45page_t page)

Write a buffer to a flash page. flushDone will be signaled.

Parameters:
cmd - AT45_C_FLUSH_BUFFER1 to write buffer 1 to flash, AT45_C_FLUSH_BUFFER2 to write buffer 2 to flash, AT45_C_QFLUSH_BUFFER1 to write buffer 1 to flash w/o erase (page must have been previously erased), AT45_C_QFLUSH_BUFFER2 to write buffer 2 to flash w/o erase (page must have been previously erased),
page - Page to write (must be less than AT45_MAX_PAGES)

read

command void read(uint8_t cmd, at45page_t page, at45pageoffset_t offset, uint8_t *data, at45pageoffset_t n)

Read directly from flash. readDone will be signaled.

Parameters:
cmd - AT45_C_READ_CONTINUOUS or AT45_C_READ_PAGE. When the end of a page is read, AT45_C_READ_CONTINUOUS continues on the next page, while AT45_C_READ_PAGE continues at the start of the same page.
page - Page to read from
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).

readBuffer

command void readBuffer(uint8_t cmd, at45pageoffset_t offset, uint8_t *data, uint16_t n)

Read from a flash buffer. readDone will be signaled.

Parameters:
cmd - AT45_C_READ_BUFFER1 to read from buffer 1, AT45_C_READ_BUFFER2 to read from buffer 2
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

waitCompare

command void waitCompare()

Wait for a buffer-flash comparison to complete. waitCompareDone will be signaled when that occurs.

waitIdle

command void waitIdle()

Wait for a "Group A" operation to complete (essentially all non-buffer operations). You should use waitComapre if you are waiting for a comparison to complete. waitIdleDone will be signaled when the operation is complete.

write

command void write(uint8_t cmd, at45page_t page, at45pageoffset_t offset, uint8_t *data, at45pageoffset_t n)

Write some data to a flash buffer, and optionally the flash itself. writeDone will be signaled.

Parameters:
cmd - One of AT45_C_WRITE_BUFFER1/2 or AT45_C_WRITE_MEM_BUFFER1/2 to write respectively to buffer 1/2, or to buffer 1/2 and the specified main memory page.
page - Page to write when cmd is AT45_C_WRITE_MEM_BUFFER1/2
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

compareDone

event void compareDone()

Signaled when compare command sent (use waitCompare to detect when compare command completes and find out comparison result)

crcDone

event void crcDone(uint16_t computedCrc)

Signaled when CRC has been computed.

Parameters:
computedCrc - CRC value

eraseDone

event void eraseDone()

Signaled when erase command sent (use waitIdle to detect when erase command completes)

fillDone

event void fillDone()

Signaled when fill command sent (use waitIdle to detect when fill command completes)

flushDone

event void flushDone()

Signaled when flush command sent (use waitIdle to detect when flush command completes)

readDone

event void readDone()

Signaled when data has been read from the buffer. The data buffer is "returned".

waitCompareDone

event void waitCompareDone(bool compareOk)

Signaled when the buffer-flash comparison is complete.

Parameters:
compareOk - TRUE if the comparison succeeded, FALSE otherwise.

waitIdleDone

event void waitIdleDone()

Signaled when the flash is idle.

writeDone

event void writeDone()

Signaled when data has been written to the buffer. The data buffer is "returned".