mbed libraries for KL25Z

Dependents:   FRDM_RGBLED

Committer:
emilmont
Date:
Fri Nov 09 11:33:53 2012 +0000
Revision:
8:c14af7958ef5
Parent:
0:8024c367e29f
Child:
9:663789d7729f
SPI driver; ADC driver; DAC driver; microlib support; general bugfixing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 0:8024c367e29f 1 /* mbed Microcontroller Library - LocalFileSystem
emilmont 0:8024c367e29f 2 * Copyright (c) 2008-2009 ARM Limited. All rights reserved.
emilmont 8:c14af7958ef5 3 */
emilmont 0:8024c367e29f 4 #ifndef MBED_LOCALFILESYSTEM_H
emilmont 0:8024c367e29f 5 #define MBED_LOCALFILESYSTEM_H
emilmont 0:8024c367e29f 6
emilmont 8:c14af7958ef5 7 #include "platform.h"
emilmont 0:8024c367e29f 8
emilmont 0:8024c367e29f 9 #if DEVICE_LOCALFILESYSTEM
emilmont 0:8024c367e29f 10
emilmont 0:8024c367e29f 11 #include "FileSystemLike.h"
emilmont 0:8024c367e29f 12
emilmont 0:8024c367e29f 13 namespace mbed {
emilmont 0:8024c367e29f 14
emilmont 0:8024c367e29f 15 FILEHANDLE local_file_open(const char* name, int flags);
emilmont 0:8024c367e29f 16
emilmont 0:8024c367e29f 17 class LocalFileHandle : public FileHandle {
emilmont 0:8024c367e29f 18
emilmont 0:8024c367e29f 19 public:
emilmont 0:8024c367e29f 20 LocalFileHandle(FILEHANDLE fh);
emilmont 0:8024c367e29f 21
emilmont 0:8024c367e29f 22 virtual int close();
emilmont 0:8024c367e29f 23
emilmont 0:8024c367e29f 24 virtual ssize_t write(const void *buffer, size_t length);
emilmont 0:8024c367e29f 25
emilmont 0:8024c367e29f 26 virtual ssize_t read(void *buffer, size_t length);
emilmont 0:8024c367e29f 27
emilmont 0:8024c367e29f 28 virtual int isatty();
emilmont 0:8024c367e29f 29
emilmont 0:8024c367e29f 30 virtual off_t lseek(off_t position, int whence);
emilmont 0:8024c367e29f 31
emilmont 0:8024c367e29f 32 virtual int fsync();
emilmont 0:8024c367e29f 33
emilmont 0:8024c367e29f 34 virtual off_t flen();
emilmont 0:8024c367e29f 35
emilmont 0:8024c367e29f 36 protected:
emilmont 0:8024c367e29f 37 FILEHANDLE _fh;
emilmont 0:8024c367e29f 38 int pos;
emilmont 0:8024c367e29f 39 };
emilmont 0:8024c367e29f 40
emilmont 8:c14af7958ef5 41 /** A filesystem for accessing the local mbed Microcontroller USB disk drive
emilmont 0:8024c367e29f 42 *
emilmont 0:8024c367e29f 43 * This allows programs to read and write files on the same disk drive that is used to program the
emilmont 0:8024c367e29f 44 * mbed Microcontroller. Once created, the standard C file access functions are used to open,
emilmont 0:8024c367e29f 45 * read and write files.
emilmont 0:8024c367e29f 46 *
emilmont 0:8024c367e29f 47 * Example:
emilmont 8:c14af7958ef5 48 * @code
emilmont 8:c14af7958ef5 49 * #include "mbed.h"
emilmont 8:c14af7958ef5 50 *
emilmont 8:c14af7958ef5 51 * LocalFileSystem local("local"); // Create the local filesystem under the name "local"
emilmont 8:c14af7958ef5 52 *
emilmont 8:c14af7958ef5 53 * int main() {
emilmont 8:c14af7958ef5 54 * FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
emilmont 8:c14af7958ef5 55 * fprintf(fp, "Hello World!");
emilmont 8:c14af7958ef5 56 * fclose(fp);
emilmont 8:c14af7958ef5 57 * remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
emilmont 0:8024c367e29f 58 *
emilmont 8:c14af7958ef5 59 * DIR *d = opendir("/local"); // Opens the root directory of the local file system
emilmont 8:c14af7958ef5 60 * struct dirent *p;
emilmont 8:c14af7958ef5 61 * while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
emilmont 8:c14af7958ef5 62 * printf("%s\n", p->d_name); // to stdout.
emilmont 8:c14af7958ef5 63 * }
emilmont 8:c14af7958ef5 64 * closedir(d);
emilmont 8:c14af7958ef5 65 * }
emilmont 8:c14af7958ef5 66 * @endcode
emilmont 8:c14af7958ef5 67 *
emilmont 8:c14af7958ef5 68 * @note
emilmont 0:8024c367e29f 69 * If the microcontroller program makes an access to the local drive, it will be marked as "removed"
emilmont 0:8024c367e29f 70 * on the Host computer. This means it is no longer accessible from the Host Computer.
emilmont 0:8024c367e29f 71 *
emilmont 0:8024c367e29f 72 * The drive will only re-appear when the microcontroller program exists. Note that if the program does
emilmont 0:8024c367e29f 73 * not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
emilmont 0:8024c367e29f 74 */
emilmont 0:8024c367e29f 75 class LocalFileSystem : public FileSystemLike {
emilmont 0:8024c367e29f 76
emilmont 0:8024c367e29f 77 public:
emilmont 0:8024c367e29f 78 LocalFileSystem(const char* n) : FileSystemLike(n) {
emilmont 8:c14af7958ef5 79
emilmont 8:c14af7958ef5 80 }
emilmont 0:8024c367e29f 81
emilmont 0:8024c367e29f 82 virtual FileHandle *open(const char* name, int flags);
emilmont 0:8024c367e29f 83 virtual int remove(const char *filename);
emilmont 0:8024c367e29f 84 virtual DirHandle *opendir(const char *name);
emilmont 0:8024c367e29f 85 };
emilmont 0:8024c367e29f 86
emilmont 0:8024c367e29f 87 } // namespace mbed
emilmont 0:8024c367e29f 88
emilmont 0:8024c367e29f 89 #endif
emilmont 0:8024c367e29f 90
emilmont 0:8024c367e29f 91 #endif