mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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