Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

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