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
src/mymap.h@6:528036abfb02, 2014-06-21 (annotated)
- 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?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:39eb4d5b97df | 1 | #pragma once |
va009039 | 0:39eb4d5b97df | 2 | |
va009039 | 0:39eb4d5b97df | 3 | template<class K,class T> |
va009039 | 0:39eb4d5b97df | 4 | class mymap { |
va009039 | 0:39eb4d5b97df | 5 | struct mypair { |
va009039 | 0:39eb4d5b97df | 6 | K first; |
va009039 | 0:39eb4d5b97df | 7 | T second; |
va009039 | 0:39eb4d5b97df | 8 | }; |
va009039 | 0:39eb4d5b97df | 9 | public: |
va009039 | 0:39eb4d5b97df | 10 | mymap() { |
va009039 | 0:39eb4d5b97df | 11 | m_size = 0; |
va009039 | 0:39eb4d5b97df | 12 | } |
va009039 | 0:39eb4d5b97df | 13 | T& operator[](const K& key) { |
va009039 | 0:39eb4d5b97df | 14 | int it; |
va009039 | 0:39eb4d5b97df | 15 | if (count(key) == 0) { |
va009039 | 0:39eb4d5b97df | 16 | it = insert(key, 0); |
va009039 | 0:39eb4d5b97df | 17 | } else { |
va009039 | 0:39eb4d5b97df | 18 | it = find(key); |
va009039 | 0:39eb4d5b97df | 19 | } |
va009039 | 0:39eb4d5b97df | 20 | return m_buf[it].second; |
va009039 | 0:39eb4d5b97df | 21 | } |
va009039 | 0:39eb4d5b97df | 22 | bool empty() { return m_size == 0 ? true : false; } |
va009039 | 0:39eb4d5b97df | 23 | int size() { return m_size; } |
va009039 | 0:39eb4d5b97df | 24 | void clear() { m_size = 0; } |
va009039 | 0:39eb4d5b97df | 25 | int count(K key) { |
va009039 | 0:39eb4d5b97df | 26 | for(int i = 0; i < m_size; i++) { |
va009039 | 0:39eb4d5b97df | 27 | if (m_buf[i].first == key) { |
va009039 | 0:39eb4d5b97df | 28 | return 1; |
va009039 | 0:39eb4d5b97df | 29 | } |
va009039 | 0:39eb4d5b97df | 30 | } |
va009039 | 0:39eb4d5b97df | 31 | return 0; |
va009039 | 0:39eb4d5b97df | 32 | } |
va009039 | 0:39eb4d5b97df | 33 | K getKey(int index) { |
va009039 | 0:39eb4d5b97df | 34 | return m_buf[index].first; |
va009039 | 0:39eb4d5b97df | 35 | } |
va009039 | 0:39eb4d5b97df | 36 | |
va009039 | 0:39eb4d5b97df | 37 | private: |
va009039 | 0:39eb4d5b97df | 38 | int find(K key) { |
va009039 | 0:39eb4d5b97df | 39 | for(int i = 0; i < m_size; i++) { |
va009039 | 0:39eb4d5b97df | 40 | if (m_buf[i].first == key) { |
va009039 | 0:39eb4d5b97df | 41 | return i; |
va009039 | 0:39eb4d5b97df | 42 | } |
va009039 | 0:39eb4d5b97df | 43 | } |
va009039 | 0:39eb4d5b97df | 44 | return -1; |
va009039 | 0:39eb4d5b97df | 45 | } |
va009039 | 0:39eb4d5b97df | 46 | int insert(K key, T value) { |
va009039 | 0:39eb4d5b97df | 47 | int it = find(key); |
va009039 | 0:39eb4d5b97df | 48 | if (it != -1) { |
va009039 | 0:39eb4d5b97df | 49 | m_buf[it].second = value; |
va009039 | 0:39eb4d5b97df | 50 | return it; |
va009039 | 0:39eb4d5b97df | 51 | } |
va009039 | 0:39eb4d5b97df | 52 | mypair* new_buf = new mypair[m_size+1]; |
va009039 | 0:39eb4d5b97df | 53 | if (m_size > 0) { |
va009039 | 0:39eb4d5b97df | 54 | for(int i = 0; i < m_size; i++) { |
va009039 | 0:39eb4d5b97df | 55 | new_buf[i] = m_buf[i]; |
va009039 | 0:39eb4d5b97df | 56 | } |
va009039 | 0:39eb4d5b97df | 57 | delete[] m_buf; |
va009039 | 0:39eb4d5b97df | 58 | } |
va009039 | 0:39eb4d5b97df | 59 | m_buf = new_buf; |
va009039 | 0:39eb4d5b97df | 60 | it = m_size++; |
va009039 | 0:39eb4d5b97df | 61 | m_buf[it].first = key; |
va009039 | 0:39eb4d5b97df | 62 | m_buf[it].second = value; |
va009039 | 0:39eb4d5b97df | 63 | return it; |
va009039 | 0:39eb4d5b97df | 64 | } |
va009039 | 0:39eb4d5b97df | 65 | |
va009039 | 0:39eb4d5b97df | 66 | int m_size; |
va009039 | 0:39eb4d5b97df | 67 | mypair *m_buf; |
va009039 | 0:39eb4d5b97df | 68 | }; |