Contiki 2.5
|
Files | |
file | flash-at45db.c |
Atmel Flash EEPROM AT45DB interface implementation | |
file | flash-at45db.h |
Atmel Flash EEPROM AT45DB interface definitions | |
Data Structures | |
struct | bufmgr_t |
Macros | |
#define | AT45DB_CS 1 |
#define | AT45DB_STATUS_REG 0xD7 |
#define | AT45DB_BLOCK_ERASE 0x50 |
#define | AT45DB_PAGE_ERASE 0x81 |
#define | AT45DB_PAGE_PROGRAM_1 0x82 |
#define | AT45DB_PAGE_PROGRAM_2 0x85 |
#define | AT45DB_BUFFER_1 0x84 |
#define | AT45DB_BUFFER_2 0x87 |
#define | AT45DB_BUF_1_TO_PAGE 0x83 |
#define | AT45DB_BUF_2_TO_PAGE 0x86 |
#define | AT45DB_PAGE_READ 0xD2 |
#define | AT45DB_PAGE_TO_BUF 0x55 |
#define | AT45DB_READ_BUFFER 0xD6 |
Functions | |
int8_t | at45db_init (void) |
Initialize the AT45DBxx1 Flash EEPROM. More... | |
void | at45db_erase_chip (void) |
This function erases the whole chip. More... | |
void | at45db_erase_block (uint16_t addr) |
This function erases one block (4 Kbytes) More... | |
void | at45db_erase_page (uint16_t addr) |
This function erases one page e.g. More... | |
void | at45db_write_buffer (uint16_t addr, uint8_t *buffer, uint16_t bytes) |
This function writes bytes to the active buffer, while the buffer management is done automatically. More... | |
void | at45db_buffer_to_page (uint16_t addr) |
This function copies the active buffer into the Flash EEPROM page. More... | |
void | at45db_write_page (uint16_t p_addr, uint16_t b_addr, uint8_t *buffer, uint16_t bytes) |
This function copies the data from the the pointer into the buffer, erases the EEPROM page and flashes the new content directly into the page. More... | |
void | at45db_read_page_buffered (uint16_t p_addr, uint16_t b_addr, uint8_t *buffer, uint16_t bytes) |
Bytes can be read via buffer from a Flash EEPROM page. More... | |
void | at45db_read_page_bypassed (uint16_t p_addr, uint16_t b_addr, uint8_t *buffer, uint16_t bytes) |
Bytes can be read direct (bypassed) from a Flash EEPROM page. More... | |
void | at45db_page_to_buf (uint16_t addr) |
Copies the given page into the buffer 2. More... | |
void | at45db_read_buffer (uint16_t b_addr, uint8_t *buffer, uint16_t bytes) |
This function readouts the buffer 2 data. More... | |
void | at45db_write_cmd (uint8_t *cmd) |
The command word of the AT45DBxx1 normally consists of 4 bytes. More... | |
void | at45db_busy_wait (void) |
This function waits until the busy flag of the status register is set, to detect when the AT45DBxx1 device is ready to receive new commands. | |
Variables | |
volatile uint8_t | bufmgr_t::active_buffer |
volatile uint8_t | bufmgr_t::buffer_addr [2] |
volatile uint8_t | bufmgr_t::buf_to_page_addr [2] |
volatile uint8_t | bufmgr_t::page_program [2] |
A fixed Flash EEPROM is always good to store some data. Furthermore in this project environment, the AT45DBxx1 will be used as a hardware interface between the boot section and the application section.
#define AT45DB_BLOCK_ERASE 0x50 |
Block Erase Opcode
Definition at line 82 of file flash-at45db.h.
Referenced by at45db_erase_block().
#define AT45DB_BUF_1_TO_PAGE 0x83 |
Copy Buffer 1 to page Opcode
Definition at line 108 of file flash-at45db.h.
Referenced by at45db_init().
#define AT45DB_BUF_2_TO_PAGE 0x86 |
Copy Buffer 2 to page Opcode
Definition at line 112 of file flash-at45db.h.
Referenced by at45db_init().
#define AT45DB_BUFFER_1 0x84 |
Write byte(s) to buffer 1 opcode
Definition at line 99 of file flash-at45db.h.
Referenced by at45db_init().
#define AT45DB_BUFFER_2 0x87 |
Write byte(s) to buffer 2 opcode
Definition at line 103 of file flash-at45db.h.
Referenced by at45db_init().
#define AT45DB_CS 1 |
SPI device order. The chip select number where the AT45DBxx1 Flash EEPROM is connected to the BCD-decimal decoder
Definition at line 67 of file flash-at45db.h.
Referenced by at45db_buffer_to_page(), at45db_busy_wait(), at45db_erase_block(), at45db_erase_chip(), at45db_erase_page(), at45db_init(), at45db_page_to_buf(), at45db_read_buffer(), at45db_read_page_bypassed(), at45db_write_buffer(), at45db_write_cmd(), and at45db_write_page().
#define AT45DB_PAGE_ERASE 0x81 |
#define AT45DB_PAGE_PROGRAM_1 0x82 |
Main Memory Page Program Buffer 1
Definition at line 90 of file flash-at45db.h.
Referenced by at45db_init().
#define AT45DB_PAGE_PROGRAM_2 0x85 |
Main Memory Page Program Buffer 2
Definition at line 94 of file flash-at45db.h.
Referenced by at45db_init().
#define AT45DB_PAGE_READ 0xD2 |
Read direct from Flash EEPROM page Opcode
Definition at line 116 of file flash-at45db.h.
Referenced by at45db_read_page_bypassed().
#define AT45DB_PAGE_TO_BUF 0x55 |
Transfer page to buffer 2 Opcode
Definition at line 123 of file flash-at45db.h.
Referenced by at45db_page_to_buf().
#define AT45DB_READ_BUFFER 0xD6 |
Read buffer 2 opcode
Definition at line 129 of file flash-at45db.h.
Referenced by at45db_read_buffer().
#define AT45DB_STATUS_REG 0xD7 |
Status Register Address. Bit 7 signalizes if the device is busy.
Definition at line 77 of file flash-at45db.h.
Referenced by at45db_busy_wait().
void at45db_buffer_to_page | ( | uint16_t | addr | ) |
This function copies the active buffer into the Flash EEPROM page.
Moreover it switches the active buffer to avoid latency.
addr | page address e.g. AT45DB161 (0 ... 4095) |
Definition at line 121 of file flash-at45db.c.
References at45db_busy_wait(), AT45DB_CS, at45db_write_cmd(), and mspi_chip_release().
void at45db_erase_block | ( | uint16_t | addr | ) |
This function erases one block (4 Kbytes)
addr | block address e.g. AT45DB161 (0 ... 511) |
Definition at line 82 of file flash-at45db.c.
References AT45DB_BLOCK_ERASE, at45db_busy_wait(), AT45DB_CS, at45db_write_cmd(), mspi_chip_release(), and mspi_chip_select().
void at45db_erase_chip | ( | void | ) |
This function erases the whole chip.
Definition at line 71 of file flash-at45db.c.
References at45db_busy_wait(), AT45DB_CS, at45db_write_cmd(), mspi_chip_release(), and mspi_chip_select().
void at45db_erase_page | ( | uint16_t | addr | ) |
This function erases one page e.g.
AT45DB161 (512 bytes)
addr | page address e.g. AT45DB161 (0 ... 4095) |
Definition at line 94 of file flash-at45db.c.
References at45db_busy_wait(), AT45DB_CS, AT45DB_PAGE_ERASE, at45db_write_cmd(), mspi_chip_release(), and mspi_chip_select().
int8_t at45db_init | ( | void | ) |
Initialize the AT45DBxx1 Flash EEPROM.
Definition at line 42 of file flash-at45db.c.
References AT45DB_BUF_1_TO_PAGE, AT45DB_BUF_2_TO_PAGE, AT45DB_BUFFER_1, AT45DB_BUFFER_2, AT45DB_CS, AT45DB_PAGE_PROGRAM_1, AT45DB_PAGE_PROGRAM_2, MSPI_BAUD_MAX, mspi_chip_release(), mspi_chip_select(), mspi_init(), MSPI_MODE_3, and mspi_transceive().
void at45db_page_to_buf | ( | uint16_t | addr | ) |
Copies the given page into the buffer 2.
addr | page address e.g. AT45DB161 (0 - 4095) |
Definition at line 183 of file flash-at45db.c.
References at45db_busy_wait(), AT45DB_CS, AT45DB_PAGE_TO_BUF, at45db_write_cmd(), and mspi_chip_release().
Referenced by at45db_read_page_buffered().
void at45db_read_buffer | ( | uint16_t | b_addr, |
uint8_t * | buffer, | ||
uint16_t | bytes | ||
) |
This function readouts the buffer 2 data.
b_addr | byte address within the page e.g. AT45DB161 (0 - 527) |
*buffer | Pointer to local byte buffer |
bytes | Number of bytes (e.g. byte buffer size) which have to be read to the local byte buffer |
Definition at line 197 of file flash-at45db.c.
References at45db_busy_wait(), AT45DB_CS, AT45DB_READ_BUFFER, at45db_write_cmd(), mspi_chip_release(), and mspi_transceive().
Referenced by at45db_read_page_buffered().
void at45db_read_page_buffered | ( | uint16_t | p_addr, |
uint16_t | b_addr, | ||
uint8_t * | buffer, | ||
uint16_t | bytes | ||
) |
Bytes can be read via buffer from a Flash EEPROM page.
With this function you select the page, the start byte within the page and the number of bytes you want to read.
p_addr | page address e.g. AT45DB161 (0 - 4095) |
b_addr | byte address within the page e.g. AT45DB161 (0 - 527) |
*buffer | Pointer to local byte buffer |
bytes | Number of bytes (e.g. byte buffer size) which have to be read to the local byte buffer |
Definition at line 154 of file flash-at45db.c.
References at45db_busy_wait(), at45db_page_to_buf(), and at45db_read_buffer().
void at45db_read_page_bypassed | ( | uint16_t | p_addr, |
uint16_t | b_addr, | ||
uint8_t * | buffer, | ||
uint16_t | bytes | ||
) |
Bytes can be read direct (bypassed) from a Flash EEPROM page.
With this function you select the page, the start byte within the page and the number of bytes you want to read.
p_addr | page address e.g. AT45DB161 (0 - 4095) |
b_addr | byte address within the page e.g. AT45DB161 (0 - 527) |
*buffer | Pointer to local byte buffer |
bytes | Number of bytes (e.g. byte buffer size) which have to be read to the local byte buffer |
Definition at line 162 of file flash-at45db.c.
References at45db_busy_wait(), AT45DB_CS, AT45DB_PAGE_READ, at45db_write_cmd(), mspi_chip_release(), and mspi_transceive().
void at45db_write_buffer | ( | uint16_t | addr, |
uint8_t * | buffer, | ||
uint16_t | bytes | ||
) |
This function writes bytes to the active buffer, while the buffer management is done automatically.
addr | Byte address within the buffer e.g. AT45DB161 (0 ... 527) |
*buffer | Pointer to local byte buffer |
bytes | Number of bytes (e.g. byte buffer size) which have to be written to the active buffer |
Definition at line 106 of file flash-at45db.c.
References AT45DB_CS, at45db_write_cmd(), mspi_chip_release(), and mspi_transceive().
void at45db_write_cmd | ( | uint8_t * | cmd | ) |
The command word of the AT45DBxx1 normally consists of 4 bytes.
This function enables the chip select and sends the command (opcode + address information) to the AT45DBxx1.
*cmd | Pointer to the 4 byte command array |
Definition at line 211 of file flash-at45db.c.
References AT45DB_CS, mspi_chip_select(), and mspi_transceive().
Referenced by at45db_buffer_to_page(), at45db_erase_block(), at45db_erase_chip(), at45db_erase_page(), at45db_page_to_buf(), at45db_read_buffer(), at45db_read_page_bypassed(), at45db_write_buffer(), and at45db_write_page().
void at45db_write_page | ( | uint16_t | p_addr, |
uint16_t | b_addr, | ||
uint8_t * | buffer, | ||
uint16_t | bytes | ||
) |
This function copies the data from the the pointer into the buffer, erases the EEPROM page and flashes the new content directly into the page.
p_addr | page address e.g. AT45DB161 (0 - 4095) |
b_addr | byte address within the page e.g. AT45DB161 (0 - 527) |
*buffer | Pointer to local byte buffer |
bytes | Number of bytes (e.g. byte buffer size) which have to be read to the local byte buffer |
Definition at line 135 of file flash-at45db.c.
References AT45DB_CS, at45db_write_cmd(), mspi_chip_release(), and mspi_transceive().
volatile uint8_t bufmgr_t::active_buffer |
Holds the active buffer
Definition at line 144 of file flash-at45db.h.
volatile uint8_t bufmgr_t::buf_to_page_addr[2] |
The specific "buffer to page" opcode for buffer 1 and buffer 2
Definition at line 154 of file flash-at45db.h.
volatile uint8_t bufmgr_t::buffer_addr[2] |
The specific "byte(s) to buffer" opcode for buffer 1 and buffer 2
Definition at line 149 of file flash-at45db.h.
volatile uint8_t bufmgr_t::page_program[2] |
Main Memory Page Program (Erase Page + Reprogram directly in one operation)
Definition at line 159 of file flash-at45db.h.