spi_at45d.c File Reference

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

Go to the source code of this file.

Defines

#define AT45_WRITE_POLLS   1000

Functions

int SpiAt45dCommand (NUTDEVICE *dev, uint8_t op, uint32_t parm, int oplen, CONST void *txbuf, void *rxbuf, int xlen)
 Send DataFlash command.
uint8_t SpiAt45dStatus (NUTDEVICE *dev)
 Query the status of the DataFlash.
int SpiAt45dWaitReady (NUTDEVICE *dev, uint32_t tmo, int poll)
 Wait until DataFlash memory cycle finished.
int SpiAt45dPageErase (NUTDEVICE *dev, uint32_t pgn)
 Erase specified DataFlash page.
int SpiAt45dChipErase (NUTDEVICE *dev)
 Erase all DataFlash pages.
int SpiAt45dInit (NUTDEVICE *dev)
 Initialize the DataFlash device.
int SpiAt45dPageRead (NUTDEVICE *dev, uint32_t pgn, void *data, int len)
 Read data from DataFlash memory.
int SpiAt45dPageWrite (NUTDEVICE *dev, uint32_t pgn, CONST void *data, int len)
 Write data to DataFlash memory.
int SpiAt45dPageWrite_P (NUTDEVICE *dev, uint32_t pgn, PGM_P data, int len)
uint32_t SpiAt45dPages (NUTDEVICE *dev)
 Return the number of pages.
int SpiAt45dPageSize (NUTDEVICE *dev)
 Return the page size.
int SpiAt45dIOCtl (NUTDEVICE *dev, int req, void *conf)
 Perform block I/O device control functions.

Variables

AT45D_INFO at45d_info []
 Parameter table of known DataFlash types.
uint_fast8_t at45d_known_types = sizeof(at45d_info) / sizeof(AT45D_INFO)
 Number of known Dataflash types.


Detailed Description

Routines for Atmel AT45 serial DataFlash memory chips.

 * $Id: spi_at45d.c,v 1.2 2009/02/17 09:31:03 haraldkipp Exp $
 * 

Definition in file spi_at45d.c.


Define Documentation

#define AT45_WRITE_POLLS   1000

Definition at line 59 of file spi_at45d.c.


Function Documentation

int SpiAt45dCommand ( NUTDEVICE dev,
uint8_t  op,
uint32_t  parm,
int  oplen,
CONST void *  txbuf,
void *  rxbuf,
int  xlen 
)

Send DataFlash command.

Parameters:
dev Specifies the DataFlash device.
op Command operation code.
parm Optional command parameter.
oplen Command length.
txbuf Pointer to the transmit data buffer, may be set to NULL.
rxbuf Pointer to the receive data buffer, may be set to NULL.
xlen Number of byte to receive and/or transmit.

Definition at line 195 of file spi_at45d.c.

References _NUTDEVICE::dev_icb, and NUTASSERT.

uint8_t SpiAt45dStatus ( NUTDEVICE dev  ) 

Query the status of the DataFlash.

Parameters:
dev Specifies the Flash device.
Returns:
0 on success or -1 in case of an error.

Definition at line 208 of file spi_at45d.c.

References _NUTDEVICE::dev_icb, and NUTASSERT.

int SpiAt45dWaitReady ( NUTDEVICE dev,
uint32_t  tmo,
int  poll 
)

Wait until DataFlash memory cycle finished.

Parameters:
dev Specifies the DataFlash device.
Returns:
0 on success or -1 in case of an error.

Definition at line 221 of file spi_at45d.c.

References _NUTDEVICE::dev_icb, and NUTASSERT.

int SpiAt45dPageErase ( NUTDEVICE dev,
uint32_t  pgn 
)

Erase specified DataFlash page.

Parameters:
dev Specifies the registered DataFlash device.
pgn Page number to erase, starting at 0.
Returns:
0 on success or -1 in case of an error.

Definition at line 235 of file spi_at45d.c.

References _AT45D_INFO::at45d_pages, _AT45D_INFO::at45d_pshft, _NUTBLOCKIO::blkio_info, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, DFCMD_PAGE_ERASE, and NUTASSERT.

int SpiAt45dChipErase ( NUTDEVICE dev  ) 

Erase all DataFlash pages.

Definition at line 257 of file spi_at45d.c.

int SpiAt45dInit ( NUTDEVICE dev  ) 

Initialize the DataFlash device.

This routine determines the DataFlash type. It is internally called by Nut/OS during device registration.

The driver framework may call this function more than once.

Parameters:
dev Specifies the DataFlash device.
Returns:
0 on success or -1 if no valid DataFlash was found.

Definition at line 274 of file spi_at45d.c.

