From 6f470322d0241e1923bd1d83d66f291aff571658 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 4 Jan 2013 15:11:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5032 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/fs/fatfs/fatfs_fsimpl.cpp | 83 +++++++++++++++++++++++++++++++++++++++++--- os/fs/fatfs/fatfs_fsimpl.hpp | 74 +++++++++++++++++++++++++++++++++------ os/fs/fs.hpp | 14 ++++---- 3 files changed, 149 insertions(+), 22 deletions(-) (limited to 'os/fs') diff --git a/os/fs/fatfs/fatfs_fsimpl.cpp b/os/fs/fatfs/fatfs_fsimpl.cpp index e63f71323..c10c1a89f 100644 --- a/os/fs/fatfs/fatfs_fsimpl.cpp +++ b/os/fs/fatfs/fatfs_fsimpl.cpp @@ -44,14 +44,82 @@ using namespace chibios_fs; */ namespace chibios_fatfs { + typedef struct { + uint32_t msg_code; + union { + struct { + + }; + } op; + } wmsg_t; + + /*------------------------------------------------------------------------* + * chibios_fatfs::FatFSFileWrapper * + *------------------------------------------------------------------------*/ + FatFSFileWrapper::FatFSFileWrapper(void) : fs(NULL) { + + } + + FatFSFileWrapper::FatFSFileWrapper(FatFSWrapper *fsref) : fs(fsref) { + + } + + size_t FatFSFileWrapper::write(const uint8_t *bp, size_t n) { + + return 0; + } + + size_t FatFSFileWrapper::read(uint8_t *bp, size_t n) { + + return 0; + } + + msg_t FatFSFileWrapper::put(uint8_t b) { + + return 0; + } + + msg_t FatFSFileWrapper::get(void) { + + return 0; + } + + uint32_t FatFSFileWrapper::getAndClearLastError(void) { + + return 0; + } + + fileoffset_t FatFSFileWrapper::getSize(void) { + + return 0; + } + + fileoffset_t FatFSFileWrapper::getPosition(void) { + + return 0; + } + + uint32_t FatFSFileWrapper::setPosition(fileoffset_t offset) { + + return 0; + } + + /*------------------------------------------------------------------------* + * chibios_fatfs::FatFSFilesPool * + *------------------------------------------------------------------------*/ + FatFSFilesPool::FatFSFilesPool(void) : MemoryPoolBuffer() { + + } + /*------------------------------------------------------------------------* - * chibios_fatfs::FatFSWrapper::FatFSServerThread * + * chibios_fatfs::FatFSServerThread * *------------------------------------------------------------------------*/ - FatFSWrapper::FatFSServerThread::FatFSServerThread(void) : + FatFSServerThread::FatFSServerThread(void) : BaseStaticThread() { } - msg_t FatFSWrapper::FatFSServerThread::main() { + msg_t FatFSServerThread::main() { msg_t sts; setName("fatfs"); @@ -72,14 +140,14 @@ namespace chibios_fatfs { } } - void FatFSWrapper::FatFSServerThread::stop(void) { + void FatFSServerThread::stop(void) { sendMessage(MSG_TERMINATE); wait(); } /*------------------------------------------------------------------------* - * chibios_fatfs::FatFSWrapper * + * chibios_fatfs::FatFSWrapper * *------------------------------------------------------------------------*/ FatFSWrapper::FatFSWrapper(void) { @@ -132,6 +200,11 @@ namespace chibios_fatfs { (void)fname; return NULL; } + + void FatFSWrapper::close(BaseFileStreamInterface *file) { + + (void)file; + } } /** @} */ diff --git a/os/fs/fatfs/fatfs_fsimpl.hpp b/os/fs/fatfs/fatfs_fsimpl.hpp index cdb46bc66..2ab7fc4b0 100644 --- a/os/fs/fatfs/fatfs_fsimpl.hpp +++ b/os/fs/fatfs/fatfs_fsimpl.hpp @@ -46,6 +46,13 @@ #define FATFS_THREAD_PRIORITY NORMALPRIO #endif +/** + * @brief Maximum number of open files. + */ +#if !defined(FATFS_MAX_FILES) || defined(__DOXYGEN__) +#define FATFS_MAX_FILES 16 +#endif + using namespace chibios_rt; using namespace chibios_fs; @@ -54,6 +61,59 @@ using namespace chibios_fs; */ namespace chibios_fatfs { + class FatFSWrapper; + + /*------------------------------------------------------------------------* + * chibios_fatfs::FatFSFileWrapper * + *------------------------------------------------------------------------*/ + class FatFSFileWrapper : public BaseFileStreamInterface { + friend class FatFSWrapper; + + protected: + FatFSWrapper *fs; + + public: + FatFSFileWrapper(void); + FatFSFileWrapper(FatFSWrapper *fsref); + + virtual size_t write(const uint8_t *bp, size_t n); + virtual size_t read(uint8_t *bp, size_t n); + virtual msg_t put(uint8_t b); + virtual msg_t get(void); + virtual uint32_t getAndClearLastError(void); + virtual fileoffset_t getSize(void); + virtual fileoffset_t getPosition(void); + virtual uint32_t setPosition(fileoffset_t offset); + }; + + /*------------------------------------------------------------------------* + * chibios_fatfs::FatFSFilesPool * + *------------------------------------------------------------------------*/ + /** + * @brief Class of memory pool of @p FatFSFileWrapper objects. + */ + class FatFSFilesPool : public MemoryPoolBuffer { + public: + FatFSFilesPool(void); + }; + + /*------------------------------------------------------------------------* + * chibios_fatfs::FatFSServerThread * + *------------------------------------------------------------------------*/ + /** + * @brief Class of the internal server thread. + */ + class FatFSServerThread : public BaseStaticThread { + private: + FatFSFilesPool files; + protected: + virtual msg_t main(void); + public: + FatFSServerThread(void); + virtual void stop(void); + }; + /*------------------------------------------------------------------------* * chibios_fatfs::FatFSWrapper * *------------------------------------------------------------------------*/ @@ -61,17 +121,10 @@ namespace chibios_fatfs { * @brief Class of the FatFS wrapper. */ class FatFSWrapper : public chibios_fs::BaseFileSystemInterface { + friend class FatFSFileWrapper; + protected: - /** - * @brief Class of the internal server thread. - */ - class FatFSServerThread : public BaseStaticThread { - protected: - virtual msg_t main(void); - public: - FatFSServerThread(void); - virtual void stop(void); - } server; + FatFSServerThread server; public: FatFSWrapper(void); @@ -82,6 +135,7 @@ namespace chibios_fatfs { virtual BaseFileStreamInterface *openForRead(const char *fname); virtual BaseFileStreamInterface *openForWrite(const char *fname); virtual BaseFileStreamInterface *create(const char *fname); + virtual void close(BaseFileStreamInterface *file); /** * @brief Mounts the file system. diff --git a/os/fs/fs.hpp b/os/fs/fs.hpp index ed4a3e177..55ef664f3 100644 --- a/os/fs/fs.hpp +++ b/os/fs/fs.hpp @@ -64,13 +64,6 @@ namespace chibios_fs { */ class BaseFileStreamInterface : public chibios_rt::BaseSequentialStreamInterface { public: - /** - * @brief File close and object destruction. - * - * @api - */ - virtual ~BaseFileStreamInterface(void) = 0; - /** * @brief Returns an implementation dependent error code. * @@ -191,6 +184,13 @@ namespace chibios_fs { * @api */ virtual BaseFileStreamInterface *create(const char *fname) = 0; + + /** + * @brief Closes a file. + * + * @api + */ + virtual void close(BaseFileStreamInterface *file) = 0; }; } #endif /* _FS_HPP_ */ -- cgit v1.2.3