From: qwert Date: Tue, 5 Aug 2008 16:24:46 +0000 (+0000) Subject: Refactor Dataflash and Flash25 struct. X-Git-Tag: 2.0.0~381 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8cca97771bf57082616dde340005874812fb728a;p=bertos.git Refactor Dataflash and Flash25 struct. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1553 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/drv/dataflash.c b/bertos/drv/dataflash.c index 158a9b3f..43eca7de 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(DataFlashKFile *fd) +INLINE void CS_TOGGLE(DataFlash *fd) { fd->setCS(false); fd->setCS(true); @@ -117,7 +117,7 @@ INLINE void CS_TOGGLE(DataFlashKFile *fd) * 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) { /* @@ -166,7 +166,7 @@ static void send_cmd(DataFlashKFile *fd, dataflash_page_t page_addr, dataflash_o * with one pulse reset long about 10usec. * */ -static void dataflash_reset(DataFlashKFile *fd) +static void dataflash_reset(DataFlash *fd) { fd->setCS(false); @@ -183,7 +183,7 @@ static void dataflash_reset(DataFlashKFile *fd) /** * 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 @@ -200,7 +200,7 @@ static uint8_t dataflash_stat(DataFlashKFile *fd) * 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; @@ -234,7 +234,7 @@ static uint8_t dataflash_cmd(DataFlashKFile *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(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); @@ -261,7 +261,7 @@ static void dataflash_readBlock(DataFlashKFile *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(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); @@ -277,7 +277,7 @@ static void dataflash_writeBlock(DataFlashKFile *fd, dataflash_offset_t offset, /** * 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); } @@ -287,7 +287,7 @@ static void dataflash_loadPage(DataFlashKFile *fd, dataflash_page_t page_addr) */ 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); @@ -316,7 +316,7 @@ static int dataflash_close(struct KFile *_fd) */ static KFile *dataflash_reopen(KFile *_fd) { - DataFlashKFile *fd = DATAFLASHKFILE(_fd); + DataFlash *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) { - DataFlashKFile *fd = DATAFLASHKFILE(_fd); + DataFlash *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) { - DataFlashKFile *fd = DATAFLASHKFILE(_fd); + DataFlash *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(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; diff --git a/bertos/drv/dataflash.h b/bertos/drv/dataflash.h index 0b12d9d1..1ad87ef4 100644 --- a/bertos/drv/dataflash.h +++ b/bertos/drv/dataflash.h @@ -81,7 +81,7 @@ typedef enum DataflashType /** * Dataflash KFile context structure. */ -typedef struct DataFlashKFile +typedef struct DataFlash { KFile fd; ///< File descriptor. KFile *channel; ///< Dataflash comm channel (usually SPI). @@ -90,7 +90,7 @@ typedef struct DataFlashKFile 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. @@ -98,12 +98,12 @@ typedef struct DataFlashKFile #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. @@ -181,7 +181,7 @@ typedef struct DataflashInfo } 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 diff --git a/bertos/drv/dataflash_test.c b/bertos/drv/dataflash_test.c index 8e40168b..90f24ecb 100644 --- a/bertos/drv/dataflash_test.c +++ b/bertos/drv/dataflash_test.c @@ -95,8 +95,8 @@ /* * 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 diff --git a/bertos/drv/flash25.c b/bertos/drv/flash25.c index 2e9c0652..70d9229a 100644 --- a/bertos/drv/flash25.c +++ b/bertos/drv/flash25.c @@ -64,7 +64,7 @@ /** * Wait until flash memory is ready. */ -static void flash25_waitReady(Flash25KFile *fd) +static void flash25_waitReady(Flash25 *fd) { uint8_t stat; @@ -89,7 +89,7 @@ static void flash25_waitReady(Flash25KFile *fd) /** * 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(); @@ -104,7 +104,7 @@ static void flash25_sendCmd(Flash25KFile *fd, Flash25Opcode cmd) * 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; @@ -140,7 +140,7 @@ static bool flash25_pin_init(Flash25KFile *fd) */ 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; @@ -176,7 +176,7 @@ static size_t flash25_read(struct KFile *_fd, void *buf, size_t 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); @@ -229,7 +229,7 @@ static size_t flash25_write(struct KFile *_fd, const void *_buf, size_t size) 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); @@ -294,7 +294,7 @@ static size_t flash25_write(struct KFile *_fd, const void *_buf, size_t 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) { /* @@ -341,7 +341,7 @@ void flash25_sectorErase(Flash25KFile *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, @@ -371,7 +371,7 @@ void flash25_chipErase(Flash25KFile *fd) /** * Init data flash memory interface. */ -void flash25_init(Flash25KFile *fd, KFile *ch) +void flash25_init(Flash25 *fd, KFile *ch) { ASSERT(fd); diff --git a/bertos/drv/flash25.h b/bertos/drv/flash25.h index ed89384d..86dee860 100644 --- a/bertos/drv/flash25.h +++ b/bertos/drv/flash25.h @@ -56,11 +56,11 @@ typedef uint8_t flash25Offset_t; /** * 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. @@ -69,12 +69,12 @@ typedef struct Flash25KFile /** - * 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; } /** @@ -131,9 +131,9 @@ typedef enum { 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 */ diff --git a/bertos/drv/flash25_test.c b/bertos/drv/flash25_test.c index 921cb4ea..814c1648 100644 --- a/bertos/drv/flash25_test.c +++ b/bertos/drv/flash25_test.c @@ -53,7 +53,7 @@ bool flash25_test(KFile *channel) { - Flash25KFile fd; + Flash25 fd; uint8_t test_buf[256]; /*