The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
158:1c57384330a6
Child:
170:e95d10626187
mbed library. Release version 162

Who changed what in which revision?

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