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@6:528036abfb02, 2014-06-21 (annotated)
- Committer:
- va009039
- Date:
- Sat Jun 21 22:39:59 2014 +0000
- Revision:
- 6:528036abfb02
- Parent:
- 4:8f6857784854
add LPC11U68
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 |
4:8f6857784854 | 4 | #include "USB_CDC.h" |
va009039 | 0:39eb4d5b97df | 5 | |
va009039 | 0:39eb4d5b97df | 6 | USBLocalFileSystem::USBLocalFileSystem(const char* name) |
va009039 | 0:39eb4d5b97df | 7 | { |
va009039 | 0:39eb4d5b97df | 8 | RamDisk* storage = new RamDisk; |
va009039 | 0:39eb4d5b97df | 9 | init(storage, name); |
va009039 | 0:39eb4d5b97df | 10 | } |
va009039 | 0:39eb4d5b97df | 11 | |
va009039 | 0:39eb4d5b97df | 12 | USBLocalFileSystem::USBLocalFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) |
va009039 | 0:39eb4d5b97df | 13 | { |
va009039 | 0:39eb4d5b97df | 14 | SDStorage* storage = new SDStorage(mosi, miso, sclk, cs); |
va009039 | 0:39eb4d5b97df | 15 | storage->storage_initialize(); |
va009039 | 0:39eb4d5b97df | 16 | init(storage, name); |
va009039 | 0:39eb4d5b97df | 17 | } |
va009039 | 0:39eb4d5b97df | 18 | |
va009039 | 0:39eb4d5b97df | 19 | USBLocalFileSystem::USBLocalFileSystem(StorageInterface* storage, const char* name) |
va009039 | 0:39eb4d5b97df | 20 | { |
va009039 | 0:39eb4d5b97df | 21 | init(storage, name); |
va009039 | 0:39eb4d5b97df | 22 | } |
va009039 | 0:39eb4d5b97df | 23 | |
va009039 | 0:39eb4d5b97df | 24 | void USBLocalFileSystem::init(StorageInterface* storage, const char* name) |
va009039 | 0:39eb4d5b97df | 25 | { |
va009039 | 0:39eb4d5b97df | 26 | _name = name; |
va009039 | 0:39eb4d5b97df | 27 | _storage = storage; |
va009039 | 0:39eb4d5b97df | 28 | _usb = new USBStorage2(_storage); |
va009039 | 0:39eb4d5b97df | 29 | _local = new LocalStorage(_storage); |
va009039 | 0:39eb4d5b97df | 30 | } |
va009039 | 0:39eb4d5b97df | 31 | |
va009039 | 0:39eb4d5b97df | 32 | void USBLocalFileSystem::remount() |
va009039 | 0:39eb4d5b97df | 33 | { |
va009039 | 0:39eb4d5b97df | 34 | if (_local) { |
va009039 | 0:39eb4d5b97df | 35 | delete _local; |
va009039 | 0:39eb4d5b97df | 36 | } |
va009039 | 0:39eb4d5b97df | 37 | _local = new LocalStorage(_storage); |
va009039 | 0:39eb4d5b97df | 38 | } |
va009039 | 0:39eb4d5b97df | 39 | |
va009039 |
4:8f6857784854 | 40 | int USBLocalFileSystem::lock(bool f) |
va009039 |
4:8f6857784854 | 41 | { |
va009039 |
4:8f6857784854 | 42 | return _usb->block(f); |
va009039 |
4:8f6857784854 | 43 | } |
va009039 |
4:8f6857784854 | 44 | |
va009039 |
4:8f6857784854 | 45 | bool USBLocalFileSystem::find(char* name, size_t size, const char* pat) |
va009039 |
4:8f6857784854 | 46 | { |
va009039 |
4:8f6857784854 | 47 | return LocalStorage::find(name, size, _name, pat); |
va009039 |
4:8f6857784854 | 48 | } |
va009039 | 1:00c9eb8af5c2 | 49 | |
va009039 | 1:00c9eb8af5c2 | 50 | int USBLocalFileSystem::readable() |
va009039 | 0:39eb4d5b97df | 51 | { |
va009039 | 1:00c9eb8af5c2 | 52 | return _usb->readable(); |
va009039 | 1:00c9eb8af5c2 | 53 | } |
va009039 | 1:00c9eb8af5c2 | 54 | |
va009039 | 1:00c9eb8af5c2 | 55 | int USBLocalFileSystem::writeable() |
va009039 | 1:00c9eb8af5c2 | 56 | { |
va009039 | 1:00c9eb8af5c2 | 57 | return _usb->writeable(); |
va009039 | 0:39eb4d5b97df | 58 | } |
va009039 | 0:39eb4d5b97df | 59 | |
va009039 | 0:39eb4d5b97df | 60 | int USBLocalFileSystem::getc() |
va009039 | 0:39eb4d5b97df | 61 | { |
va009039 | 0:39eb4d5b97df | 62 | return _usb->getc(); |
va009039 | 0:39eb4d5b97df | 63 | } |
va009039 | 0:39eb4d5b97df | 64 | |
va009039 |
4:8f6857784854 | 65 | int USBLocalFileSystem::putc(int c) |
va009039 | 1:00c9eb8af5c2 | 66 | { |
va009039 | 1:00c9eb8af5c2 | 67 | _usb->putc(c); |
va009039 |
4:8f6857784854 | 68 | return c; |
va009039 |
4:8f6857784854 | 69 | } |
va009039 |
4:8f6857784854 | 70 | |
va009039 |
4:8f6857784854 | 71 | int USBLocalFileSystem::puts(const char* str) |
va009039 |
4:8f6857784854 | 72 | { |
va009039 |
4:8f6857784854 | 73 | while(*str) { |
va009039 |
4:8f6857784854 | 74 | putc(*str++); |
va009039 |
4:8f6857784854 | 75 | } |
va009039 |
4:8f6857784854 | 76 | return 0; |
va009039 | 1:00c9eb8af5c2 | 77 | } |
va009039 | 1:00c9eb8af5c2 | 78 | |
va009039 |
4:8f6857784854 | 79 | void USBLocalFileSystem::attachSendBreak(void (*fptr)(uint16_t duration)) |
va009039 |
4:8f6857784854 | 80 | { |
va009039 |
4:8f6857784854 | 81 | getUsb()->getCDC()->attachSendBreak(fptr); |
va009039 |
4:8f6857784854 | 82 | } |
va009039 |
2:97c314eae8b8 | 83 | |
va009039 |
4:8f6857784854 | 84 | void USBLocalFileSystem::attachControlLineState(void (*fptr)(int dts, int dtr)) |
va009039 |
4:8f6857784854 | 85 | { |
va009039 |
4:8f6857784854 | 86 | getUsb()->getCDC()->attachControlLineStateChanged(fptr); |
va009039 |
4:8f6857784854 | 87 | } |
va009039 |
4:8f6857784854 | 88 | |
va009039 |
4:8f6857784854 | 89 | void USBLocalFileSystem::attachSettingChanged(void (*fptr)(int baud, int bits, int parity, int stop)) |
va009039 |
4:8f6857784854 | 90 | { |
va009039 |
4:8f6857784854 | 91 | getUsb()->getCDC()->attach(fptr); |
va009039 |
4:8f6857784854 | 92 | } |
va009039 |
4:8f6857784854 | 93 |