* * $Log: at45db.c,v $ * Revision 1.3 2007/08/17 10:45:21 haraldkipp * Enhanced documentation. * * Revision 1.2 2006/10/08 16:48:09 haraldkipp * Documentation fixed * * Revision 1.1 2006/09/29 12:41:55 haraldkipp * Added support for AT45 serial DataFlash memory chips. Currently limited * to AT91 builds. * * *
Definition in file at45db.c.
Go to the source code of this file.
AT45 DataFlash Commands | |
#define | DFCMD_CONT_READ_LF 0x03 |
Continuos read (low frequency). | |
#define | DFCMD_CONT_READ_HF 0x0B |
Continuos read (high frequency). | |
#define | DFCMD_BLOCK_ERASE 0x50 |
Block erase. | |
#define | DFCMD_SECTOR_ERASE 0x7C |
Sector erase. | |
#define | DFCMD_PAGE_ERASE 0x81 |
Page erase. | |
#define | DFCMD_BUF1_PROG 0x82 |
Main memory page program through buffer 1. | |
#define | DFCMD_BUF1_FLASH 0x83 |
Buffer 1 flash with page erase. | |
#define | DFCMD_BUF1_WRITE 0x84 |
Buffer 1 write. | |
#define | DFCMD_BUF2_PROG 0x85 |
Main memory page program through buffer 2. | |
#define | DFCMD_BUF2_FLASH 0x86 |
Buffer 2 flash with page erase. | |
#define | DFCMD_BUF2_WRITE 0x87 |
Buffer 2 write. | |
#define | DFCMD_BUF1_FLASH_NE 0x88 |
Buffer 1 flash without page erase. | |
#define | DFCMD_BUF2_FLASH_NE 0x89 |
Buffer 2 flash without page erase. | |
#define | DFCMD_CHIP_ERASE 0xC7 |
Chip erase. | |
#define | DFCMD_BUF1_READ_LF 0xD1 |
Buffer 1 read (low frequency). | |
#define | DFCMD_READ_PAGE 0xD2 |
Read main memory page. | |
#define | DFCMD_BUF2_READ_LF 0xD3 |
Buffer 2 read (low frequency). | |
#define | DFCMD_BUF1_READ 0xD4 |
Buffer 1 read. | |
#define | DFCMD_BUF2_READ 0xD6 |
Buffer 2 read. | |
#define | DFCMD_READ_STATUS 0xD7 |
Read status register. | |
#define | DFCMD_CONT_READ 0xE8 |
Continuos read (legacy). | |
Defines | |
#define | MAX_AT45_DEVICES 1 |
#define | MAX_AT45_CMDLEN 8 |
#define | AT45_CONF_DFSPI SPI0_BASE |
#define | AT45_CONF_DFPCS 1 |
#define | AT45_ERASE_WAIT 3000 |
#define | AT45_CHIP_ERASE_WAIT 50000 |
#define | AT45_WRITE_POLLS 1000 |
#define | AT45DB_AT91 |
Functions | |
int | At45dbSendCmd (int dd, u_char op, u_long parm, int len, CONST void *tdata, void *rdata, int datalen) |
Send DataFlash command. | |
u_char | At45dbGetStatus (int dd) |
int | At45dbWaitReady (int dd, u_long tmo, int poll) |
Wait until flash memory cycle finished. | |
int | At45dbInit (u_int spibas, u_int spipcs) |
Initialize dataflash at specified interface and chip select. | |
int | At45dbPageErase (int dd, u_int pgn) |
Erase sector at the specified offset. | |
int | At45dbChipErase (void) |
Erase entire flash memory chip. | |
int | At45dbPageRead (int dd, u_long pgn, void *data, u_int len) |
Read data from flash memory. | |
int | At45dbPageWrite (int dd, u_int pgn, CONST void *data, u_int len) |
Write data into flash memory. | |
u_long | At45dbParamPage (void) |
int | At45dbParamSize (void) |
Get size of configuration area. | |
int | At45dbParamRead (u_int pos, void *data, u_int len) |
Load configuration parameters from flash memory. | |
int | At45dbParamWrite (u_int pos, CONST void *data, u_int len) |
Store configuration parameters in flash memory. | |
Variables | |
AT45_DEVTAB | at45_devt [] |
Table of known Dataflash types. |
#define MAX_AT45_DEVICES 1 |
#define MAX_AT45_CMDLEN 8 |
#define AT45_CONF_DFSPI SPI0_BASE |
#define AT45_CONF_DFPCS 1 |
#define AT45_WRITE_POLLS 1000 |
#define DFCMD_CONT_READ_LF 0x03 |
#define DFCMD_CONT_READ_HF 0x0B |
#define DFCMD_PAGE_ERASE 0x81 |
#define DFCMD_BUF1_PROG 0x82 |
#define DFCMD_BUF1_FLASH 0x83 |
Buffer 1 flash with page erase.
Definition at line 126 of file at45db.c.
Referenced by At45dbPageWrite().
#define DFCMD_BUF1_WRITE 0x84 |
#define DFCMD_BUF2_PROG 0x85 |
#define DFCMD_BUF2_FLASH 0x86 |
#define DFCMD_BUF1_FLASH_NE 0x88 |
#define DFCMD_BUF2_FLASH_NE 0x89 |
#define DFCMD_BUF1_READ_LF 0xD1 |
#define DFCMD_READ_PAGE 0xD2 |
#define DFCMD_BUF2_READ_LF 0xD3 |
#define DFCMD_READ_STATUS 0xD7 |
#define DFCMD_CONT_READ 0xE8 |
Continuos read (legacy).
Reads a continous stream. Automatically switches to the the page and wraps to the first page after the last has been read. Note, that the data buffers are not used for this operation.
Definition at line 175 of file at45db.c.
Referenced by At45dbPageRead().
int At45dbSendCmd | ( | int | dd, | |
u_char | op, | |||
u_long | parm, | |||
int | len, | |||
CONST void * | tdata, | |||
void * | rdata, | |||
int | datalen | |||
) |
Send DataFlash command.
dd | Device descriptor. | |
op | Command operation code. | |
parm | Command parameter. | |
len | Command length. | |
tdata | Transmit data. | |
rdata | Receive data buffer. | |
datalen | Data length. |
Definition at line 278 of file at45db.c.
References At91SpiTransfer2(), MAX_AT45_CMDLEN, and memset().
u_char At45dbGetStatus | ( | int | dd | ) |
int At45dbWaitReady | ( | int | dd, | |
u_long | tmo, | |||
int | poll | |||
) |
Wait until flash memory cycle finished.
Definition at line 310 of file at45db.c.
References At45dbGetStatus(), and NutSleep().
Initialize dataflash at specified interface and chip select.
spibas | Interface base address. For ARM MCUs this may be the I/O base address of the hardware SPI. | |
spipcs | Device chip select. |
Definition at line 334 of file at45db.c.
References _BV, at45_devt, At45dbGetStatus(), At91SpiInit(), At91SpiInitChipSelects(), At91SpiReset(), At91SpiSetModeFlags(), At91SpiSetRate(), MAX_AT45_DEVICES, SPIMF_CAPRISE, SPIMF_MASTER, and SPIMF_SCKIAHI.
int At45dbPageErase | ( | int | dd, | |
u_int | pgn | |||
) |
Erase sector at the specified offset.
Definition at line 376 of file at45db.c.
References At45dbSendCmd(), and DFCMD_PAGE_ERASE.
int At45dbChipErase | ( | void | ) |
Read data from flash memory.
dd | Device descriptor. | |
pgn | Page number to read, starting at 0. | |
data | Points to a buffer that receives the data. | |
len | Number of bytes to read. |
Definition at line 399 of file at45db.c.
References At45dbSendCmd(), and DFCMD_CONT_READ.
Write data into flash memory.
The related sector must have been erased before calling this function.
dd | Device descriptor. | |
pgn | Start location within the chip, starting at 0. | |
data | Points to a buffer that contains the bytes to be written. | |
len | Number of bytes to write. |
Definition at line 417 of file at45db.c.
References AT45_WRITE_POLLS, At45dbSendCmd(), At45dbWaitReady(), DFCMD_BUF1_FLASH, DFCMD_BUF1_WRITE, free, and malloc.
u_long At45dbParamPage | ( | void | ) |
int At45dbParamSize | ( | void | ) |
Get size of configuration area.
A part of the DataFlash may be used to store configuration parameters, like the network interface MAC address, the local hostname etc. The size of this area may be configured by defining AT45_CONF_SIZE. Otherwise one full page is used.
Definition at line 456 of file at45db.c.
References AT45_CONF_DFPCS, AT45_CONF_DFSPI, and At45dbInit().
Referenced by At45dbParamRead(), and At45dbParamWrite().
Load configuration parameters from flash memory.
pos | Start location within configuration sector. | |
data | Points to a buffer that receives the contents. | |
len | Number of bytes to read. |
Definition at line 480 of file at45db.c.
References At45dbPageRead(), At45dbParamPage(), At45dbParamSize(), free, malloc, and memcpy().
Store configuration parameters in flash memory.
pos | Start location within configuration sector. | |
data | Points to a buffer that contains the bytes to store. | |
len | Number of bytes to store. |
Definition at line 506 of file at45db.c.
References At45dbPageRead(), At45dbPageWrite(), At45dbParamPage(), At45dbParamSize(), free, malloc, memcmp(), and memcpy().
AT45_DEVTAB at45_devt[] |
Initial value:
{ {512, 264, 9, 0x3C, 0x0C}, {1025, 264, 9, 0x3C, 0x14}, {2048, 264, 9, 0x3C, 0x1C}, {4096, 264, 9, 0x3C, 0x24}, {4096, 528, 10, 0x3C, 0x2C}, {8192, 528, 10, 0x3C, 0x34}, {8192, 1056, 11, 0x38, 0x38}, {0, 0, 0, 0, 0} }
Definition at line 245 of file at45db.c.
Referenced by At45dbInit().