,,

Fork of Application by Daniel Sygut

Committer:
Zaitsev
Date:
Tue Jan 10 20:42:26 2017 +0000
Revision:
10:41552d038a69
USB Serial bi-directional bridge

Who changed what in which revision?

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