Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AT45DBX DataFlash (from ASF ver. 1)

Driver for the AT45dbX series SPI DataFlash memories (from ASF V1).

It provides functions for initialization and read/write operations at byte or sector level.

Modules

 

Macros

#define AT45DBX_SECTOR_BITS   9
 Number of bits for addresses within sectors. More...
 
#define AT45DBX_SECTOR_SIZE   (1 << AT45DBX_SECTOR_BITS)
 Sector size in bytes. More...
 

Control Functions

static void at45dbx_chipselect_df (U8 memidx, bool bSelect)
 Selects or unselects a DF memory. More...
 
static void at45dbx_wait_ready (void)
 Waits until the DF is ready. More...
 

Available AT45DBX Sizes

Number of address bits of available AT45DBX data flash memories.

Note
Only memories with page sizes of at least 512 bytes (sector size) are supported.
#define AT45DBX_2MB   21
 
#define AT45DBX_4MB   22
 
#define AT45DBX_8MB   23
 

Control Functions

bool at45dbx_init (spi_options_t spiOptions, unsigned int pba_hz)
 Initializes the data flash controller and the SPI channel by which the DF is controlled. More...
 
bool at45dbx_mem_check (void)
 Performs a memory check on all DFs. More...
 
bool at45dbx_read_open (U32 sector)
 Opens a DF memory in read mode at a given sector. More...
 
void at45dbx_read_close (void)
 Unselects the current DF memory. More...
 
bool at45dbx_write_open (U32 sector)
 This function opens a DF memory in write mode at a given sector. More...
 
void at45dbx_write_close (void)
 Fills the end of the current logical sector and launches page programming. More...
 

Single-Byte Access Functions

U8 at45dbx_read_byte (void)
 Performs a single byte read from DF memory. More...
 
bool at45dbx_write_byte (U8 b)
 Performs a single byte write to DF memory. More...
 

Multiple-Sector Access Functions

bool at45dbx_read_multiple_sector (U16 nb_sector)
 Reads nb_sector sectors from DF memory. More...
 
void at45dbx_read_multiple_sector_callback (const void *psector)
 Callback function invoked after each sector read during at45dbx_read_multiple_sector. More...
 
bool at45dbx_write_multiple_sector (U16 nb_sector)
 Writes nb_sector sectors to DF memory. More...
 
void at45dbx_write_multiple_sector_callback (void *psector)
 Callback function invoked before each sector write during at45dbx_write_multiple_sector. More...
 

Single-Sector Access Functions

bool at45dbx_read_sector_2_ram (void *ram)
 Reads 1 DF sector to a RAM buffer. More...
 
bool at45dbx_write_sector_from_ram (const void *ram)
 Writes 1 DF sector from a RAM buffer. More...
 

#define AT45DBX_2MB   21
#define AT45DBX_4MB   22
#define AT45DBX_8MB   23
#define AT45DBX_SECTOR_BITS   9

Number of bits for addresses within sectors.

#define AT45DBX_SECTOR_SIZE   (1 << AT45DBX_SECTOR_BITS)

Sector size in bytes.

static void at45dbx_chipselect_df ( U8  memidx,
bool  bSelect 
)
static

Selects or unselects a DF memory.

Parameters
memidxMemory ID of DF to select or unselect.
bSelectBoolean indicating whether the DF memory has to be selected.

References AT45DBX_SPI_FIRST_NPCS, spi_selectChip(), and spi_unselectChip().

