mbed library sources. Supersedes mbed-src.

Fork of mbed by teralytic

Committer:
rodriguise
Date:
Mon Oct 17 18:47:01 2016 +0000
Revision:
148:4802eb17e82b
Parent:
144:ef7eb2e8f9f7
backup

Who changed what in which revision?

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