From d4b5073d22a2a8f0cfd26739eb57f35b5984e1bc Mon Sep 17 00:00:00 2001 From: qwert Date: Mon, 4 Aug 2008 15:45:57 +0000 Subject: [PATCH] Refactor KFileDataFlash in DataFlashKFile. Tested and working. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1540 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/drv/dataflash.c | 26 +++++++++++++------------- bertos/drv/dataflash.h | 12 ++++++------ bertos/drv/dataflash_test.c | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/bertos/drv/dataflash.c b/bertos/drv/dataflash.c index f70628fb..158a9b3f 100644 --- a/bertos/drv/dataflash.c +++ b/bertos/drv/dataflash.c @@ -106,7 +106,7 @@ STATIC_ASSERT(countof(mem_info) == DFT_CNT); * Macro that toggle CS of dataflash. * \note This is equivalent to fd->setCS(false) immediately followed by fd->setCS(true). */ -INLINE void CS_TOGGLE(KFileDataflash *fd) +INLINE void CS_TOGGLE(DataFlashKFile *fd) { fd->setCS(false); fd->setCS(true); @@ -117,7 +117,7 @@ INLINE void CS_TOGGLE(KFileDataflash *fd) * This function send only 4 byte: opcode, page address and * byte address. */ -static void send_cmd(KFileDataflash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode) +static void send_cmd(DataFlashKFile *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode) { /* @@ -166,7 +166,7 @@ static void send_cmd(KFileDataflash *fd, dataflash_page_t page_addr, dataflash_o * with one pulse reset long about 10usec. * */ -static void dataflash_reset(KFileDataflash *fd) +static void dataflash_reset(DataFlashKFile *fd) { fd->setCS(false); @@ -183,7 +183,7 @@ static void dataflash_reset(KFileDataflash *fd) /** * Read status register of dataflah memory. */ -static uint8_t dataflash_stat(KFileDataflash *fd) +static uint8_t dataflash_stat(DataFlashKFile *fd) { /* * Make sure to toggle CS signal @@ -200,7 +200,7 @@ static uint8_t dataflash_stat(KFileDataflash *fd) * return status register value. * */ -static uint8_t dataflash_cmd(KFileDataflash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode) +static uint8_t dataflash_cmd(DataFlashKFile *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode) { uint8_t stat; @@ -234,7 +234,7 @@ static uint8_t dataflash_cmd(KFileDataflash *fd, dataflash_page_t page_addr, dat * Read \a len bytes from main data flash memory or buffer data * flash memory, and put it in \a *block. */ -static void dataflash_readBlock(KFileDataflash *fd, dataflash_page_t page_addr, dataflash_offset_t byte_addr, DataFlashOpcode opcode, uint8_t *block, dataflash_size_t len) +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) { send_cmd(fd, page_addr, byte_addr, opcode); @@ -261,7 +261,7 @@ static void dataflash_readBlock(KFileDataflash *fd, dataflash_page_t page_addr, * 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(KFileDataflash *fd, dataflash_offset_t offset, DataFlashOpcode opcode, const uint8_t *block, dataflash_size_t len) +static void dataflash_writeBlock(DataFlashKFile *fd, dataflash_offset_t offset, DataFlashOpcode opcode, const uint8_t *block, dataflash_size_t len) { ASSERT(offset + len <= mem_info[fd->dev].page_size); @@ -277,7 +277,7 @@ static void dataflash_writeBlock(KFileDataflash *fd, dataflash_offset_t offset, /** * Load selct page from dataflash memory to buffer. */ -static void dataflash_loadPage(KFileDataflash *fd, dataflash_page_t page_addr) +static void dataflash_loadPage(DataFlashKFile *fd, dataflash_page_t page_addr) { dataflash_cmd(fd, page_addr, 0x00, DFO_MOV_MEM_TO_BUFF1); } @@ -287,7 +287,7 @@ static void dataflash_loadPage(KFileDataflash *fd, dataflash_page_t page_addr) */ static int dataflash_flush(KFile *_fd) { - KFileDataflash *fd = KFILEDATAFLASH(_fd); + DataFlashKFile *fd = DATAFLASHKFILE(_fd); if (fd->page_dirty) { dataflash_cmd(fd, fd->current_page, 0x00, DFO_WRITE_BUFF1_TO_MEM_E); @@ -316,7 +316,7 @@ static int dataflash_close(struct KFile *_fd) */ static KFile *dataflash_reopen(KFile *_fd) { - KFileDataflash *fd = KFILEDATAFLASH(_fd); + DataFlashKFile *fd = DATAFLASHKFILE(_fd); dataflash_close(_fd); fd->current_page = 0; @@ -344,7 +344,7 @@ static KFile *dataflash_reopen(KFile *_fd) */ static size_t dataflash_read(struct KFile *_fd, void *buf, size_t size) { - KFileDataflash *fd = KFILEDATAFLASH(_fd); + DataFlashKFile *fd = DATAFLASHKFILE(_fd); dataflash_offset_t byte_addr; dataflash_page_t page_addr; @@ -394,7 +394,7 @@ static size_t dataflash_read(struct KFile *_fd, void *buf, size_t size) */ static size_t dataflash_write(struct KFile *_fd, const void *_buf, size_t size) { - KFileDataflash *fd = KFILEDATAFLASH(_fd); + DataFlashKFile *fd = DATAFLASHKFILE(_fd); dataflash_offset_t offset; dataflash_page_t new_page; @@ -458,7 +458,7 @@ MOD_DEFINE(dataflash); * \return true if ok, false if memory density read from dataflash is not compliant with the * configured one. */ -bool dataflash_init(KFileDataflash *fd, KFile *ch, DataflashType dev, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset) +bool dataflash_init(DataFlashKFile *fd, KFile *ch, DataflashType dev, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset) { uint8_t stat; diff --git a/bertos/drv/dataflash.h b/bertos/drv/dataflash.h index 8fd3a4f7..0b12d9d1 100644 --- a/bertos/drv/dataflash.h +++ b/bertos/drv/dataflash.h @@ -81,7 +81,7 @@ typedef enum DataflashType /** * Dataflash KFile context structure. */ -typedef struct KFileDataflash +typedef struct DataFlashKFile { KFile fd; ///< File descriptor. KFile *channel; ///< Dataflash comm channel (usually SPI). @@ -90,7 +90,7 @@ typedef struct KFileDataflash 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. -} KFileDataflash; +} DataFlashKFile; /** * ID for dataflash. @@ -98,12 +98,12 @@ typedef struct KFileDataflash #define KFT_DATAFLASH MAKE_ID('D', 'F', 'L', 'H') /** - * Convert + ASSERT from generic KFile to KFileDataflash. + * Convert + ASSERT from generic KFile to DataFlashKFile. */ -INLINE KFileDataflash * KFILEDATAFLASH(KFile *fd) +INLINE DataFlashKFile * DATAFLASHKFILE(KFile *fd) { ASSERT(fd->_type == KFT_DATAFLASH); - return (KFileDataflash *)fd; + return (DataFlashKFile *)fd; } #define RESET_PULSE_WIDTH 10 ///< Width of reset pulse in usec. @@ -181,7 +181,7 @@ typedef struct DataflashInfo } DataflashInfo; -bool dataflash_init(KFileDataflash *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset); +bool dataflash_init(DataFlashKFile *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset); /** * To test data falsh drive you could use diff --git a/bertos/drv/dataflash_test.c b/bertos/drv/dataflash_test.c index 0774f084..8e40168b 100644 --- a/bertos/drv/dataflash_test.c +++ b/bertos/drv/dataflash_test.c @@ -96,7 +96,7 @@ * Kfile structure to test a dataflash. */ static SerialKFile spi_fd; -static KFileDataflash dflash_fd; +static DataFlashKFile dflash_fd; /* * Define tmp buffer to stora data for -- 2.25.1