mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Mon Feb 18 09:41:56 2013 +0000
Revision:
9:663789d7729f
Parent:
8:c14af7958ef5
Update mbed-KL25Z to latest build

Who changed what in which revision?

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