help :(

Dependencies:   FFT

Committer:
dimitryjl23
Date:
Fri Dec 04 18:01:22 2020 +0000
Revision:
11:951bbb0385aa
Parent:
0:d6c9b09b4042
Final :)

Who changed what in which revision?

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