Nut/OS  4.10.3
API Reference
at45db.c File Reference

Routines for Atmel AT45 serial dataflash memory chips. More...

#include <cfg/os.h>
#include <cfg/memory.h>
#include <sys/timer.h>
#include <string.h>
#include <stdlib.h>
#include <dev/at91_spi.h>
#include <dev/at45db.h>
Include dependency graph for at45db.c:

Go to the source code of this file.

Data Structures

struct  _AT45_DEVTAB
 Known device type entry. More...
struct  _AT45DB_DCB
 Active device entry. More...

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

Typedefs

typedef struct _AT45_DEVTAB AT45_DEVTAB
 Known device type entry.
typedef struct _AT45DB_DCB AT45DB_DCB
 Active device entry.

Functions

int At45dbSendCmd (int dd, uint8_t op, uint32_t parm, int len, CONST void *tdata, void *rdata, int datalen)
 Send DataFlash command.
uint8_t At45dbGetStatus (int dd)
int At45dbWaitReady (int dd, uint32_t tmo, int poll)
 Wait until flash memory cycle finished.
int At45dbInit (unsigned int spibas, unsigned int spipcs)
 Initialize dataflash at specified interface and chip select.
int At45dbPageErase (int dd, uint32_t pgn)
 Erase sector at the specified offset.
int At45dbChipErase (void)
 Erase entire flash memory chip.
int At45dbPageRead (int dd, uint32_t pgn, void *data, unsigned int len)
 Read data from flash memory.
int At45dbPageWrite (int dd, uint32_t pgn, CONST void *data, unsigned int len)
 Write data into flash memory.
uint32_t At45dbPages (int dd)
unsigned int At45dbPageSize (int dd)
uint32_t At45dbParamPage (void)
int At45dbParamSize (void)
 Get size of configuration area.
int At45dbParamRead (unsigned int pos, void *data, unsigned int len)
 Load configuration parameters from flash memory.
int At45dbParamWrite (unsigned int pos, CONST void *data, unsigned int len)
 Store configuration parameters in flash memory.

Variables

AT45_DEVTAB at45_devt []
 Table of known Dataflash types.

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).

Detailed Description

Routines for Atmel AT45 serial dataflash memory chips.

 *
 * $Log$
 * Revision 1.91 2010/12/15 15:20:42  ve2yag
 * Added MCU_AT91SAM7S family.
 *
 * Revision 1.9  2009/02/06 15:53:42  haraldkipp
 * Corrected a bug with non-negated chip selects.
 *
 * Revision 1.8  2009/01/17 11:26:46  haraldkipp
 * Getting rid of two remaining BSD types in favor of stdint.
 * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
 *
 * Revision 1.7  2008/12/15 19:18:49  haraldkipp
 * Enable DataFlash support for EIR board.
 *
 * Revision 1.6  2008/08/11 06:59:41  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.5  2008/08/06 12:51:09  haraldkipp
 * Added support for Ethernut 5 (AT91SAM9XE reference design).
 *
 * Revision 1.4  2008/02/15 17:10:43  haraldkipp
 * At45dbPageErase selected the wrong bank. Fixed. Parameter pgn (page number)
 * of At45dbPageWrite() changed from unsigned int to unsigned long.
 * New routines At45dbPages() and At45dbPageSize() allow to determine the
 * chip's layout.
 *
 * 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.


Define Documentation

#define MAX_AT45_DEVICES   1

Definition at line 93 of file at45db.c.

Referenced by At45dbInit().

#define MAX_AT45_CMDLEN   8

Definition at line 97 of file at45db.c.

Referenced by At45dbSendCmd().

#define AT45_CONF_DFSPI   SPI0_BASE

Definition at line 101 of file at45db.c.

Referenced by At45dbParamSize(), and ShowHardwareConfiguration().

#define AT45_CONF_DFPCS   1

Definition at line 105 of file at45db.c.

Referenced by At45dbParamSize(), and ShowHardwareConfiguration().

#define AT45_ERASE_WAIT   3000

Definition at line 109 of file at45db.c.

#define AT45_CHIP_ERASE_WAIT   50000

Definition at line 113 of file at45db.c.

#define AT45_WRITE_POLLS   1000

Definition at line 117 of file at45db.c.

Referenced by At45dbPageWrite().

#define DFCMD_CONT_READ_LF   0x03

Continuos read (low frequency).

Reads a continous stream in low speed mode. 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 130 of file at45db.c.

#define DFCMD_CONT_READ_HF   0x0B

Continuos read (high frequency).

Reads a continous stream in high speed mode. 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 137 of file at45db.c.

#define DFCMD_BLOCK_ERASE   0x50