References at45d_known_types, _AT45D_INFO::at45d_pages, _AT45D_INFO::at45d_psize, AT45D_STATUS_DENSITY, AT45D_STATUS_PAGE_SIZE, _NUTBLOCKIO::blkio_blk_cnt, _NUTBLOCKIO::blkio_blk_siz, _NUTBLOCKIO::blkio_info, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, and NUTASSERT.

int SpiAt45dPageRead ( NUTDEVICE dev,
uint32_t  pgn,
void *  data,
int  len 
)

Read data from DataFlash memory.

Parameters:
dev Specifies the registered DataFlash device.
pgn Page number to read, starting at 0.
data Points to a buffer that receives the data.
len Number of bytes to read.
Returns:
The number of bytes actually read. A return value of -1 indicates an error.

Definition at line 314 of file spi_at45d.c.

References _AT45D_INFO::at45d_pages, _AT45D_INFO::at45d_pshft, _NUTBLOCKIO::blkio_info, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, DFCMD_CONT_READ, and NUTASSERT.

int SpiAt45dPageWrite ( NUTDEVICE dev,
uint32_t  pgn,
CONST void *  data,
int  len 
)

Write data to DataFlash memory.

Each page will be automatically erased before writing the data. If the last page is not completely filled with new data, the contents of remaining bytes at the end of the page is undetermined.

Parameters:
dev Specifies the registered DataFlash device.
pgn The page number.
data Points to the buffer that contains the bytes to be written.
len Number of bytes available in the buffer. This may be less than the page size, in which case the remaining bytes of the page will be set to 0xff.
Returns:
The number of bytes actually written. A return value of -1 indicates an error.

Definition at line 354 of file spi_at45d.c.

References AT45_WRITE_POLLS, _NUTBLOCKIO::blkio_info, _NUTDEVICE::dev_dcb, _NUTDEVICE::dev_icb, DFCMD_BUF1_FLASH, DFCMD_BUF1_WRITE, and NUTASSERT.

int SpiAt45dPageWrite_P ( NUTDEVICE dev,
uint32_t  pgn,
PGM_P  data,
int  len 
)

Definition at line 408 of file spi_at45d.c.

uint32_t SpiAt45dPages ( NUTDEVICE dev  ) 

Return the number of pages.

Parameters:
dev Specifies the registered DataFlash device.
Returns:
The total number of pages available in this device.

Definition at line 421 of file spi_at45d.c.

References _NUTBLOCKIO::blkio_info, _NUTDEVICE::dev_dcb, and NUTASSERT.

int SpiAt45dPageSize ( NUTDEVICE dev  ) 

Return the page size.

Parameters:
dev Specifies the registered DataFlash device.
Returns:
The number of bytes per page.

Definition at line 440 of file spi_at45d.c.

References _NUTBLOCKIO::blkio_info, _NUTDEVICE::dev_dcb, and NUTASSERT.

int SpiAt45dIOCtl ( NUTDEVICE dev,
int  req,
void *  conf 
)

Perform block I/O device control functions.

This function is called by the ioctl() function of the C runtime library. Applications should not directly call this function.

Parameters:
dev Identifies the device that receives the control command.
req Requested control command. May be set to one of the following constants:
conf Points to a buffer that contains any data required for the given control function or receives data from that function.
Returns:
0 on success, -1 otherwise.

Definition at line 469 of file spi_at45d.c.

References NUTASSERT, NUTBLKDEV_MEDIAAVAIL, and NUTBLKDEV_MEDIACHANGE.


Variable Documentation

AT45D_INFO at45d_info[]

Initial value:

 {
    {8, 512, 256, 0x0D},    
    {9, 512, 264, 0x0C},    
    {8, 1025, 256, 0x15},   
    {9, 1025, 264, 0x14},   
    {8, 2048, 256, 0x1D},   
    {9, 2048, 264, 0x1C},   
    {8, 4096, 256, 0x25},   
    {9, 4096, 264, 0x24},   
    {9, 4096, 512, 0x2D},   
    {10, 4096, 528, 0x2C},  
    {9, 8192, 512, 0x35},   
    {10, 8192, 528, 0x34},  
    {10, 8192, 1024, 0x39}, 
    {11, 8192, 1056, 0x38}, 
    {10, 8192, 1024, 0x3D}, 
    {11, 8192, 1056, 0x3C}  
}
Parameter table of known DataFlash types.

Table of known AT45D DataFlash chips.

Definition at line 63 of file spi_at45d.c.

uint_fast8_t at45d_known_types = sizeof(at45d_info) / sizeof(AT45D_INFO)

Number of known Dataflash types.

Number of known AT45D DataFlash chips.

Definition at line 83 of file spi_at45d.c.


© 2000-2007 by egnite Software GmbH - visit http://www.ethernut.de/