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