aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-01-04 15:11:03 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2013-01-04 15:11:03 +0000
commit6f470322d0241e1923bd1d83d66f291aff571658 (patch)
tree7841acf3bdcc48add6bea4f23a7aef794e3e9531
parent2fa014a7be21c7d893fbbb2101c97c51971321b9 (diff)
downloadChibiOS-6f470322d0241e1923bd1d83d66f291aff571658.tar.gz
ChibiOS-6f470322d0241e1923bd1d83d66f291aff571658.tar.bz2
ChibiOS-6f470322d0241e1923bd1d83d66f291aff571658.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5032 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/fs/fatfs/fatfs_fsimpl.cpp83
-rw-r--r--os/fs/fatfs/fatfs_fsimpl.hpp74
-rw-r--r--os/fs/fs.hpp14
-rw-r--r--os/various/cpp_wrappers/ch.hpp2
4 files changed, 150 insertions, 23 deletions
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<FatFSFileWrapper,
+ FATFS_MAX_FILES>() {
+
+ }
+
/*------------------------------------------------------------------------*
- * chibios_fatfs::FatFSWrapper::FatFSServerThread *
+ * chibios_fatfs::FatFSServerThread *
*------------------------------------------------------------------------*/
- FatFSWrapper::FatFSServerThread::FatFSServerThread(void) :
+ FatFSServerThread::FatFSServerThread(void) :
BaseStaticThread<FATFS_THREAD_STACK_SIZE>() {
}
- 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<FatFSFileWrapper,
+ FATFS_MAX_FILES> {
+ public:
+ FatFSFilesPool(void);
+ };
+
+ /*------------------------------------------------------------------------*
+ * chibios_fatfs::FatFSServerThread *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Class of the internal server thread.
+ */
+ class FatFSServerThread : public BaseStaticThread<FATFS_THREAD_STACK_SIZE> {
+ 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<FATFS_THREAD_STACK_SIZE> {
- 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
@@ -65,13 +65,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.
*
* @return 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_ */
diff --git a/os/various/cpp_wrappers/ch.hpp b/os/various/cpp_wrappers/ch.hpp
index 6e41cea6e..073024ce5 100644
--- a/os/various/cpp_wrappers/ch.hpp
+++ b/os/various/cpp_wrappers/ch.hpp
@@ -2081,7 +2081,7 @@ namespace chibios_rt {
* @brief Template class encapsulating a mailbox and its elements.
*/
template<class T, size_t N>
- class MemoryPoolBuffer : MemoryPool {
+ class MemoryPoolBuffer : public MemoryPool {
private:
T pool_buf[N];