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