![]() |
LUFA Library
120219
|
Atmel Dataflash storage IC board hardware driver. More...
Modules | |
EVK527 | |
Board specific Dataflash driver header for the Atmel EVK527. | |
STK525 | |
Board specific Dataflash driver header for the Atmel STK525. | |
STK526 | |
Board specific Dataflash driver header for the Atmel STK525. | |
USBKEY | |
Board specific Dataflash driver header for the Atmel USBKEY. | |
XPLAIN_REV1 | |
Board specific Dataflash driver header for the original Atmel XPLAIN, revision 1. | |
XPLAIN | |
Board specific Dataflash driver header for the original Atmel XPLAIN. | |
B1_XPLAINED | |
Board specific Dataflash driver header for the Atmel XMEGA B1 Xplained. | |
A3BU_XPLAINED | |
Board specific Dataflash driver header for the Atmel XMEGA A3BU Xplained. | |
Defines | |
#define | DATAFLASH_CHIP_MASK(index) __GET_DATAFLASH_MASK(index) |
Functions | |
static void | Dataflash_Init (void) |
static uint8_t | Dataflash_GetSelectedChip (void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT |
static void | Dataflash_SelectChip (const uint8_t ChipMask) ATTR_ALWAYS_INLINE |
static void | Dataflash_DeselectChip (void) ATTR_ALWAYS_INLINE |
static void | Dataflash_SelectChipFromPage (const uint16_t PageAddress) |
static void | Dataflash_ToggleSelectedChipCS (void) |
static void | Dataflash_WaitWhileBusy (void) |
static void | Dataflash_SendAddressBytes (uint16_t PageAddress, const uint16_t BufferByte) |
static uint8_t | Dataflash_TransferByte (const uint8_t Byte) ATTR_ALWAYS_INLINE |
static void | Dataflash_SendByte (const uint8_t Byte) ATTR_ALWAYS_INLINE |
static uint8_t | Dataflash_ReceiveByte (void) ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT |
The following files must be built with any user project that uses this module:
Dataflash driver. This module provides an easy to use interface for the Dataflash ICs located on many boards, for the storage of large amounts of data into the Dataflash's non-volatile memory.
If the BOARD
value is set to BOARD_USER
, this will include the /Board/Dataflash
.h file in the user project directory. Otherwise, it will include the appropriate built in board driver header file.
For possible BOARD
makefile values, see Board Types.
The following snippet is an example of how this module may be used within a typical application.
// Initialize the SPI and board Dataflash drivers before first use SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_ORDER_MSB_FIRST | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER); Dataflash_Init(); uint8_t WriteBuffer[DATAFLASH_PAGE_SIZE]; uint8_t ReadBuffer[DATAFLASH_PAGE_SIZE]; // Fill page write buffer with a repeating pattern for (uint16_t i = 0; i < DATAFLASH_PAGE_SIZE; i++) WriteBuffer[i] = (i & 0xFF); // Must select the chip of interest first before operating on it Dataflash_SelectChip(DATAFLASH_CHIP1); // Write to the Dataflash's first internal memory buffer printf("Writing data to first dataflash buffer:\r\n"); Dataflash_SendByte(DF_CMD_BUFF1WRITE); Dataflash_SendAddressBytes(0, 0); for (uint16_t i = 0; i < DATAFLASH_PAGE_SIZE; i++) Dataflash_SendByte(WriteBuffer[i]); // Commit the Dataflash's first memory buffer to the non-volatile FLASH memory printf("Committing page to non-volatile memory page index 5:\r\n"); Dataflash_SendByte(DF_CMD_BUFF1TOMAINMEMWITHERASE); Dataflash_SendAddressBytes(5, 0); Dataflash_WaitWhileBusy(); // Read the page from non-volatile FLASH memory into the Dataflash's second memory buffer printf("Reading data into second dataflash buffer:\r\n"); Dataflash_SendByte(DF_CMD_MAINMEMTOBUFF2); Dataflash_SendAddressBytes(5, 0); Dataflash_WaitWhileBusy(); // Read the Dataflash's second internal memory buffer Dataflash_SendByte(DF_CMD_BUFF2READ); Dataflash_SendAddressBytes(0, 0); for (uint16_t i = 0; i < DATAFLASH_PAGE_SIZE; i++) ReadBuffer[i] = Dataflash_ReceiveByte(); // Deselect the chip after use Dataflash_DeselectChip();
#define DATAFLASH_CHIP_MASK | ( | index | ) | __GET_DATAFLASH_MASK(index) |
Retrieves the Dataflash chip select mask for the given Dataflash chip index.
[in] | index | Index of the dataflash chip mask to retrieve |
static void Dataflash_DeselectChip | ( | void | ) | [inline, static] |
Deselects the current dataflash chip, so that no dataflash is selected.
static uint8_t Dataflash_GetSelectedChip | ( | void | ) | [inline, static] |
Determines the currently selected dataflash chip.
DATAFLASH_CHIPn
mask (where n is the chip number). static void Dataflash_Init | ( | void | ) | [inline, static] |
Initializes the dataflash driver so that commands and data may be sent to an attached dataflash IC.
static uint8_t Dataflash_ReceiveByte | ( | void | ) | [inline, static] |
Sends a dummy byte to the currently selected dataflash IC, and returns the next byte from the dataflash.
static void Dataflash_SelectChip | ( | const uint8_t | ChipMask | ) | [inline, static] |
Selects the given dataflash chip.
[in] | ChipMask | Mask of the Dataflash IC to select, in the form of DATAFLASH_CHIPn mask (where n is the chip number). |
static void Dataflash_SelectChipFromPage | ( | const uint16_t | PageAddress | ) | [inline, static] |
Selects a dataflash IC from the given page number, which should range from 0 to ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). For boards containing only one dataflash IC, this will select DATAFLASH_CHIP1. If the given page number is outside the total number of pages contained in the boards dataflash ICs, all dataflash ICs are deselected.
[in] | PageAddress | Address of the page to manipulate, ranging from 0 to ((DATAFLASH_PAGES * DATAFLASH_TOTALCHIPS) - 1). |
static void Dataflash_SendAddressBytes | ( | uint16_t | PageAddress, |
const uint16_t | BufferByte | ||
) | [inline, static] |
Sends a set of page and buffer address bytes to the currently selected dataflash IC, for use with dataflash commands which require a complete 24-bit address.
[in] | PageAddress | Page address within the selected dataflash IC |
[in] | BufferByte | Address within the dataflash's buffer |
static void Dataflash_SendByte | ( | const uint8_t | Byte | ) | [inline, static] |
Sends a byte to the currently selected dataflash IC, and ignores the next byte from the dataflash.
[in] | Byte | Byte of data to send to the dataflash |
static void Dataflash_ToggleSelectedChipCS | ( | void | ) | [inline, static] |
Toggles the select line of the currently selected dataflash IC, so that it is ready to receive a new command.
static uint8_t Dataflash_TransferByte | ( | const uint8_t | Byte | ) | [inline, static] |
Sends a byte to the currently selected dataflash IC, and returns a byte from the dataflash.
[in] | Byte | Byte of data to send to the dataflash |
static void Dataflash_WaitWhileBusy | ( | void | ) | [inline, static] |
Spin-loops while the currently selected dataflash is busy executing a command, such as a main memory page program or main memory to buffer transfer.