Nut/OS  5.0.5
API Reference
at49bv.c File Reference

Routines for Atmel AT49 flash memory chips. More...

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

Defines

#define FLASH_CHIP_BASE   0x10000000
 Base address of the flash memory chip.
#define FLASH_CONF_SECTOR   0x6000
 Address offset of the configuration sector.
#define FLASH_CONF_SIZE   512
 Size of the configuration area.
#define FLASH_ERASE_WAIT   3000
#define FLASH_CHIP_ERASE_WAIT   50000
#define FLASH_WRITE_POLLS   1000
#define FLASH_UNLOCK(base)
#define FLASH_COMMAND(base, cmd)
#define FLASH_CMD_ERASE   0x80
#define FLASH_CMD_ERASE_CHIP   0x10
#define FLASH_CMD_ERASE_SECTOR   0x30
#define FLASH_CMD_ENTER_ID   0x90
#define FLASH_CMD_EXIT_ID   0xF0
#define FLASH_CMD_PROGRAM   0xA0

Typedefs

typedef unsigned short flashdat_t
typedef unsigned long flashadr_t
typedef volatile flashdat_tflashptr_t

Functions

unsigned long At49bvInit (void)
unsigned long long AT49bvReadProtectionRegister (int factory)
 Read user or factory id from protection register.
int At49bvSectorErase (unsigned int off)
 Erase sector at the specified offset.
int At49bvChipErase (void)
 Erase entire flash memory chip.
int At49bvSectorRead (unsigned int off, void *data, unsigned int len)
 Read data from flash memory.
int At49bvSectorWrite (unsigned int off, const void *data, unsigned int len)
 Write data into flash memory.
int At49bvParamRead (unsigned int pos, void *data, unsigned int len)
 Load configuration parameters from flash memory.
int At49bvParamWrite (unsigned int pos, const void *data, unsigned int len)
 Store configuration parameters in flash memory.

Detailed Description

Routines for Atmel AT49 flash memory chips.

 *
 * $Log$
 * Revision 1.6  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.5  2008/08/11 06:59:41  haraldkipp
 * BSD types replaced by stdint types (feature request #1282721).
 *
 * Revision 1.4  2008/07/17 11:51:18  olereinhardt
 * Added function AT49bvReadProtectionRegister to read the 64bit factory
 * or user id
 *
 * Revision 1.3  2006/10/08 16:48:09  haraldkipp
 * Documentation fixed
 *
 * Revision 1.2  2006/05/25 09:33:35  haraldkipp
 * Bugfix. At49bvParamWrite() returned an error when flash sector contents
 * was equal to the contents to write.
 *
 * Revision 1.1  2006/04/07 13:51:36  haraldkipp
 * AT49BV flash memory support added. A single sector may be used to
 * store system configurations in case there is no EEPROM available.
 *
 *
 * 

Define Documentation

#define FLASH_CHIP_BASE   0x10000000

Base address of the flash memory chip.

Referenced by At49bvSectorErase(), At49bvSectorRead(), and At49bvSectorWrite().

#define FLASH_CONF_SECTOR   0x6000

Address offset of the configuration sector.

Referenced by At49bvParamRead(), and At49bvParamWrite().

#define FLASH_CONF_SIZE   512

Size of the configuration area.

During write operations a buffer with this size is allocated from heap and may cause memory problems with large sectors. Thus, this value may be less than the size of the configuration sector, in which case the rest of the sector is unused.

Referenced by At49bvParamWrite().

#define FLASH_ERASE_WAIT   3000

Referenced by At49bvSectorErase().

#define FLASH_CHIP_ERASE_WAIT   50000

Referenced by At49bvChipErase().

#define FLASH_WRITE_POLLS   1000

Referenced by At49bvSectorWrite().

#define FLASH_UNLOCK (   base)
Value:
{ \
    base[0x0555] = 0xAA; \
    base[0x0AAA] = 0x55; \
}

Referenced by At49bvChipErase(), At49bvInit(), AT49bvReadProtectionRegister(), At49bvSectorErase(), and At49bvSectorWrite().

#define FLASH_COMMAND (   base,
  cmd 
)
#define FLASH_CMD_ERASE   0x80
#define FLASH_CMD_ERASE_CHIP   0x10

Referenced by At49bvChipErase().

#define FLASH_CMD_ERASE_SECTOR   0x30

Referenced by At49bvSectorErase().

#define FLASH_CMD_ENTER_ID   0x90
#define FLASH_CMD_EXIT_ID   0xF0
#define FLASH_CMD_PROGRAM   0xA0

Referenced by At49bvSectorWrite().


Typedef Documentation

typedef unsigned short flashdat_t
typedef unsigned long flashadr_t
typedef volatile flashdat_t* flashptr_t

Function Documentation

unsigned long At49bvInit ( void  )
unsigned long long AT49bvReadProtectionRegister ( int  factory)

Read user or factory id from protection register.

Parameters:
factoryIf true, read factory id, otherwise read user id
Returns:
The ID read, 64 bit long!

References FLASH_CMD_ENTER_ID, FLASH_CMD_EXIT_ID, FLASH_COMMAND, and FLASH_UNLOCK.

int At49bvSectorErase ( unsigned int  off)

Erase sector at the specified offset.

References FLASH_CHIP_BASE, FLASH_CMD_ERASE, FLASH_CMD_ERASE_SECTOR, FLASH_COMMAND, FLASH_ERASE_WAIT, and FLASH_UNLOCK.

Referenced by At49bvParamWrite().

int At49bvChipErase ( void  )

Erase entire flash memory chip.

References FLASH_CHIP_ERASE_WAIT, FLASH_CMD_ERASE, FLASH_CMD_ERASE_CHIP, FLASH_COMMAND, and FLASH_UNLOCK.

int At49bvSectorRead ( unsigned int  off,
void *  data,
unsigned int  len 
)

Read data from flash memory.

Parameters:
offStart location within the chip, 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.

References FLASH_CHIP_BASE, and memcpy().

Referenced by At49bvParamRead(), and At49bvParamWrite().

Here is the call graph for this function:

int At49bvSectorWrite ( unsigned int  off,
const void *  data,
unsigned int  len 
)

Write data into flash memory.

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

Parameters:
offStart 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.

References FLASH_CHIP_BASE, FLASH_CMD_PROGRAM, FLASH_COMMAND, FLASH_UNLOCK, FLASH_WRITE_POLLS, and rc.

Referenced by At49bvParamWrite().

int At49bvParamRead ( 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.

References At49bvSectorRead(), and FLASH_CONF_SECTOR.

Referenced by NutNvMemLoad().

Here is the call graph for this function:

int At49bvParamWrite ( 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.

References At49bvSectorErase(), At49bvSectorRead(), At49bvSectorWrite(), FLASH_CONF_SECTOR, FLASH_CONF_SIZE, free(), malloc(), memcmp(), memcpy(), and rc.

Referenced by NutNvMemSave().

Here is the call graph for this function: