mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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