Norimasa Okamoto / USBLocalFileSystem

Dependencies:   USBDevice

Dependents:   KL46Z-lpc81isp lpcterm2

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBLocalFileSystem.h Source File

USBLocalFileSystem.h

00001 #pragma once
00002 #include "Storage.h"
00003 
00004 /** Access the LocalFileSystem using RamDisk(64KB)
00005  *
00006  * @code
00007  * #include "USBLocalFileSystem.h"
00008  *
00009  * int main() {
00010  *     USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB) 
00011  *
00012  *     FILE *fp = fopen("/local/mbed.txt", "a");
00013  *     fprintf(fp, "Hello World!\n");
00014  *     fclose(fp);
00015  * }
00016  * @endcode
00017  */
00018 class USBLocalFileSystem {
00019 public:
00020 
00021     /** Create the Local File System using RamDisk(64KB)
00022      *
00023      * @param name The name used to access the virtual filesystem
00024      */
00025     USBLocalFileSystem(const char* name = "local");
00026 
00027     /** Create the Local File System for accessing an SD Card using SPI
00028      *
00029      * @param mosi SPI mosi pin connected to SD Card
00030      * @param miso SPI miso pin conencted to SD Card
00031      * @param sclk SPI sclk pin connected to SD Card
00032      * @param cs   DigitalOut pin used as SD Card chip select
00033      * @param name The name used to access the virtual filesystem
00034      */    
00035     USBLocalFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name = "local");
00036     
00037     /** Create the Local File System using StorageInterface
00038      *
00039      * @param storage StorageInterface 
00040      * @param name The name used to access the virtual filesystem
00041      */ 
00042     USBLocalFileSystem(StorageInterface* storage, const char* name = "local");
00043 
00044     void remount(); // remount local storage
00045     int lock(bool f);
00046     bool find(char* name, size_t size, const char* pat);
00047 
00048     /** Determine if there is a character available to read
00049      *
00050      *  @returns
00051      *    1 if there is a character available to read,
00052      *    0 otherwise
00053      */
00054     int readable();
00055     
00056      /** Determine if there is space available to write a character
00057      *
00058      *  @returns
00059      *    1 if there is space to write a character,
00060      *    0 otherwise
00061      */
00062     int writeable();
00063 
00064     /** Read a char from the serial port
00065      *
00066      * @returns The char read from the serial port
00067      */
00068     int getc();
00069 
00070     /** Write a char to the serial port
00071      *
00072      * @param c The char to write
00073      *
00074      * @returns The written char or -1 if an error occured
00075      */
00076     int putc(int c);
00077 
00078     /** Write a string to the serial port
00079      *
00080      * @param str The string to write
00081      *
00082      * @returns 0 if the write succeeds, EOF for error
00083      */
00084     int puts(const char* str);
00085 
00086     void attachSendBreak(void (*fptr)(uint16_t duration));
00087     void attachControlLineState(void (*fptr)(int dts, int dtr));
00088     void attachSettingChanged(void (*fptr)(int baud, int bits, int parity, int stop));
00089 
00090     StorageInterface* getStoage() { return _storage; }
00091     LocalStorage* getLocal() { return _local; }
00092     USBStorage2* getUsb() { return _usb; }
00093 
00094 private:
00095     void init(StorageInterface* storage, const char* name);
00096     const char* _name;
00097     StorageInterface* _storage;
00098     LocalStorage* _local;
00099     USBStorage2* _usb;
00100 };