mbed.h verzija za koristenje na predmetu PAI

Committer:
esokic
Date:
Tue Mar 10 09:51:52 2015 +0000
Revision:
0:05aad811ea07
mbed.h verzija od marta 2014, za koristenje na predmetu PAI

Who changed what in which revision?

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