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:
Sun May 04 00:23:05 2014 +0000
Revision:
1:00c9eb8af5c2
Parent:
0:39eb4d5b97df
Child:
2:97c314eae8b8
add virtual com interface.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:39eb4d5b97df 1 #pragma once
va009039 0:39eb4d5b97df 2 #include "Storage.h"
va009039 0:39eb4d5b97df 3
va009039 1:00c9eb8af5c2 4 /** Access the LocalFileSystem using RamDisk(64KB)
va009039 1:00c9eb8af5c2 5 *
va009039 1:00c9eb8af5c2 6 * @code
va009039 1:00c9eb8af5c2 7 * #include "USBLocalFileSystem.h"
va009039 1:00c9eb8af5c2 8 *
va009039 1:00c9eb8af5c2 9 * int main() {
va009039 1:00c9eb8af5c2 10 * USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB)
va009039 1:00c9eb8af5c2 11 *
va009039 1:00c9eb8af5c2 12 * FILE *fp = fopen("/local/mbed.txt", "a");
va009039 1:00c9eb8af5c2 13 * fprintf(fp, "Hello World!\n");
va009039 1:00c9eb8af5c2 14 * fclose(fp);
va009039 1:00c9eb8af5c2 15 * }
va009039 1:00c9eb8af5c2 16 * @endcode
va009039 1:00c9eb8af5c2 17 */
va009039 0:39eb4d5b97df 18 class USBLocalFileSystem {
va009039 0:39eb4d5b97df 19 public:
va009039 1:00c9eb8af5c2 20
va009039 1:00c9eb8af5c2 21 /** Create the Local File System using RamDisk(64KB)
va009039 1:00c9eb8af5c2 22 *
va009039 1:00c9eb8af5c2 23 * @param name The name used to access the virtual filesystem
va009039 1:00c9eb8af5c2 24 */
va009039 0:39eb4d5b97df 25 USBLocalFileSystem(const char* name = "local");
va009039 1:00c9eb8af5c2 26
va009039 1:00c9eb8af5c2 27 /** Create the Local File System for accessing an SD Card using SPI
va009039 1:00c9eb8af5c2 28 *
va009039 1:00c9eb8af5c2 29 * @param mosi SPI mosi pin connected to SD Card
va009039 1:00c9eb8af5c2 30 * @param miso SPI miso pin conencted to SD Card
va009039 1:00c9eb8af5c2 31 * @param sclk SPI sclk pin connected to SD Card
va009039 1:00c9eb8af5c2 32 * @param cs DigitalOut pin used as SD Card chip select
va009039 1:00c9eb8af5c2 33 * @param name The name used to access the virtual filesystem
va009039 1:00c9eb8af5c2 34 */
va009039 0:39eb4d5b97df 35 USBLocalFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name = "local");
va009039 1:00c9eb8af5c2 36
va009039 1:00c9eb8af5c2 37 /** Create the Local File System using StorageInterface
va009039 1:00c9eb8af5c2 38 *
va009039 1:00c9eb8af5c2 39 * @param storage StorageInterface
va009039 1:00c9eb8af5c2 40 * @param name The name used to access the virtual filesystem
va009039 1:00c9eb8af5c2 41 */
va009039 0:39eb4d5b97df 42 USBLocalFileSystem(StorageInterface* storage, const char* name = "local");
va009039 0:39eb4d5b97df 43 void attachEvent(void (*ptr)());
va009039 0:39eb4d5b97df 44 void remount();
va009039 1:00c9eb8af5c2 45
va009039 1:00c9eb8af5c2 46 /** Determine if there is a character available to read
va009039 1:00c9eb8af5c2 47 *
va009039 1:00c9eb8af5c2 48 * @returns
va009039 1:00c9eb8af5c2 49 * 1 if there is a character available to read,
va009039 1:00c9eb8af5c2 50 * 0 otherwise
va009039 1:00c9eb8af5c2 51 */
va009039 1:00c9eb8af5c2 52 int readable();
va009039 1:00c9eb8af5c2 53
va009039 1:00c9eb8af5c2 54 /** Determine if there is space available to write a character
va009039 1:00c9eb8af5c2 55 *
va009039 1:00c9eb8af5c2 56 * @returns
va009039 1:00c9eb8af5c2 57 * 1 if there is space to write a character,
va009039 1:00c9eb8af5c2 58 * 0 otherwise
va009039 1:00c9eb8af5c2 59 */
va009039 1:00c9eb8af5c2 60 int writeable();
va009039 1:00c9eb8af5c2 61
va009039 0:39eb4d5b97df 62 int getc();
va009039 1:00c9eb8af5c2 63 void putc(int c);
va009039 1:00c9eb8af5c2 64
va009039 0:39eb4d5b97df 65 private:
va009039 0:39eb4d5b97df 66 void init(StorageInterface* storage, const char* name);
va009039 0:39eb4d5b97df 67 const char* _name;
va009039 0:39eb4d5b97df 68 StorageInterface* _storage;
va009039 0:39eb4d5b97df 69 LocalStorage* _local;
va009039 0:39eb4d5b97df 70 USBStorage2* _usb;
va009039 0:39eb4d5b97df 71 };