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