mbed library sources

Fork of mbed-src by mbed official

Committer:
emilmont
Date:
Mon Feb 18 11:44:18 2013 +0000
Revision:
2:143cac498751
Parent:
0:fd0d7bdfcdc2
Update mbed sources to Rev 59

Who changed what in which revision?

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