.

Dependents:   RTC

Committer:
jhon309
Date:
Thu Aug 13 00:20:09 2015 +0000
Revision:
0:88e313c910d0
RTC Example

Who changed what in which revision?

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