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 //-----------------------------------------------------------------------
va009039 0:39eb4d5b97df 2 // Low level disk interface modlue include file
va009039 0:39eb4d5b97df 3 //-----------------------------------------------------------------------
va009039 0:39eb4d5b97df 4
va009039 0:39eb4d5b97df 5 #ifndef _DISKIO
va009039 0:39eb4d5b97df 6
va009039 0:39eb4d5b97df 7 #define _READONLY 0 // 1: Remove write functions
va009039 0:39eb4d5b97df 8 #define _USE_IOCTL 1 // 1: Use disk_ioctl fucntion
va009039 0:39eb4d5b97df 9
va009039 0:39eb4d5b97df 10 #include "integer.h"
va009039 0:39eb4d5b97df 11
va009039 0:39eb4d5b97df 12
va009039 0:39eb4d5b97df 13 // Status of Disk Functions
va009039 0:39eb4d5b97df 14 typedef BYTE DSTATUS;
va009039 0:39eb4d5b97df 15
va009039 0:39eb4d5b97df 16 // Results of Disk Functions
va009039 0:39eb4d5b97df 17 typedef enum {
va009039 0:39eb4d5b97df 18 RES_OK = 0, // 0: Successful
va009039 0:39eb4d5b97df 19 RES_ERROR, // 1: R/W Error
va009039 0:39eb4d5b97df 20 RES_WRPRT, // 2: Write Protected
va009039 0:39eb4d5b97df 21 RES_NOTRDY, // 3: Not Ready
va009039 0:39eb4d5b97df 22 RES_PARERR // 4: Invalid Parameter
va009039 0:39eb4d5b97df 23 } DRESULT;
va009039 0:39eb4d5b97df 24
va009039 0:39eb4d5b97df 25
va009039 0:39eb4d5b97df 26 // Prototypes for disk control functions
va009039 0:39eb4d5b97df 27
va009039 0:39eb4d5b97df 28 int assign_drives (int, int);
va009039 0:39eb4d5b97df 29 DSTATUS disk_initialize (BYTE);
va009039 0:39eb4d5b97df 30 DSTATUS disk_status (BYTE);
va009039 0:39eb4d5b97df 31 DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
va009039 0:39eb4d5b97df 32 #if _READONLY == 0
va009039 0:39eb4d5b97df 33 DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
va009039 0:39eb4d5b97df 34 #endif
va009039 0:39eb4d5b97df 35 DRESULT disk_ioctl (BYTE, BYTE, void*);
va009039 0:39eb4d5b97df 36
va009039 0:39eb4d5b97df 37
va009039 0:39eb4d5b97df 38
va009039 0:39eb4d5b97df 39 // Disk Status Bits (DSTATUS)
va009039 0:39eb4d5b97df 40 #define STA_NOINIT 0x01 // Drive not initialized
va009039 0:39eb4d5b97df 41 #define STA_NODISK 0x02 // No medium in the drive
va009039 0:39eb4d5b97df 42 #define STA_PROTECT 0x04 // Write protected
va009039 0:39eb4d5b97df 43
va009039 0:39eb4d5b97df 44
va009039 0:39eb4d5b97df 45 // Command code for disk_ioctrl fucntion
va009039 0:39eb4d5b97df 46
va009039 0:39eb4d5b97df 47 // Generic command (defined for FatFs)
va009039 0:39eb4d5b97df 48 #define CTRL_SYNC 0 // Flush disk cache (for write functions)
va009039 0:39eb4d5b97df 49 #define GET_SECTOR_COUNT 1 // Get media size (for only f_mkfs())
va009039 0:39eb4d5b97df 50 #define GET_SECTOR_SIZE 2 // Get sector size (for multiple sector size (_MAX_SS >= 1024))
va009039 0:39eb4d5b97df 51 #define GET_BLOCK_SIZE 3 // Get erase block size (for only f_mkfs())
va009039 0:39eb4d5b97df 52 #define CTRL_ERASE_SECTOR 4 // Force erased a block of sectors (for only _USE_ERASE)
va009039 0:39eb4d5b97df 53
va009039 0:39eb4d5b97df 54 // Generic command
va009039 0:39eb4d5b97df 55 #define CTRL_POWER 5 // Get/Set power status
va009039 0:39eb4d5b97df 56 #define CTRL_LOCK 6 // Lock/Unlock media removal
va009039 0:39eb4d5b97df 57 #define CTRL_EJECT 7 // Eject media
va009039 0:39eb4d5b97df 58
va009039 0:39eb4d5b97df 59 // MMC/SDC specific ioctl command
va009039 0:39eb4d5b97df 60 #define MMC_GET_TYPE 10 // Get card type
va009039 0:39eb4d5b97df 61 #define MMC_GET_CSD 11 // Get CSD
va009039 0:39eb4d5b97df 62 #define MMC_GET_CID 12 // Get CID
va009039 0:39eb4d5b97df 63 #define MMC_GET_OCR 13 // Get OCR
va009039 0:39eb4d5b97df 64 #define MMC_GET_SDSTAT 14 // Get SD status
va009039 0:39eb4d5b97df 65
va009039 0:39eb4d5b97df 66 // ATA/CF specific ioctl command
va009039 0:39eb4d5b97df 67 #define ATA_GET_REV 20 // Get F/W revision
va009039 0:39eb4d5b97df 68 #define ATA_GET_MODEL 21 // Get model name
va009039 0:39eb4d5b97df 69 #define ATA_GET_SN 22 // Get serial number
va009039 0:39eb4d5b97df 70
va009039 0:39eb4d5b97df 71 // NAND specific ioctl command
va009039 0:39eb4d5b97df 72 #define NAND_FORMAT 30 // Create physical format
va009039 0:39eb4d5b97df 73
va009039 0:39eb4d5b97df 74
va009039 0:39eb4d5b97df 75 #define _DISKIO
va009039 0:39eb4d5b97df 76 #endif