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