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:
AnnaBridge
Date:
Wed Jun 21 17:31:38 2017 +0100
Revision:
145:64910690c574
Child:
146:22da6e220af6
Release 145 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 145:64910690c574 25
AnnaBridge 145:64910690c574 26 namespace mbed {
AnnaBridge 145:64910690c574 27 /** \addtogroup platform */
AnnaBridge 145:64910690c574 28 /** @{*/
AnnaBridge 145:64910690c574 29
AnnaBridge 145:64910690c574 30 FILEHANDLE local_file_open(const char* name, int flags);
AnnaBridge 145:64910690c574 31 /** @}*/
AnnaBridge 145:64910690c574 32
AnnaBridge 145:64910690c574 33 /**
AnnaBridge 145:64910690c574 34 * @class LocalFileHandle
AnnaBridge 145:64910690c574 35 * @ingroup platform
AnnaBridge 145:64910690c574 36 */
AnnaBridge 145:64910690c574 37 class LocalFileHandle : public FileHandle {
AnnaBridge 145:64910690c574 38
AnnaBridge 145:64910690c574 39 public:
AnnaBridge 145:64910690c574 40 LocalFileHandle(FILEHANDLE fh);
AnnaBridge 145:64910690c574 41
AnnaBridge 145:64910690c574 42 virtual int close();
AnnaBridge 145:64910690c574 43
AnnaBridge 145:64910690c574 44 virtual ssize_t write(const void *buffer, size_t length);
AnnaBridge 145:64910690c574 45
AnnaBridge 145:64910690c574 46 virtual ssize_t read(void *buffer, size_t length);
AnnaBridge 145:64910690c574 47
AnnaBridge 145:64910690c574 48 virtual int isatty();
AnnaBridge 145:64910690c574 49
AnnaBridge 145:64910690c574 50 virtual off_t seek(off_t position, int whence);
AnnaBridge 145:64910690c574 51
AnnaBridge 145:64910690c574 52 virtual int sync();
AnnaBridge 145:64910690c574 53
AnnaBridge 145:64910690c574 54 virtual off_t size();
AnnaBridge 145:64910690c574 55
AnnaBridge 145:64910690c574 56 protected:
AnnaBridge 145:64910690c574 57 virtual void lock();
AnnaBridge 145:64910690c574 58 virtual void unlock();
AnnaBridge 145:64910690c574 59 FILEHANDLE _fh;
AnnaBridge 145:64910690c574 60 int pos;
AnnaBridge 145:64910690c574 61 PlatformMutex _mutex;
AnnaBridge 145:64910690c574 62 };
AnnaBridge 145:64910690c574 63
AnnaBridge 145:64910690c574 64 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
AnnaBridge 145:64910690c574 65 *
AnnaBridge 145:64910690c574 66 * This allows programs to read and write files on the same disk drive that is used to program the
AnnaBridge 145:64910690c574 67 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
AnnaBridge 145:64910690c574 68 * read and write files.
AnnaBridge 145:64910690c574 69 *
AnnaBridge 145:64910690c574 70 * @note Synchronization level: Thread safe
AnnaBridge 145:64910690c574 71 *
AnnaBridge 145:64910690c574 72 * Example:
AnnaBridge 145:64910690c574 73 * @code
AnnaBridge 145:64910690c574 74 * #include "mbed.h"
AnnaBridge 145:64910690c574 75 *
AnnaBridge 145:64910690c574 76 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
AnnaBridge 145:64910690c574 77 *
AnnaBridge 145:64910690c574 78 * int main() {
AnnaBridge 145:64910690c574 79 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
AnnaBridge 145:64910690c574 80 * fprintf(fp, "Hello World!");
AnnaBridge 145:64910690c574 81 * fclose(fp);
AnnaBridge 145:64910690c574 82 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
AnnaBridge 145:64910690c574 83 *
AnnaBridge 145:64910690c574 84 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
AnnaBridge 145:64910690c574 85 * struct dirent *p;
AnnaBridge 145:64910690c574 86 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
AnnaBridge 145:64910690c574 87 * printf("%s\n", p->d_name); // to stdout.
AnnaBridge 145:64910690c574 88 * }
AnnaBridge 145:64910690c574 89 * closedir(d);
AnnaBridge 145:64910690c574 90 * }
AnnaBridge 145:64910690c574 91 * @endcode
AnnaBridge 145:64910690c574 92 *
AnnaBridge 145:64910690c574 93 * @note
AnnaBridge 145:64910690c574 94 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
AnnaBridge 145:64910690c574 95 * on the Host computer. This means it is no longer accessible from the Host Computer.
AnnaBridge 145:64910690c574 96 *
AnnaBridge 145:64910690c574 97 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
AnnaBridge 145:64910690c574 98 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
AnnaBridge 145:64910690c574 99 * @ingroup platform
AnnaBridge 145:64910690c574 100 */
AnnaBridge 145:64910690c574 101 class LocalFileSystem : public FileSystemLike {
AnnaBridge 145:64910690c574 102 // No modifiable state
AnnaBridge 145:64910690c574 103
AnnaBridge 145:64910690c574 104 public:
AnnaBridge 145:64910690c574 105 LocalFileSystem(const char* n) : FileSystemLike(n) {
AnnaBridge 145:64910690c574 106
AnnaBridge 145:64910690c574 107 }
AnnaBridge 145:64910690c574 108
AnnaBridge 145:64910690c574 109 virtual int open(FileHandle **file, const char *path, int flags);
AnnaBridge 145:64910690c574 110 virtual int open(DirHandle **dir, const char *name);
AnnaBridge 145:64910690c574 111 virtual int remove(const char *filename);
AnnaBridge 145:64910690c574 112 };
AnnaBridge 145:64910690c574 113
AnnaBridge 145:64910690c574 114 } // namespace mbed
AnnaBridge 145:64910690c574 115
AnnaBridge 145:64910690c574 116 #endif
AnnaBridge 145:64910690c574 117
AnnaBridge 145:64910690c574 118 #endif
AnnaBridge 145:64910690c574 119