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:
Kojto
Date:
Wed Jul 19 16:46:19 2017 +0100
Revision:
147:a97add6d7e64
Parent:
146:22da6e220af6
Release 147 of the mbed library.

Who changed what in which revision?

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