Referenced by at45dbx_mem_check(), at45dbx_read_byte(), at45dbx_read_close(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_close(), at45dbx_write_open(), and at45dbx_write_sector_from_ram().

bool at45dbx_init ( spi_options_t  spiOptions,
unsigned int  pba_hz 
)

Initializes the data flash controller and the SPI channel by which the DF is controlled.

Parameters
spiOptionsInitialization options of the DF SPI channel.
pba_hzSPI module input clock frequency (PBA clock, Hz).
Return values
trueSuccess.
falseFailure.

References at45dbx_busy, AT45DBX_MEM_CNT, AT45DBX_SPI_FIRST_NPCS, spi_options_t::reg, SPI_OK, and spi_setupChipReg().

bool at45dbx_mem_check ( void  )

Performs a memory check on all DFs.

Return values
trueSuccess.
falseFailure.

Performs a memory check on all DFs.

Return values
trueSuccess.
falseFailure.

References at45dbx_chipselect_df(), AT45DBX_CMDC_RD_STATUS_REG, AT45DBX_DENSITY, AT45DBX_MEM_CNT, AT45DBX_MSK_DENSITY, at45dbx_spi_read_byte(), at45dbx_spi_write_byte(), spi_read(), spi_write(), spi_write_dummy, and status.

Referenced by at45dbx_example_check_mem(), at45dbx_test_unit_ready(), main(), nvm_init(), and run_memory_check_test().

U8 at45dbx_read_byte ( void  )

Performs a single byte read from DF memory.

Returns
The read byte.
Note
First call must be preceded by a call to the at45dbx_read_open function.

Performs a single byte read from DF memory.

Returns
The read byte.
Note
First call must be preceded by a call to the at45dbx_read_byte_open function.

References at45dbx_busy, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, at45dbx_read_open(), at45dbx_read_sector_open(), AT45DBX_SECTOR_BITS, at45dbx_spi_read_byte(), data, gl_ptr_mem, Rd_bitfield, spi_read(), and spi_write_dummy.

Referenced by at45dbx_example_test_byte_mem(), nvm_read_char(), and run_byte_access_test().

bool at45dbx_read_multiple_sector ( U16  nb_sector)

Reads nb_sector sectors from DF memory.

Data flow is: DF -> callback.

Parameters
nb_sectorNumber of contiguous sectors to read.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_read_open function.
As AT45DBX_PAGE_SIZE is always a multiple of AT45DBX_SECTOR_SIZE, there is no need to check page end for each byte.

References at45dbx_read_multiple_sector_callback(), at45dbx_read_sector_2_ram(), and sector_buf.

Referenced by at45dbx_example_test_multiple_sector(), at45dbx_usb_read_10(), and nvram_rw().

void at45dbx_read_multiple_sector_callback ( const void *  psector)
bool at45dbx_read_open ( U32  sector)
bool at45dbx_read_sector_2_ram ( void *  ram)

Reads 1 DF sector to a RAM buffer.

Data flow is: DF -> RAM.

Parameters
ramPointer to RAM buffer.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_read_open function.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, at45dbx_read_open(), AT45DBX_SECTOR_BITS, AT45DBX_SECTOR_SIZE, data, gl_ptr_mem, i, ram, Rd_bitfield, spi_read(), and spi_write_dummy.

Referenced by at45dbx_df_2_ram(), at45dbx_example_test_RAM_mem(), and at45dbx_read_multiple_sector().

static void at45dbx_wait_ready ( void  )
static
bool at45dbx_write_byte ( U8  b)

Performs a single byte write to DF memory.

Parameters
bThe byte to write.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_open function.

Performs a single byte write to DF memory.

Parameters
bThe byte to write.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_byte_open function.

References at45dbx_busy, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_SECTOR_BITS, at45dbx_spi_write_byte(), at45dbx_write_byte_open(), at45dbx_write_open(), gl_ptr_mem, Rd_bitfield, and spi_write().

Referenced by at45dbx_example_test_byte_mem(), nvm_write_char(), and run_byte_access_test().

bool at45dbx_write_multiple_sector ( U16  nb_sector)

Writes nb_sector sectors to DF memory.

Data flow is: callback -> DF.

Parameters
nb_sectorNumber of contiguous sectors to write.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_open function.
As AT45DBX_PAGE_SIZE is always a multiple of AT45DBX_SECTOR_SIZE, there is no need to check page end for each byte.

References at45dbx_write_multiple_sector_callback(), at45dbx_write_sector_from_ram(), and sector_buf.

Referenced by at45dbx_example_test_multiple_sector(), at45dbx_usb_write_10(), and nvram_rw().

void at45dbx_write_multiple_sector_callback ( void *  psector)

Callback function invoked before each sector write during at45dbx_write_multiple_sector.

Parameters
psectorPointer to sector to write.

Callback function invoked before each sector write during at45dbx_write_multiple_sector.

References AT45DBX_SECTOR_SIZE, buf, nvram::data, data_to_transfer, g_scsi_ep_ms_out, Is_usb_endpoint_enabled, Is_usb_out_received, nvram::len, nvram::off, PRIV, Union32::u32, Usb_ack_out_received_free, usb_read_ep_rxpacket(), and Usb_reset_endpoint_fifo_access.

Referenced by at45dbx_write_multiple_sector().

bool at45dbx_write_open ( U32  sector)

This function opens a DF memory in write mode at a given sector.

Parameters
sectorStart sector.
Return values
trueSuccess.
falseFailure.
Note
Sector may be page-unaligned (depending on the DF page size).
If AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE, page content is first loaded in buffer to then be partially updated by write byte or write sector functions.

References at45dbx_busy, at45dbx_chipselect_df(), AT45DBX_CMDB_PR_PAGE_TH_BUF1, AT45DBX_CMDB_XFR_PAGE_TO_BUF1, AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_MSK_PTR_PAGE, AT45DBX_SECTOR_BITS, at45dbx_wait_ready(), gl_ptr_mem, LSB0W, LSB1W, LSB2W, Rd_bitfield, and spi_write().

Referenced by at45dbx_example_test_byte_mem(), at45dbx_example_test_multiple_sector(), at45dbx_example_test_RAM_mem(), at45dbx_ram_2_df(), at45dbx_usb_write_10(), at45dbx_write_byte(), at45dbx_write_sector_from_ram(), and nvram_rw().

bool at45dbx_write_sector_from_ram ( const void *  ram)

Writes 1 DF sector from a RAM buffer.

Data flow is: RAM -> DF.

Parameters
ramPointer to RAM buffer.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_open function.

Writes 1 DF sector from a RAM buffer.

Data flow is: RAM -> DataFlash.

Parameters
ramPointer to RAM buffer.
Return values
trueSuccess.
falseFailure.
Note
First call must be preceded by a call to the at45dbx_write_sector_open function.

References at45dbx_busy, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MEM_SIZE, AT45DBX_MSK_PTR_BYTE, AT45DBX_PAGE_SIZE, AT45DBX_SECTOR_BITS, AT45DBX_SECTOR_SIZE, at45dbx_spi_write_packet(), at45dbx_write_byte_open(), at45dbx_write_open(), gl_ptr_mem, i, ram, Rd_bitfield, and spi_write().

Referenced by at45dbx_example_test_RAM_mem(), at45dbx_ram_2_df(), at45dbx_usb_write_10(), at45dbx_write_multiple_sector(), main(), nvm_write(), run_multiple_sector_access_test(), and run_sector_access_test().