mbed library sources

Dependents:   Freedman_v2 Nucleo_i2c_OLED_BME280_copy

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Nov 20 17:24:08 2012 +0000
Revision:
0:fd0d7bdfcdc2
Child:
2:143cac498751
mbed sources

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
mbed_official 0:fd0d7bdfcdc2 2 * Copyright (c) 2006-2012 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
mbed_official 0:fd0d7bdfcdc2 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
mbed_official 0:fd0d7bdfcdc2 5 * of this software and associated documentation files (the "Software"), to deal
mbed_official 0:fd0d7bdfcdc2 6 * in the Software without restriction, including without limitation the rights
mbed_official 0:fd0d7bdfcdc2 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbed_official 0:fd0d7bdfcdc2 8 * copies of the Software, and to permit persons to whom the Software is
mbed_official 0:fd0d7bdfcdc2 9 * furnished to do so, subject to the following conditions:
mbed_official 0:fd0d7bdfcdc2 10 *
mbed_official 0:fd0d7bdfcdc2 11 * The above copyright notice and this permission notice shall be included in
mbed_official 0:fd0d7bdfcdc2 12 * all copies or substantial portions of the Software.
mbed_official 0:fd0d7bdfcdc2 13 *
mbed_official 0:fd0d7bdfcdc2 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbed_official 0:fd0d7bdfcdc2 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbed_official 0:fd0d7bdfcdc2 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbed_official 0:fd0d7bdfcdc2 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbed_official 0:fd0d7bdfcdc2 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbed_official 0:fd0d7bdfcdc2 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
mbed_official 0:fd0d7bdfcdc2 20 * SOFTWARE.
mbed_official 0:fd0d7bdfcdc2 21 */
mbed_official 0:fd0d7bdfcdc2 22 #ifndef MBED_LOCALFILESYSTEM_H
mbed_official 0:fd0d7bdfcdc2 23 #define MBED_LOCALFILESYSTEM_H
mbed_official 0:fd0d7bdfcdc2 24
mbed_official 0:fd0d7bdfcdc2 25 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 26
mbed_official 0:fd0d7bdfcdc2 27 #if DEVICE_LOCALFILESYSTEM
mbed_official 0:fd0d7bdfcdc2 28
mbed_official 0:fd0d7bdfcdc2 29 #include "FileSystemLike.h"
mbed_official 0:fd0d7bdfcdc2 30
mbed_official 0:fd0d7bdfcdc2 31 namespace mbed {
mbed_official 0:fd0d7bdfcdc2 32
mbed_official 0:fd0d7bdfcdc2 33 FILEHANDLE local_file_open(const char* name, int flags);
mbed_official 0:fd0d7bdfcdc2 34
mbed_official 0:fd0d7bdfcdc2 35 class LocalFileHandle : public FileHandle {
mbed_official 0:fd0d7bdfcdc2 36
mbed_official 0:fd0d7bdfcdc2 37 public:
mbed_official 0:fd0d7bdfcdc2 38 LocalFileHandle(FILEHANDLE fh);
mbed_official 0:fd0d7bdfcdc2 39
mbed_official 0:fd0d7bdfcdc2 40 virtual int close();
mbed_official 0:fd0d7bdfcdc2 41
mbed_official 0:fd0d7bdfcdc2 42 virtual ssize_t write(const void *buffer, size_t length);
mbed_official 0:fd0d7bdfcdc2 43
mbed_official 0:fd0d7bdfcdc2 44 virtual ssize_t read(void *buffer, size_t length);
mbed_official 0:fd0d7bdfcdc2 45
mbed_official 0:fd0d7bdfcdc2 46 virtual int isatty();
mbed_official 0:fd0d7bdfcdc2 47
mbed_official 0:fd0d7bdfcdc2 48 virtual off_t lseek(off_t position, int whence);
mbed_official 0:fd0d7bdfcdc2 49
mbed_official 0:fd0d7bdfcdc2 50 virtual int fsync();
mbed_official 0:fd0d7bdfcdc2 51
mbed_official 0:fd0d7bdfcdc2 52 virtual off_t flen();
mbed_official 0:fd0d7bdfcdc2 53
mbed_official 0:fd0d7bdfcdc2 54 protected:
mbed_official 0:fd0d7bdfcdc2 55 FILEHANDLE _fh;
mbed_official 0:fd0d7bdfcdc2 56 int pos;
mbed_official 0:fd0d7bdfcdc2 57 };
mbed_official 0:fd0d7bdfcdc2 58
mbed_official 0:fd0d7bdfcdc2 59 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
mbed_official 0:fd0d7bdfcdc2 60 *
mbed_official 0:fd0d7bdfcdc2 61 * This allows programs to read and write files on the same disk drive that is used to program the
mbed_official 0:fd0d7bdfcdc2 62 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
mbed_official 0:fd0d7bdfcdc2 63 * read and write files.
mbed_official 0:fd0d7bdfcdc2 64 *
mbed_official 0:fd0d7bdfcdc2 65 * Example:
mbed_official 0:fd0d7bdfcdc2 66 * @code
mbed_official 0:fd0d7bdfcdc2 67 * #include "mbed.h"
mbed_official 0:fd0d7bdfcdc2 68 *
mbed_official 0:fd0d7bdfcdc2 69 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
mbed_official 0:fd0d7bdfcdc2 70 *
mbed_official 0:fd0d7bdfcdc2 71 * int main() {
mbed_official 0:fd0d7bdfcdc2 72 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
mbed_official 0:fd0d7bdfcdc2 73 * fprintf(fp, "Hello World!");
mbed_official 0:fd0d7bdfcdc2 74 * fclose(fp);
mbed_official 0:fd0d7bdfcdc2 75 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
mbed_official 0:fd0d7bdfcdc2 76 *
mbed_official 0:fd0d7bdfcdc2 77 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
mbed_official 0:fd0d7bdfcdc2 78 * struct dirent *p;
mbed_official 0:fd0d7bdfcdc2 79 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
mbed_official 0:fd0d7bdfcdc2 80 * printf("%s\n", p->d_name); // to stdout.
mbed_official 0:fd0d7bdfcdc2 81 * }
mbed_official 0:fd0d7bdfcdc2 82 * closedir(d);
mbed_official 0:fd0d7bdfcdc2 83 * }
mbed_official 0:fd0d7bdfcdc2 84 * @endcode
mbed_official 0:fd0d7bdfcdc2 85 *
mbed_official 0:fd0d7bdfcdc2 86 * @note
mbed_official 0:fd0d7bdfcdc2 87 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
mbed_official 0:fd0d7bdfcdc2 88 * on the Host computer. This means it is no longer accessible from the Host Computer.
mbed_official 0:fd0d7bdfcdc2 89 *
mbed_official 0:fd0d7bdfcdc2 90 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
mbed_official 0:fd0d7bdfcdc2 91 * 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 92 */
mbed_official 0:fd0d7bdfcdc2 93 class LocalFileSystem : public FileSystemLike {
mbed_official 0:fd0d7bdfcdc2 94
mbed_official 0:fd0d7bdfcdc2 95 public:
mbed_official 0:fd0d7bdfcdc2 96 LocalFileSystem(const char* n) : FileSystemLike(n) {
mbed_official 0:fd0d7bdfcdc2 97
mbed_official 0:fd0d7bdfcdc2 98 }
mbed_official 0:fd0d7bdfcdc2 99
mbed_official 0:fd0d7bdfcdc2 100 virtual FileHandle *open(const char* name, int flags);
mbed_official 0:fd0d7bdfcdc2 101 virtual int remove(const char *filename);
mbed_official 0:fd0d7bdfcdc2 102 virtual DirHandle *opendir(const char *name);
mbed_official 0:fd0d7bdfcdc2 103 };
mbed_official 0:fd0d7bdfcdc2 104
mbed_official 0:fd0d7bdfcdc2 105 } // namespace mbed
mbed_official 0:fd0d7bdfcdc2 106
mbed_official 0:fd0d7bdfcdc2 107 #endif
mbed_official 0:fd0d7bdfcdc2 108
mbed_official 0:fd0d7bdfcdc2 109 #endif