SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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