Emulation of LocalFileSystem with virtual COM.

Dependencies:   USBDevice

Dependents:   KL46Z-lpc81isp lpcterm2

#include "USBLocalFileSystem.h"

int main() {
    USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)

    while(1) {
        usb_local->lock(true);
        usb_local->remount();
        char filename[32];
        if (usb_local->find(filename, sizeof(filename), "*.TXT")) {
            FILE* fp = fopen(filename, "r");
            if (fp) {
                int c;
                while((c = fgetc(fp)) != EOF) {
                    usb_local->putc(c);
                }
                fclose(fp);
            }
        }    
        usb_local->lock(false);

        wait_ms(1000*5);
    }
}



Sample application:

Import programKL46Z-lpc81isp

ISP example program.

Import programlpcterm2

semihost server example program

Committer:
va009039
Date:
Sat Jun 21 22:39:59 2014 +0000
Revision:
6:528036abfb02
Parent:
0:39eb4d5b97df
add LPC11U68

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:39eb4d5b97df 1 /* mbed Microcontroller Library
va009039 0:39eb4d5b97df 2 * Copyright (c) 2006-2012 ARM Limited
va009039 0:39eb4d5b97df 3 *
va009039 0:39eb4d5b97df 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
va009039 0:39eb4d5b97df 5 * of this software and associated documentation files (the "Software"), to deal
va009039 0:39eb4d5b97df 6 * in the Software without restriction, including without limitation the rights
va009039 0:39eb4d5b97df 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
va009039 0:39eb4d5b97df 8 * copies of the Software, and to permit persons to whom the Software is
va009039 0:39eb4d5b97df 9 * furnished to do so, subject to the following conditions:
va009039 0:39eb4d5b97df 10 *
va009039 0:39eb4d5b97df 11 * The above copyright notice and this permission notice shall be included in
va009039 0:39eb4d5b97df 12 * all copies or substantial portions of the Software.
va009039 0:39eb4d5b97df 13 *
va009039 0:39eb4d5b97df 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
va009039 0:39eb4d5b97df 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
va009039 0:39eb4d5b97df 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
va009039 0:39eb4d5b97df 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
va009039 0:39eb4d5b97df 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
va009039 0:39eb4d5b97df 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
va009039 0:39eb4d5b97df 20 * SOFTWARE.
va009039 0:39eb4d5b97df 21 */
va009039 0:39eb4d5b97df 22 #ifndef MBED_FATFILESYSTEM_H
va009039 0:39eb4d5b97df 23 #define MBED_FATFILESYSTEM_H
va009039 0:39eb4d5b97df 24
va009039 0:39eb4d5b97df 25 #include "FileSystemLike.h"
va009039 0:39eb4d5b97df 26 #include "FileHandle.h"
va009039 0:39eb4d5b97df 27 #include "ff.h"
va009039 0:39eb4d5b97df 28 #include <stdint.h>
va009039 0:39eb4d5b97df 29
va009039 0:39eb4d5b97df 30 using namespace mbed;
va009039 0:39eb4d5b97df 31
va009039 0:39eb4d5b97df 32 class FATFileSystem : public FileSystemLike {
va009039 0:39eb4d5b97df 33 public:
va009039 0:39eb4d5b97df 34
va009039 0:39eb4d5b97df 35 FATFileSystem(const char* n);
va009039 0:39eb4d5b97df 36 virtual ~FATFileSystem();
va009039 0:39eb4d5b97df 37
va009039 0:39eb4d5b97df 38 static FATFileSystem * _ffs[_VOLUMES]; // FATFileSystem objects, as parallel to FatFs drives array
va009039 0:39eb4d5b97df 39 FATFS _fs; // Work area (file system object) for logical drive
va009039 0:39eb4d5b97df 40 int _fsid;
va009039 0:39eb4d5b97df 41
va009039 0:39eb4d5b97df 42 virtual FileHandle *open(const char* name, int flags);
va009039 0:39eb4d5b97df 43 virtual int remove(const char *filename);
va009039 0:39eb4d5b97df 44 virtual int format();
va009039 0:39eb4d5b97df 45 virtual DirHandle *opendir(const char *name);
va009039 0:39eb4d5b97df 46 virtual int mkdir(const char *name, mode_t mode);
va009039 0:39eb4d5b97df 47
va009039 0:39eb4d5b97df 48 virtual int disk_initialize() { return 0; }
va009039 0:39eb4d5b97df 49 virtual int disk_status() { return 0; }
va009039 0:39eb4d5b97df 50 virtual int disk_read(uint8_t * buffer, uint64_t sector) = 0;
va009039 0:39eb4d5b97df 51 virtual int disk_write(const uint8_t * buffer, uint64_t sector) = 0;
va009039 0:39eb4d5b97df 52 virtual int disk_sync() { return 0; }
va009039 0:39eb4d5b97df 53 virtual uint64_t disk_sectors() = 0;
va009039 0:39eb4d5b97df 54
va009039 0:39eb4d5b97df 55 };
va009039 0:39eb4d5b97df 56
va009039 0:39eb4d5b97df 57 #endif