Block erase.

Definition at line 140 of file at45db.c.

#define DFCMD_SECTOR_ERASE   0x7C

Sector erase.

Definition at line 143 of file at45db.c.

#define DFCMD_PAGE_ERASE   0x81

Page erase.

Definition at line 146 of file at45db.c.

Referenced by At45dbPageErase().

#define DFCMD_BUF1_PROG   0x82

Main memory page program through buffer 1.

Definition at line 149 of file at45db.c.

#define DFCMD_BUF1_FLASH   0x83

Buffer 1 flash with page erase.

Definition at line 152 of file at45db.c.

Referenced by At45dbPageWrite().

#define DFCMD_BUF1_WRITE   0x84

Buffer 1 write.

Definition at line 155 of file at45db.c.

Referenced by At45dbPageWrite().

#define DFCMD_BUF2_PROG   0x85

Main memory page program through buffer 2.

Definition at line 158 of file at45db.c.

#define DFCMD_BUF2_FLASH   0x86

Buffer 2 flash with page erase.

Definition at line 161 of file at45db.c.

#define DFCMD_BUF2_WRITE   0x87

Buffer 2 write.

Definition at line 164 of file at45db.c.

#define DFCMD_BUF1_FLASH_NE   0x88

Buffer 1 flash without page erase.

Definition at line 167 of file at45db.c.

#define DFCMD_BUF2_FLASH_NE   0x89

Buffer 2 flash without page erase.

Definition at line 170 of file at45db.c.

#define DFCMD_CHIP_ERASE   0xC7

Chip erase.

Definition at line 173 of file at45db.c.

#define DFCMD_BUF1_READ_LF   0xD1

Buffer 1 read (low frequency).

Definition at line 176 of file at45db.c.

#define DFCMD_READ_PAGE   0xD2

Read main memory page.

Automatically wraps to the first byte of the same page after the last byte had been read. The data buffers are left unchanged.

Definition at line 182 of file at45db.c.

#define DFCMD_BUF2_READ_LF   0xD3

Buffer 2 read (low frequency).

Definition at line 185 of file at45db.c.

#define DFCMD_BUF1_READ   0xD4

Buffer 1 read.

Definition at line 188 of file at45db.c.

#define DFCMD_BUF2_READ   0xD6

Buffer 2 read.

Definition at line 191 of file at45db.c.

#define DFCMD_READ_STATUS   0xD7

Read status register.

Definition at line 194 of file at45db.c.

Referenced by At45dbGetStatus().

#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 201 of file at45db.c.

Referenced by At45dbPageRead().

#define AT45DB_AT91

Definition at line 204 of file at45db.c.


Typedef Documentation

typedef struct _AT45_DEVTAB AT45_DEVTAB

Known device type entry.

typedef struct _AT45DB_DCB AT45DB_DCB

Active device entry.


Function Documentation

int At45dbSendCmd ( int  dd,
uint8_t  op,
uint32_t  parm,
int  len,
CONST void *  tdata,
void *  rdata,
int  datalen 
)

Send DataFlash command.

Parameters:
ddDevice descriptor.
opCommand operation code.
parmCommand parameter.
lenCommand length.
tdataTransmit data.
rdataReceive data buffer.
datalenData length.

Definition at line 304 of file at45db.c.

References At91SpiTransfer2(), _AT45DB_DCB::dcb_cmdbuf, MAX_AT45_CMDLEN, and memset().

Referenced by At45dbPageErase(), At45dbPageRead(), and At45dbPageWrite().

Here is the call graph for this function:

uint8_t At45dbGetStatus ( int  dd)

Definition at line 321 of file at45db.c.

References At91SpiTransfer2(), and DFCMD_READ_STATUS.

Referenced by At45dbInit(), and At45dbWaitReady().

Here is the call graph for this function:

int At45dbWaitReady ( int  dd,
uint32_t  tmo,
int  poll 
)

Wait until flash memory cycle finished.

Returns:
0 on success or -1 in case of an error.

Definition at line 336 of file at45db.c.

References At45dbGetStatus(), and NutSleep().

Referenced by At45dbPageWrite().

Here is the call graph for this function:

int At45dbInit ( unsigned int  spibas,
unsigned int  spipcs 
)

Initialize dataflash at specified interface and chip select.

Parameters:
spibasInterface base address. For ARM MCUs this may be the I/O base address of the hardware SPI.
spipcsDevice chip select.
Returns:
Device descriptor or -1 in case of an error.

Definition at line 360 of file at45db.c.

