SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 09:08:29 2019 +0000
Revision:
0:aa3fc5ad02f7
SPKT

Who changed what in which revision?

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