Emulation of LocalFileSystem with virtual COM.
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
USBLocalFileSystem.cpp@2:97c314eae8b8, 2014-05-06 (annotated)
- Committer:
- va009039
- Date:
- Tue May 06 15:42:30 2014 +0900
- Branch:
- branch
- Revision:
- 2:97c314eae8b8
- Parent:
- 1:00c9eb8af5c2
- Child:
- 4:8f6857784854
add USB MSD block operation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:39eb4d5b97df | 1 | #include "USBLocalFileSystem.h" |
va009039 | 0:39eb4d5b97df | 2 | #include "RamDisk.h" |
va009039 | 0:39eb4d5b97df | 3 | #include "SDStorage.h" |
va009039 | 0:39eb4d5b97df | 4 | |
va009039 | 0:39eb4d5b97df | 5 | USBLocalFileSystem::USBLocalFileSystem(const char* name) |
va009039 | 0:39eb4d5b97df | 6 | { |
va009039 | 0:39eb4d5b97df | 7 | RamDisk* storage = new RamDisk; |
va009039 | 0:39eb4d5b97df | 8 | init(storage, name); |
va009039 | 0:39eb4d5b97df | 9 | } |
va009039 | 0:39eb4d5b97df | 10 | |
va009039 | 0:39eb4d5b97df | 11 | USBLocalFileSystem::USBLocalFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) |
va009039 | 0:39eb4d5b97df | 12 | { |
va009039 | 0:39eb4d5b97df | 13 | SDStorage* storage = new SDStorage(mosi, miso, sclk, cs); |
va009039 | 0:39eb4d5b97df | 14 | storage->storage_initialize(); |
va009039 | 0:39eb4d5b97df | 15 | init(storage, name); |
va009039 | 0:39eb4d5b97df | 16 | } |
va009039 | 0:39eb4d5b97df | 17 | |
va009039 | 0:39eb4d5b97df | 18 | USBLocalFileSystem::USBLocalFileSystem(StorageInterface* storage, const char* name) |
va009039 | 0:39eb4d5b97df | 19 | { |
va009039 | 0:39eb4d5b97df | 20 | init(storage, name); |
va009039 | 0:39eb4d5b97df | 21 | } |
va009039 | 0:39eb4d5b97df | 22 | |
va009039 | 0:39eb4d5b97df | 23 | void USBLocalFileSystem::init(StorageInterface* storage, const char* name) |
va009039 | 0:39eb4d5b97df | 24 | { |
va009039 | 0:39eb4d5b97df | 25 | _name = name; |
va009039 | 0:39eb4d5b97df | 26 | _storage = storage; |
va009039 | 0:39eb4d5b97df | 27 | _usb = new USBStorage2(_storage); |
va009039 | 0:39eb4d5b97df | 28 | _local = new LocalStorage(_storage); |
va009039 | 0:39eb4d5b97df | 29 | } |
va009039 | 0:39eb4d5b97df | 30 | |
va009039 | 0:39eb4d5b97df | 31 | void USBLocalFileSystem::remount() |
va009039 | 0:39eb4d5b97df | 32 | { |
va009039 | 0:39eb4d5b97df | 33 | if (_local) { |
va009039 | 0:39eb4d5b97df | 34 | delete _local; |
va009039 | 0:39eb4d5b97df | 35 | } |
va009039 | 0:39eb4d5b97df | 36 | _local = new LocalStorage(_storage); |
va009039 | 0:39eb4d5b97df | 37 | } |
va009039 | 0:39eb4d5b97df | 38 | |
va009039 | 1:00c9eb8af5c2 | 39 | |
va009039 | 1:00c9eb8af5c2 | 40 | int USBLocalFileSystem::readable() |
va009039 | 0:39eb4d5b97df | 41 | { |
va009039 | 1:00c9eb8af5c2 | 42 | return _usb->readable(); |
va009039 | 1:00c9eb8af5c2 | 43 | } |
va009039 | 1:00c9eb8af5c2 | 44 | |
va009039 | 1:00c9eb8af5c2 | 45 | int USBLocalFileSystem::writeable() |
va009039 | 1:00c9eb8af5c2 | 46 | { |
va009039 | 1:00c9eb8af5c2 | 47 | return _usb->writeable(); |
va009039 | 0:39eb4d5b97df | 48 | } |
va009039 | 0:39eb4d5b97df | 49 | |
va009039 | 0:39eb4d5b97df | 50 | int USBLocalFileSystem::getc() |
va009039 | 0:39eb4d5b97df | 51 | { |
va009039 | 0:39eb4d5b97df | 52 | return _usb->getc(); |
va009039 | 0:39eb4d5b97df | 53 | } |
va009039 | 0:39eb4d5b97df | 54 | |
va009039 | 1:00c9eb8af5c2 | 55 | void USBLocalFileSystem::putc(int c) |
va009039 | 1:00c9eb8af5c2 | 56 | { |
va009039 | 1:00c9eb8af5c2 | 57 | _usb->putc(c); |
va009039 | 1:00c9eb8af5c2 | 58 | } |
va009039 | 1:00c9eb8af5c2 | 59 | |
va009039 |
2:97c314eae8b8 | 60 |