References _BV, At45dbGetStatus(), At91SpiInit(), At91SpiInitChipSelects(), At91SpiReset(), At91SpiSetModeFlags(), At91SpiSetRate(), _AT45DB_DCB::dcb_devt, _AT45DB_DCB::dcb_spibas, _AT45DB_DCB::dcb_spipcs, _AT45_DEVTAB::devt_pages, MAX_AT45_DEVICES, SPIMF_CAPRISE, SPIMF_MASTER, and SPIMF_SCKIAHI.

Referenced by At45dbParamSize().

Here is the call graph for this function:

int At45dbPageErase ( int  dd,
uint32_t  pgn 
)

Erase sector at the specified offset.

Definition at line 402 of file at45db.c.

References At45dbSendCmd(), _AT45DB_DCB::dcb_devt, _AT45_DEVTAB::devt_offs, and DFCMD_PAGE_ERASE.

Here is the call graph for this function:

int At45dbChipErase ( void  )

Erase entire flash memory chip.

Definition at line 411 of file at45db.c.

int At45dbPageRead ( int  dd,
uint32_t  pgn,
void *  data,
unsigned int  len 
)

Read data from flash memory.

Parameters:
ddDevice descriptor.
pgnPage number to read, starting at 0.
dataPoints to a buffer that receives the data.
lenNumber of bytes to read.
Returns:
0 on success or -1 in case of an error.

Definition at line 426 of file at45db.c.

References At45dbSendCmd(), _AT45DB_DCB::dcb_devt, _AT45_DEVTAB::devt_offs, and DFCMD_CONT_READ.

Referenced by At45dbParamRead(), and At45dbParamWrite().

Here is the call graph for this function:

int At45dbPageWrite ( int  dd,
uint32_t  pgn,
CONST void *  data,
unsigned int  len 
)

Write data into flash memory.

The related sector must have been erased before calling this function.

Parameters:
ddDevice descriptor.
pgnStart location within the chip, starting at 0.
dataPoints to a buffer that contains the bytes to be written.
lenNumber of bytes to write.
Returns:
0 on success or -1 in case of an error.

Definition at line 444 of file at45db.c.

References AT45_WRITE_POLLS, At45dbSendCmd(), At45dbWaitReady(), _AT45DB_DCB::dcb_devt, _AT45_DEVTAB::devt_offs, DFCMD_BUF1_FLASH, DFCMD_BUF1_WRITE, free(), and malloc().

Referenced by At45dbParamWrite().

Here is the call graph for this function:

uint32_t At45dbPages ( int  dd)

Definition at line 463 of file at45db.c.

References _AT45DB_DCB::dcb_devt, and _AT45_DEVTAB::devt_pages.

unsigned int At45dbPageSize ( int  dd)

Definition at line 468 of file at45db.c.

References _AT45DB_DCB::dcb_devt, and _AT45_DEVTAB::devt_pagsiz.

Referenced by ShowHardwareConfiguration().

uint32_t At45dbParamPage ( void  )

Definition at line 473 of file at45db.c.

References _AT45DB_DCB::dcb_devt, and _AT45_DEVTAB::devt_pages.

Referenced by At45dbParamRead(), and At45dbParamWrite().

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.

Returns:
The number of bytes available for configuration data. In case of an error, -1 is returned.

Definition at line 493 of file at45db.c.

References AT45_CONF_DFPCS, AT45_CONF_DFSPI, At45dbInit(), _AT45DB_DCB::dcb_devt, and _AT45_DEVTAB::devt_pagsiz.

Referenced by At45dbParamRead(), and At45dbParamWrite().

Here is the call graph for this function:

int At45dbParamRead ( unsigned int  pos,
void *  data,
unsigned int  len 
)

Load configuration parameters from flash memory.

Parameters:
posStart location within configuration sector.
dataPoints to a buffer that receives the contents.
lenNumber of bytes to read.
Returns:
Always 0.

Definition at line 517 of file at45db.c.

References At45dbPageRead(), At45dbParamPage(), At45dbParamSize(), free(), malloc(), and memcpy().

Referenced by NutNvMemLoad().

Here is the call graph for this function:

int At45dbParamWrite ( unsigned int  pos,
CONST void *  data,
unsigned int  len 
)

Store configuration parameters in flash memory.

Parameters:
posStart location within configuration sector.
dataPoints to a buffer that contains the bytes to store.
lenNumber of bytes to store.
Returns:
0 on success or -1 in case of an error.

Definition at line 543 of file at45db.c.

References At45dbPageRead(), At45dbPageWrite(), At45dbParamPage(), At45dbParamSize(), free(), malloc(), memcmp(), and memcpy().

Referenced by NutNvMemSave().

Here is the call graph for this function:


Variable Documentation

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}             
}

Table of known Dataflash types.

Definition at line 271 of file at45db.c.