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 #include <string.h>
va009039 0:39eb4d5b97df 23 #include "ff.h"
va009039 0:39eb4d5b97df 24 #include "FATDirHandle.h"
va009039 0:39eb4d5b97df 25
va009039 0:39eb4d5b97df 26 using namespace mbed;
va009039 0:39eb4d5b97df 27
va009039 0:39eb4d5b97df 28 FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) {
va009039 0:39eb4d5b97df 29 dir = the_dir;
va009039 0:39eb4d5b97df 30 }
va009039 0:39eb4d5b97df 31
va009039 0:39eb4d5b97df 32 int FATDirHandle::closedir() {
va009039 0:39eb4d5b97df 33 delete this;
va009039 0:39eb4d5b97df 34 return 0;
va009039 0:39eb4d5b97df 35 }
va009039 0:39eb4d5b97df 36 FILINFO FATDirHandle_finfo;
va009039 0:39eb4d5b97df 37
va009039 0:39eb4d5b97df 38 struct dirent *FATDirHandle::readdir() {
va009039 0:39eb4d5b97df 39 FILINFO finfo;
va009039 0:39eb4d5b97df 40
va009039 0:39eb4d5b97df 41 #if _USE_LFN
va009039 0:39eb4d5b97df 42 finfo.lfname = cur_entry.d_name;
va009039 0:39eb4d5b97df 43 finfo.lfsize = sizeof(cur_entry.d_name);
va009039 0:39eb4d5b97df 44 #endif // _USE_LFN
va009039 0:39eb4d5b97df 45
va009039 0:39eb4d5b97df 46 FRESULT res = f_readdir(&dir, &finfo);
va009039 0:39eb4d5b97df 47 FATDirHandle_finfo = finfo;
va009039 0:39eb4d5b97df 48
va009039 0:39eb4d5b97df 49 #if _USE_LFN
va009039 0:39eb4d5b97df 50 if(res != 0 || finfo.fname[0]==0) {
va009039 0:39eb4d5b97df 51 return NULL;
va009039 0:39eb4d5b97df 52 } else {
va009039 0:39eb4d5b97df 53 if(cur_entry.d_name[0]==0) {
va009039 0:39eb4d5b97df 54 // No long filename so use short filename.
va009039 0:39eb4d5b97df 55 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
va009039 0:39eb4d5b97df 56 }
va009039 0:39eb4d5b97df 57 return &cur_entry;
va009039 0:39eb4d5b97df 58 }
va009039 0:39eb4d5b97df 59 #else
va009039 0:39eb4d5b97df 60 if(res != 0 || finfo.fname[0]==0) {
va009039 0:39eb4d5b97df 61 return NULL;
va009039 0:39eb4d5b97df 62 } else {
va009039 0:39eb4d5b97df 63 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
va009039 0:39eb4d5b97df 64 return &cur_entry;
va009039 0:39eb4d5b97df 65 }
va009039 0:39eb4d5b97df 66 #endif /* _USE_LFN */
va009039 0:39eb4d5b97df 67 }
va009039 0:39eb4d5b97df 68
va009039 0:39eb4d5b97df 69 void FATDirHandle::rewinddir() {
va009039 0:39eb4d5b97df 70 dir.index = 0;
va009039 0:39eb4d5b97df 71 }
va009039 0:39eb4d5b97df 72
va009039 0:39eb4d5b97df 73 off_t FATDirHandle::telldir() {
va009039 0:39eb4d5b97df 74 return dir.index;
va009039 0:39eb4d5b97df 75 }
va009039 0:39eb4d5b97df 76
va009039 0:39eb4d5b97df 77 void FATDirHandle::seekdir(off_t location) {
va009039 0:39eb4d5b97df 78 dir.index = location;
va009039 0:39eb4d5b97df 79 }
va009039 0:39eb4d5b97df 80