temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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