Rahul Dahiya / Mbed OS STM32F7 Ethernet
Committer:
rahul_dahiya
Date:
Wed Jan 15 15:57:15 2020 +0530
Revision:
0:fb8047b156bb
STM32F7 LWIP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rahul_dahiya 0:fb8047b156bb 1 /* mbed Microcontroller Library
rahul_dahiya 0:fb8047b156bb 2 * Copyright (c) 2006-2013 ARM Limited
rahul_dahiya 0:fb8047b156bb 3 *
rahul_dahiya 0:fb8047b156bb 4 * Licensed under the Apache License, Version 2.0 (the "License");
rahul_dahiya 0:fb8047b156bb 5 * you may not use this file except in compliance with the License.
rahul_dahiya 0:fb8047b156bb 6 * You may obtain a copy of the License at
rahul_dahiya 0:fb8047b156bb 7 *
rahul_dahiya 0:fb8047b156bb 8 * http://www.apache.org/licenses/LICENSE-2.0
rahul_dahiya 0:fb8047b156bb 9 *
rahul_dahiya 0:fb8047b156bb 10 * Unless required by applicable law or agreed to in writing, software
rahul_dahiya 0:fb8047b156bb 11 * distributed under the License is distributed on an "AS IS" BASIS,
rahul_dahiya 0:fb8047b156bb 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rahul_dahiya 0:fb8047b156bb 13 * See the License for the specific language governing permissions and
rahul_dahiya 0:fb8047b156bb 14 * limitations under the License.
rahul_dahiya 0:fb8047b156bb 15 */
rahul_dahiya 0:fb8047b156bb 16 #ifndef MBED_LOCALFILESYSTEM_H
rahul_dahiya 0:fb8047b156bb 17 #define MBED_LOCALFILESYSTEM_H
rahul_dahiya 0:fb8047b156bb 18
rahul_dahiya 0:fb8047b156bb 19 #include "platform/platform.h"
rahul_dahiya 0:fb8047b156bb 20
rahul_dahiya 0:fb8047b156bb 21 #if DEVICE_LOCALFILESYSTEM
rahul_dahiya 0:fb8047b156bb 22
rahul_dahiya 0:fb8047b156bb 23 #include "platform/FileSystemLike.h"
rahul_dahiya 0:fb8047b156bb 24 #include "platform/PlatformMutex.h"
rahul_dahiya 0:fb8047b156bb 25 #include "platform/NonCopyable.h"
rahul_dahiya 0:fb8047b156bb 26
rahul_dahiya 0:fb8047b156bb 27 namespace mbed {
rahul_dahiya 0:fb8047b156bb 28 /** \addtogroup platform */
rahul_dahiya 0:fb8047b156bb 29 /** @{*/
rahul_dahiya 0:fb8047b156bb 30 /**
rahul_dahiya 0:fb8047b156bb 31 * \defgroup platform_LocalFileSystem LocalFileSystem functions
rahul_dahiya 0:fb8047b156bb 32 * @{
rahul_dahiya 0:fb8047b156bb 33 */
rahul_dahiya 0:fb8047b156bb 34
rahul_dahiya 0:fb8047b156bb 35 FILEHANDLE local_file_open(const char* name, int flags);
rahul_dahiya 0:fb8047b156bb 36
rahul_dahiya 0:fb8047b156bb 37 /**
rahul_dahiya 0:fb8047b156bb 38 * @class LocalFileHandle
rahul_dahiya 0:fb8047b156bb 39 * @ingroup platform
rahul_dahiya 0:fb8047b156bb 40 */
rahul_dahiya 0:fb8047b156bb 41 class LocalFileHandle : public FileHandle, private NonCopyable<LocalFileHandle> {
rahul_dahiya 0:fb8047b156bb 42
rahul_dahiya 0:fb8047b156bb 43 public:
rahul_dahiya 0:fb8047b156bb 44 LocalFileHandle(FILEHANDLE fh);
rahul_dahiya 0:fb8047b156bb 45
rahul_dahiya 0:fb8047b156bb 46 virtual int close();
rahul_dahiya 0:fb8047b156bb 47
rahul_dahiya 0:fb8047b156bb 48 virtual ssize_t write(const void *buffer, size_t length);
rahul_dahiya 0:fb8047b156bb 49
rahul_dahiya 0:fb8047b156bb 50 virtual ssize_t read(void *buffer, size_t length);
rahul_dahiya 0:fb8047b156bb 51
rahul_dahiya 0:fb8047b156bb 52 virtual int isatty();
rahul_dahiya 0:fb8047b156bb 53
rahul_dahiya 0:fb8047b156bb 54 virtual off_t seek(off_t position, int whence);
rahul_dahiya 0:fb8047b156bb 55
rahul_dahiya 0:fb8047b156bb 56 virtual int sync();
rahul_dahiya 0:fb8047b156bb 57
rahul_dahiya 0:fb8047b156bb 58 virtual off_t size();
rahul_dahiya 0:fb8047b156bb 59
rahul_dahiya 0:fb8047b156bb 60 protected:
rahul_dahiya 0:fb8047b156bb 61 virtual void lock();
rahul_dahiya 0:fb8047b156bb 62 virtual void unlock();
rahul_dahiya 0:fb8047b156bb 63 FILEHANDLE _fh;
rahul_dahiya 0:fb8047b156bb 64 int pos;
rahul_dahiya 0:fb8047b156bb 65 PlatformMutex _mutex;
rahul_dahiya 0:fb8047b156bb 66 };
rahul_dahiya 0:fb8047b156bb 67
rahul_dahiya 0:fb8047b156bb 68 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
rahul_dahiya 0:fb8047b156bb 69 *
rahul_dahiya 0:fb8047b156bb 70 * This allows programs to read and write files on the same disk drive that is used to program the
rahul_dahiya 0:fb8047b156bb 71 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
rahul_dahiya 0:fb8047b156bb 72 * read and write files.
rahul_dahiya 0:fb8047b156bb 73 *
rahul_dahiya 0:fb8047b156bb 74 * @note Synchronization level: Thread safe
rahul_dahiya 0:fb8047b156bb 75 *
rahul_dahiya 0:fb8047b156bb 76 * Example:
rahul_dahiya 0:fb8047b156bb 77 * @code
rahul_dahiya 0:fb8047b156bb 78 * #include "mbed.h"
rahul_dahiya 0:fb8047b156bb 79 *
rahul_dahiya 0:fb8047b156bb 80 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
rahul_dahiya 0:fb8047b156bb 81 *
rahul_dahiya 0:fb8047b156bb 82 * int main() {
rahul_dahiya 0:fb8047b156bb 83 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
rahul_dahiya 0:fb8047b156bb 84 * fprintf(fp, "Hello World!");
rahul_dahiya 0:fb8047b156bb 85 * fclose(fp);
rahul_dahiya 0:fb8047b156bb 86 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
rahul_dahiya 0:fb8047b156bb 87 *
rahul_dahiya 0:fb8047b156bb 88 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
rahul_dahiya 0:fb8047b156bb 89 * struct dirent *p;
rahul_dahiya 0:fb8047b156bb 90 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
rahul_dahiya 0:fb8047b156bb 91 * printf("%s\n", p->d_name); // to stdout.
rahul_dahiya 0:fb8047b156bb 92 * }
rahul_dahiya 0:fb8047b156bb 93 * closedir(d);
rahul_dahiya 0:fb8047b156bb 94 * }
rahul_dahiya 0:fb8047b156bb 95 * @endcode
rahul_dahiya 0:fb8047b156bb 96 *
rahul_dahiya 0:fb8047b156bb 97 * @note
rahul_dahiya 0:fb8047b156bb 98 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
rahul_dahiya 0:fb8047b156bb 99 * on the Host computer. This means it is no longer accessible from the Host Computer.
rahul_dahiya 0:fb8047b156bb 100 *
rahul_dahiya 0:fb8047b156bb 101 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
rahul_dahiya 0:fb8047b156bb 102 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
rahul_dahiya 0:fb8047b156bb 103 * @ingroup platform
rahul_dahiya 0:fb8047b156bb 104 */
rahul_dahiya 0:fb8047b156bb 105 class LocalFileSystem : public FileSystemLike, private NonCopyable<LocalFileSystem> {
rahul_dahiya 0:fb8047b156bb 106 // No modifiable state
rahul_dahiya 0:fb8047b156bb 107
rahul_dahiya 0:fb8047b156bb 108 public:
rahul_dahiya 0:fb8047b156bb 109 LocalFileSystem(const char* n) : FileSystemLike(n) {
rahul_dahiya 0:fb8047b156bb 110
rahul_dahiya 0:fb8047b156bb 111 }
rahul_dahiya 0:fb8047b156bb 112
rahul_dahiya 0:fb8047b156bb 113 virtual int open(FileHandle **file, const char *path, int flags);
rahul_dahiya 0:fb8047b156bb 114 virtual int open(DirHandle **dir, const char *name);
rahul_dahiya 0:fb8047b156bb 115 virtual int remove(const char *filename);
rahul_dahiya 0:fb8047b156bb 116 };
rahul_dahiya 0:fb8047b156bb 117
rahul_dahiya 0:fb8047b156bb 118 /**@}*/
rahul_dahiya 0:fb8047b156bb 119
rahul_dahiya 0:fb8047b156bb 120 /**@}*/
rahul_dahiya 0:fb8047b156bb 121
rahul_dahiya 0:fb8047b156bb 122 } // namespace mbed
rahul_dahiya 0:fb8047b156bb 123
rahul_dahiya 0:fb8047b156bb 124 #endif
rahul_dahiya 0:fb8047b156bb 125
rahul_dahiya 0:fb8047b156bb 126 #endif
rahul_dahiya 0:fb8047b156bb 127