From 2c2c07eb47ee84d3f2a73209d0968b12c5809255 Mon Sep 17 00:00:00 2001 From: batt Date: Thu, 23 Oct 2008 17:05:59 +0000 Subject: [PATCH] Merged from external project: ********** r22538 | batt | 2008-10-23 19:05:21 +0200(gio, 23 ott 2008) | 1 line Add battfs diskinit for dataflash. ********** git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1900 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/drv/dataflash.c | 32 +++++++++++++++++++++++++++++++- bertos/drv/dataflash.h | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/bertos/drv/dataflash.c b/bertos/drv/dataflash.c index 69b4bdf0..b2fb9c86 100644 --- a/bertos/drv/dataflash.c +++ b/bertos/drv/dataflash.c @@ -277,6 +277,8 @@ static void dataflash_loadPage(DataFlash *fd, dataflash_page_t page_addr) dataflash_cmd(fd, page_addr, 0x00, DFO_MOV_MEM_TO_BUFF1); } +/* Battfs disk interface section */ + static size_t dataflash_disk_page_read(struct BattFsSuper *d, pgcnt_t page, pgaddr_t addr, void *buf, size_t len) { DataFlash *fd = DATAFLASH_CAST((KFile *)d->disk_ctx); @@ -336,6 +338,35 @@ static bool dataflash_disk_page_erase(struct BattFsSuper *d, pgcnt_t page) return true; } +static int dataflash_close(struct KFile *_fd); + +static bool dataflash_disk_close(struct BattFsSuper *d) +{ + DataFlash *fd = DATAFLASH_CAST((KFile *)d->disk_ctx); + return dataflash_close(&fd->fd) == 0; +} + +bool dataflash_diskInit(struct BattFsSuper *d, DataFlash *fd, pgcnt_t *page_array) +{ + ASSERT(d); + ASSERT(fd); + d->read = dataflash_disk_page_read; + d->load = dataflash_disk_page_load; + d->bufferWrite = dataflash_disk_buffer_write; + d->bufferRead = dataflash_disk_buffer_read; + d->save = dataflash_disk_page_save; + d->erase = dataflash_disk_page_erase; + d->close = dataflash_disk_close; + d->disk_ctx = fd; + d->page_size = mem_info[fd->dev].page_size; + d->page_count = mem_info[fd->dev].page_cnt; + ASSERT(page_array); + d->page_array = page_array; + return d->page_array && fd; +} + +/* Kfile interface section */ + /** * Flush select page (stored in buffer) in data flash main memory page. */ @@ -353,7 +384,6 @@ static int dataflash_flush(KFile *_fd) return 0; } -/* Kfile interface section */ /** * Close file \a fd. diff --git a/bertos/drv/dataflash.h b/bertos/drv/dataflash.h index 1da6105b..43a345b4 100644 --- a/bertos/drv/dataflash.h +++ b/bertos/drv/dataflash.h @@ -44,6 +44,7 @@ #include #include +#include /** * Type definitions for dflash memory. @@ -182,6 +183,7 @@ typedef struct DataflashInfo bool dataflash_init(DataFlash *fd, KFile *ch, DataflashType type, dataflash_setCS_t *setCS, dataflash_setReset_t *setReset); +bool dataflash_diskInit(struct BattFsSuper *d, DataFlash *fd, pgcnt_t *page_array); /** * To test data falsh drive you could use -- 2.25.1