Fork of mbed for KL05Z based smart sensor which has no crystal on the board, so MCG FEI mode is required.

Dependents:   smart-sensor-KL05Z-debug

Fork of mbed-src by Ermanno Brusadin

Committer:
ebrus
Date:
Wed Jul 27 18:35:32 2016 +0000
Revision:
0:0a673c671a56
4

Who changed what in which revision?

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