mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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