* Macro that toggle CS of dataflash.
* \note This is equivalent to fd->setCS(false) immediately followed by fd->setCS(true).
*/
-INLINE void CS_TOGGLE(DataFlashKFile *fd)
+INLINE void CS_TOGGLE(DataFlash *fd)
{
fd->setCS(false);
fd->setCS(true);
* This function send only 4 byte: opcode, page address and
* byte address.
*/
-static void send_cmd(DataFlashKFile *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode)
+static void send_cmd(DataFlash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode)
{
/*
* with one pulse reset long about 10usec.
*
*/
-static void dataflash_reset(DataFlashKFile *fd)
+static void dataflash_reset(DataFlash *fd)
{
fd->setCS(false);
/**
* Read status register of dataflah memory.
*/
-static uint8_t dataflash_stat(DataFlashKFile *fd)
+static uint8_t dataflash_stat(DataFlash *fd)
{
/*
* Make sure to toggle CS signal
* return status register value.
*
*/
-static uint8_t dataflash_cmd(DataFlashKFile *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode)
+static uint8_t dataflash_cmd(DataFlash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode)
{
uint8_t stat;
* Read \a len bytes from main data flash memory or buffer data
* flash memory, and put it in \a *block.
*/
-static void dataflash_readBlock(DataFlashKFile *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode, uint8_t *block, dataflash_size_t len)
+static void dataflash_readBlock(DataFlash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode, uint8_t *block, dataflash_size_t len)
{
send_cmd(fd, page_addr, byte_addr, opcode);
* To perform a write in main memory you must first write in dataflash buffer
* memory and then send a command to write the page in main memory.
*/
-static void dataflash_writeBlock(DataFlashKFile *fd, dataflash_offset_t offset, DataFlashOpcode opcode, const uint8_t *block, dataflash_size_t len)
+static void dataflash_writeBlock(DataFlash *fd, dataflash_offset_t offset, DataFlashOpcode opcode, const uint8_t *block, dataflash_size_t len)
{
ASSERT(offset + len <= mem_info[fd->dev].page_size);
/**
* Load selct page from dataflash memory to buffer.
*/
-static void dataflash_loadPage(DataFlashKFile *fd, dataflash_page_t page_addr)
+static void dataflash_loadPage(DataFlash *fd, dataflash_page_t page_addr)
{
dataflash_cmd(fd, page_addr, 0x00, DFO_MOV_MEM_TO_BUFF1);
}
*/
static int dataflash_flush(KFile *_fd)
{
- DataFlashKFile *fd = DATAFLASHKFILE(_fd);
+ DataFlash *fd = DATAFLASHKFILE(_fd);
if (fd->page_dirty)
{
dataflash_cmd(fd, fd->current_page, 0x00, DFO_WRITE_BUFF1_TO_MEM_E);
*/
static KFile *dataflash_reopen(KFile *_fd)
{
- DataFlashKFile *fd = DATAFLASHKFILE(_fd);
+ DataFlash *fd = DATAFLASHKFILE(_fd);
dataflash_close(_fd);
fd->current_page = 0;
*/
static size_t dataflash_read(struct KFile *_fd, void *buf, size_t size)
{
- DataFlashKFile *fd = DATAFLASHKFILE(_fd);
+ DataFlash *fd = DATAFLASHKFILE(_fd);
dataflash_offset_t byte_addr;
dataflash_page_t page_addr;
*/
static size_t dataflash_write(struct KFile *_fd, const void *_buf, size_t size)
{
- DataFlashKFile *fd = DATAFLASHKFILE(_fd);
+ DataFlash *fd = DATAFLASHKFILE(_fd);
dataflash_offset_t offset;
dataflash_page_t new_page;
* \return true if ok, false if memory density read from dataflash is not compliant with the
* configured one.
*/
-bool dataflash_init(DataFlashKFile *fd, KFile *ch, DataflashType dev, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset)
+bool dataflash_init(DataFlash *fd, KFile *ch, DataflashType dev, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset)
{
uint8_t stat;
/**
* Dataflash KFile context structure.
*/
-typedef struct DataFlashKFile
+typedef struct DataFlash
{
KFile fd; ///< File descriptor.
KFile *channel; ///< Dataflash comm channel (usually SPI).
bool page_dirty; ///< True if current_page is dirty (needs to be flushed).
dataflash_setReset_t *setReset; ///< Callback used to set reset pin of dataflash.
dataflash_setCS_t *setCS; ///< Callback used to set CS pin of dataflash.
-} DataFlashKFile;
+} DataFlash;
/**
* ID for dataflash.
#define KFT_DATAFLASH MAKE_ID('D', 'F', 'L', 'H')
/**
- * Convert + ASSERT from generic KFile to DataFlashKFile.
+ * Convert + ASSERT from generic KFile to DataFlash.
*/
-INLINE DataFlashKFile * DATAFLASHKFILE(KFile *fd)
+INLINE DataFlash * DATAFLASHKFILE(KFile *fd)
{
ASSERT(fd->_type == KFT_DATAFLASH);
- return (DataFlashKFile *)fd;
+ return (DataFlash *)fd;
}
#define RESET_PULSE_WIDTH 10 ///< Width of reset pulse in usec.
} DataflashInfo;
-bool dataflash_init(DataFlashKFile *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset);
+bool dataflash_init(DataFlash *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset);
/**
* To test data falsh drive you could use
/*
* Kfile structure to test a dataflash.
*/
-static SerialKFile spi_fd;
-static DataFlashKFile dflash_fd;
+static Serial spi_fd;
+static DataFlash dflash_fd;
/*
* Define tmp buffer to stora data for
/**
* Wait until flash memory is ready.
*/
-static void flash25_waitReady(Flash25KFile *fd)
+static void flash25_waitReady(Flash25 *fd)
{
uint8_t stat;
/**
* Send a single command to serial flash memory.
*/
-static void flash25_sendCmd(Flash25KFile *fd, Flash25Opcode cmd)
+static void flash25_sendCmd(Flash25 *fd, Flash25Opcode cmd)
{
CS_ENABLE();
* try to read manufacturer id of serial memory,
* then check if is equal to selected type.
*/
-static bool flash25_pin_init(Flash25KFile *fd)
+static bool flash25_pin_init(Flash25 *fd)
{
uint8_t device_id;
uint8_t manufacturer;
*/
static KFile * flash25_reopen(struct KFile *_fd)
{
- Flash25KFile *fd = FLASH25KFILE(_fd);
+ Flash25 *fd = FLASH25KFILE(_fd);
fd->fd.seek_pos = 0;
fd->fd.size = FLASH25_MEM_SIZE;
{
uint8_t *data = (uint8_t *)buf;
- Flash25KFile *fd = FLASH25KFILE(_fd);
+ Flash25 *fd = FLASH25KFILE(_fd);
ASSERT(fd->fd.seek_pos + (kfile_size_t)size <= fd->fd.size);
size = MIN((kfile_size_t)size, fd->fd.size - fd->fd.seek_pos);
flash25Size_t wr_len;
const uint8_t *data = (const uint8_t *) _buf;
- Flash25KFile *fd = FLASH25KFILE(_fd);
+ Flash25 *fd = FLASH25KFILE(_fd);
ASSERT(fd->fd.seek_pos + (kfile_size_t)size <= fd->fd.size);
* \note A sector size is FLASH25_SECTOR_SIZE.
* This operation could take a while.
*/
-void flash25_sectorErase(Flash25KFile *fd, Flash25Sector sector)
+void flash25_sectorErase(Flash25 *fd, Flash25Sector sector)
{
/*
*
* \note This operation could take a while.
*/
-void flash25_chipErase(Flash25KFile *fd)
+void flash25_chipErase(Flash25 *fd)
{
/*
* Erase all chip could take a while,
/**
* Init data flash memory interface.
*/
-void flash25_init(Flash25KFile *fd, KFile *ch)
+void flash25_init(Flash25 *fd, KFile *ch)
{
ASSERT(fd);
/**
* Flash25 KFile context structure.
*/
-typedef struct Flash25KFile
+typedef struct Flash25
{
KFile fd; ///< File descriptor.
KFile *channel; ///< Dataflash comm channel (usually SPI).
-} Flash25KFile;
+} Flash25;
/**
* ID for dataflash.
/**
- * Convert + ASSERT from generic KFile to Flash25KFile.
+ * Convert + ASSERT from generic KFile to Flash25.
*/
-INLINE Flash25KFile * FLASH25KFILE(KFile *fd)
+INLINE Flash25 * FLASH25KFILE(KFile *fd)
{
ASSERT(fd->_type == KFT_FLASH25);
- return (Flash25KFile *)fd;
+ return (Flash25 *)fd;
}
/**
FLASH25_SECT4 = 0x30000, ///< Sector 4 (0x30000 -0x3FFFF)
} Flash25Sector;
-void flash25_init(Flash25KFile *fd, KFile *ch);
-void flash25_chipErase(Flash25KFile *fd);
-void flash25_sectorErase(Flash25KFile *fd, Flash25Sector sector);
+void flash25_init(Flash25 *fd, KFile *ch);
+void flash25_chipErase(Flash25 *fd);
+void flash25_sectorErase(Flash25 *fd, Flash25Sector sector);
bool flash25_test(KFile *channel);
#endif /* DRV_FLASH25_H */
bool flash25_test(KFile *channel)
{
- Flash25KFile fd;
+ Flash25 fd;
uint8_t test_buf[256];
/*