This is a driver for the AT45dbX series DataFlash memories.
It provides functions for initialization, read and write operations at byte or sector level. The DataFlash driver can be used either with SPI Master Service or USART_SPI Service. The SPI service configuration depends on AT45DBX_USES_SPI_MASTER_SERVICE or AT45DBX_USES_USART_SPI_SERVICE defined in conf_at45dbx.h.
This driver depends on the following modules:
Macros | |
#define | AT45DBX_SECTOR_BITS 9 |
Number of bits for addresses within logical sectors of file system. More... | |
#define | AT45DBX_SECTOR_SIZE (1 << AT45DBX_SECTOR_BITS) |
Logical sector size of file system in bytes. More... | |
Control Functions | |
static void | at45dbx_chipselect_df (uint8_t memidx, bool bSelect) |
Selects or unselects a DF memory. More... | |
static void | at45dbx_wait_ready (void) |
Available AT45DBX Sizes | |
Number of address bits of available AT45DBX data flash memories.
| |
#define | AT45DBX_500KB 19 |
#define | AT45DBX_1MB 20 |
#define | AT45DBX_2MB 21 |
#define | AT45DBX_4MB 22 |
#define | AT45DBX_8MB 23 |
Control Functions | |
bool | at45dbx_init (void) |
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 DataFlash memories. More... | |
bool | at45dbx_read_sector_open (uint32_t sector) |
Opens a DataFlash memory in read mode at a given sector. More... | |
bool | at45dbx_read_byte_open (uint32_t ad) |
Opens a DataFlash memory in read mode at a given byte address. More... | |
void | at45dbx_read_close (void) |
Unselects the current DataFlash memory. More... | |
bool | at45dbx_write_sector_open (uint32_t sector) |
This function opens a DataFlash memory in write mode at a given sector. More... | |
bool | at45dbx_write_byte_open (uint32_t ad) |
This function opens a DataFlash memory in write mode at a given address. More... | |
void | at45dbx_write_close (void) |
Fills the end of the current logical sector and launches page programming. More... | |
Single-Byte Access Functions | |
uint8_t | at45dbx_read_byte (void) |
Performs a single byte read from DataFlash memory. More... | |
bool | at45dbx_write_byte (uint8_t b) |
Performs a single byte write to DataFlash memory. More... | |
Single-Sector Access Functions | |
bool | at45dbx_read_sector_to_ram (void *ram) |
Reads one DataFlash sector to a RAM buffer. More... | |
bool | at45dbx_write_sector_from_ram (const void *ram) |
Writes one DataFlash sector from a RAM buffer. More... | |
Functions to connect the DataFlash driver with the SPI Multiple-Sector Access Functions | |
void | at45dbx_spi_init (void) |
Initialize SPI external resource for AT45dbx DataFlash driver. More... | |
void | at45dbx_spi_select_device (uint8_t mem_id) |
Select one external DataFlash component. More... | |
void | at45dbx_spi_deselect_device (uint8_t mem_id) |
Unselect one external DataFlash component. More... | |
void | at45dbx_spi_write_byte (uint8_t data) |
Send one byte to the DataFlash. More... | |
void | at45dbx_spi_read_byte (uint8_t *data) |
Get one byte (read) from the DataFlash. More... | |
void | at45dbx_spi_read_packet (void const *data, size_t len) |
Receive a sequence of bytes from a DataFlash. More... | |
void | at45dbx_spi_write_packet (void const *data, size_t len) |
Send a sequence of bytes to a DataFlash from. More... | |
#define AT45DBX_1MB 20 |
#define AT45DBX_2MB 21 |
#define AT45DBX_4MB 22 |
#define AT45DBX_500KB 19 |
#define AT45DBX_8MB 23 |
#define AT45DBX_SECTOR_BITS 9 |
Number of bits for addresses within logical sectors of file system.
Referenced by at45dbx_read_byte(), at45dbx_read_sector_open(), at45dbx_usb_read_10(), at45dbx_usb_write_10(), and at45dbx_write_sector_open().
#define AT45DBX_SECTOR_SIZE (1 << AT45DBX_SECTOR_BITS) |
Logical sector size of file system in bytes.
Referenced by at45dbx_usb_read_10(), at45dbx_usb_write_10(), and at45dbx_write_sector_from_ram().
|
static |
Selects or unselects a DF memory.
memidx | Memory ID of DF to select or unselect. |
bSelect | Boolean indicating whether the DF memory has to be selected. |
References at45dbx_spi_deselect_device(), and at45dbx_spi_select_device().
Referenced by at45dbx_mem_check(), at45dbx_read_byte(), at45dbx_read_byte_open(), at45dbx_read_close(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_byte_open(), at45dbx_write_close(), and at45dbx_write_sector_from_ram().
bool at45dbx_init | ( | void | ) |
Initializes the data flash controller and the SPI channel by which the DF is controlled.
true | Success. |
false | Failure. |
bool at45dbx_mem_check | ( | void | ) |
Performs a memory check on all DataFlash memories.
true | Success. |
false | Failure. |
References at45dbx_chipselect_df(), AT45DBX_CMDC_RD_STATUS_REG, AT45DBX_MSK_DENSITY, at45dbx_spi_read_byte(), at45dbx_spi_write_byte(), and status.
Referenced by at45dbx_test_unit_ready().
uint8_t at45dbx_read_byte | ( | void | ) |
Performs a single byte read from DataFlash memory.
References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, at45dbx_read_sector_open(), AT45DBX_SECTOR_BITS, at45dbx_spi_read_byte(), data, and Rd_bitfield.
bool at45dbx_read_byte_open | ( | uint32_t | ad | ) |
Opens a DataFlash memory in read mode at a given byte address.
ad | Start address. |
true | Success. |
false | Failure. |
References addr, at45dbx_busy, at45dbx_check_address(), at45dbx_chipselect_df(), AT45DBX_CMDA_RD_PAGE, at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, AT45DBX_MSK_PTR_PAGE, at45dbx_spi_write_byte(), at45dbx_wait_ready(), LSB0W, LSB1W, LSB2W, and Rd_bitfield.
Referenced by at45dbx_read_sector_open().
void at45dbx_read_close | ( | void | ) |
Unselects the current DataFlash memory.
References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), and at45dbx_gl_ptr_mem.
Referenced by at45dbx_df_2_ram(), and at45dbx_usb_read_10().
bool at45dbx_read_sector_open | ( | uint32_t | sector | ) |
Opens a DataFlash memory in read mode at a given sector.
sector | Start sector. |
true | Success. |
false | Failure. |
References at45dbx_check_address(), at45dbx_read_byte_open(), and AT45DBX_SECTOR_BITS.
Referenced by at45dbx_df_2_ram(), at45dbx_read_byte(), and at45dbx_usb_read_10().
bool at45dbx_read_sector_to_ram | ( | void * | ram | ) |
Reads one DataFlash sector to a RAM buffer.
Data flow is: DataFlash -> RAM.
ram | Pointer to RAM buffer. |
true | Success. |
false | Failure. |
Referenced by at45dbx_df_2_ram(), and at45dbx_usb_read_10().
|
inline |
Unselect one external DataFlash component.
mem_id | The DataFlash index number. |
References AT45DBX_DESELECT, and MREPEAT.
Referenced by at45dbx_chipselect_df().
|
inline |
Initialize SPI external resource for AT45dbx DataFlash driver.
This function initializes the DataFlash component as well as the SPI service the memory is connected to.
References spi_enable(), spi_is_enabled(), spi_master_init(), and usart_spi_init().
|
inline |
Get one byte (read) from the DataFlash.
References at45dbx_drv_read_packet.
Referenced by at45dbx_mem_check(), at45dbx_read_byte(), and at45dbx_wait_ready().
|
inline |
Receive a sequence of bytes from a DataFlash.
data | data buffer to read |
len | Length of data |
References at45dbx_drv_read_packet.
|
inline |
Select one external DataFlash component.
mem_id | The DataFlash index number. |
References AT45DBX_SELECT, and MREPEAT.
Referenced by at45dbx_chipselect_df().
|
inline |
Send one byte to the DataFlash.
data | The data byte to send. |
References at45dbx_drv_write_packet.
Referenced by at45dbx_mem_check(), at45dbx_read_byte_open(), at45dbx_wait_ready(), at45dbx_write_byte(), at45dbx_write_byte_open(), and at45dbx_write_close().
|
inline |
Send a sequence of bytes to a DataFlash from.
data | data buffer to write |
len | Length of data |
References at45dbx_drv_write_packet.
Referenced by at45dbx_write_sector_from_ram().
|
static |
References AT45DBX_BUSY, at45dbx_chipselect_df(), AT45DBX_CMDC_RD_STATUS_REG, at45dbx_gl_ptr_mem, AT45DBX_MSK_BUSY, at45dbx_spi_read_byte(), at45dbx_spi_write_byte(), and status.
Referenced by at45dbx_read_byte_open(), and at45dbx_write_byte_open().
bool at45dbx_write_byte | ( | uint8_t | b | ) |
Performs a single byte write to DataFlash memory.
b | The byte to write. |
true | Success. |
false | Failure. |
References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, at45dbx_spi_write_byte(), at45dbx_write_byte_open(), and Rd_bitfield.
bool at45dbx_write_byte_open | ( | uint32_t | ad | ) |
This function opens a DataFlash memory in write mode at a given address.
ad | Start address. |
true | Success. |
false | Failure. |
References addr, at45dbx_busy, at45dbx_check_address(), at45dbx_chipselect_df(), AT45DBX_CMDB_PR_PAGE_TH_BUF1, AT45DBX_CMDB_XFR_PAGE_TO_BUF1, at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, AT45DBX_MSK_PTR_PAGE, at45dbx_spi_write_byte(), at45dbx_wait_ready(), LSB0W, LSB1W, LSB2W, and Rd_bitfield.
Referenced by at45dbx_write_byte(), at45dbx_write_sector_from_ram(), and at45dbx_write_sector_open().
void at45dbx_write_close | ( | void | ) |
Fills the end of the current logical sector and launches page programming.
References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_SECTOR, at45dbx_spi_write_byte(), and Rd_bitfield.
Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().
bool at45dbx_write_sector_from_ram | ( | const void * | ram | ) |
Writes one DataFlash sector from a RAM buffer.
Data flow is: RAM -> DataFlash.
ram | Pointer to RAM buffer. |
true | Success. |
false | Failure. |
References at45dbx_busy, AT45DBX_CHIP_UNSELECT, at45dbx_chipselect_df(), at45dbx_gl_ptr_mem, AT45DBX_MSK_PTR_BYTE, AT45DBX_PAGE_SIZE, AT45DBX_SECTOR_SIZE, at45dbx_spi_write_packet(), at45dbx_write_byte_open(), and Rd_bitfield.
Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().
bool at45dbx_write_sector_open | ( | uint32_t | sector | ) |
This function opens a DataFlash memory in write mode at a given sector.
sector | Start sector. |
true | Success. |
false | Failure. |
References at45dbx_check_address(), AT45DBX_SECTOR_BITS, and at45dbx_write_byte_open().
Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().