![](/media/cache/profiles/3ec0e2c7f4536e7ce9e9ce183b1de9e8.jpg.50x50_q85.jpg)
RAMDisk example for the USBFileSystem
Dependencies: mbed USBFileSystem
Fork of USBFileSystem_RAMDISK_HelloWorld by
Diff: RAM_DISK/USBMSD_Ram.cpp
- Revision:
- 2:1c8a3c4ba703
- Parent:
- 1:e1b0157ce547
- Child:
- 4:69b7cece8e72
diff -r e1b0157ce547 -r 1c8a3c4ba703 RAM_DISK/USBMSD_Ram.cpp --- a/RAM_DISK/USBMSD_Ram.cpp Tue Jul 30 18:27:18 2013 +0000 +++ b/RAM_DISK/USBMSD_Ram.cpp Sun Aug 04 19:59:07 2013 +0000 @@ -22,12 +22,12 @@ #include "USBMSD_Ram.h" -//5 sectors -const char disk[512*5] = { +const unsigned char disk[512*6] = { + //sector 0: boot sector - 0xEB,0x3C,0x90,0x4D,0x53,0x44,0x4F,0x53,0x35,0x2E,0x30, 0x00,0x02,/*bytes per sector: 512*/ 0x08, /*sectors per cluster*/ 0x01,0x00,/*number of reserved sector*/ - 0x01, /* number of FATs*/ 0x10,0x00, /*Maximum number of root directory entries: 16*/ 0x20,0x00, /*Total sector count: 32*/ 0xF0, 0x02,0x00,/*sectors per FAT: 2*/ 0x01,0x00,/*Sectors per track*/ 0x01,0x00, /*Number of heads*/ 0x00,0x00,0x00,0x00, + 0xEB,0x3C,0x90,0x4D,0x53,0x44,0x4F,0x53,0x35,0x2E,0x30, 0x00,0x02,/*bytes per sector: 512*/ 0x01, /*sectors per cluster*/ 0x01,0x00,/*number of reserved sector*/ + 0x01, /* number of FATs*/ 0x10,0x00, /*Maximum number of root directory entries: 16*/ 0x10,0x00, /*Total sector count: 16*/ 0xF0, 0x02,0x00,/*sectors per FAT: 2*/ 0x01,0x00,/*Sectors per track*/ 0x01,0x00, /*Number of heads*/ 0x00,0x00,0x00,0x00, 0x00,0x01,0x00,0x00,0x00,0x00, 0x29, /*boot signature*/ 0x74,0x19,0x02,0x27, /*volume ID*/ 'M','b','e','d',' ', 'U','S','B',' ',' ',' ', /*volume label: Mbed USB*/ 0x46,0x41,0x54,0x31,0x32,0x20,0x20,0x20,0x33,0xC9, 0x8E,0xD1,0xBC,0xF0,0x7B,0x8E,0xD9,0xB8,0x00,0x20,0x8E,0xC0,0xFC,0xBD,0x00,0x7C, @@ -129,12 +129,47 @@ //sector 3: root directory //entry 1 - 'M','b','e','d',' ','U','S','B',' ',' ',' ', 0x28,0x00,0x00,0x00,0x00, +'M','b','e','d',' ','U','S','B',' ',' ',' ', 0x28,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //entry 2 - 0x52,0x45,0x41,0x44,0x4D,0x45,0x20,0x20,0x54,0x58,0x54, /*readme.txt*/ 0x20,0x00,0x00,0x00,0x00, + 0x49,0x4E,0x20,0x20,0x20,0x20,0x20,0x20,0x54,0x58,0x54, /*IN.txt*/ 0x20,0x00,0x00,0x00,0x00, 0x21,0x00,0xBB,0x32,0x00,0x00, 0xDC,0x83,/*hour/min/doublesec*/ 0x6A,0x3F,/*year/month/day*/ 0x02,0x00, /*starting cluster*/ 0x1e,0x00,0x00,0x00, /*size*/ + //entry 3 + 0x4f,0x55,0x54,0x20,0x20,0x20,0x20,0x20,0x54,0x58,0x54, /*OUT.txt*/ 0x20,0x00,0x00,0x00,0x00, + 0x21,0x00,0xBB,0x32,0x00,0x00, 0xDC,0x83,/*hour/min/doublesec*/ 0x6A,0x3F,/*year/month/day*/ 0x03,0x00, /*starting cluster*/ 0x1e,0x00,0x00,0x00, /*size*/ + + + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + //sector 4: data + 'T','y','p','e',' ','y','o','u','r',' ','t','e','x','t',' ','h', + 'e','r','e','!',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -163,10 +198,12 @@ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - - //sector 4: data - 'H','e','l','l','o',' ','f','r','o','m',' ','M','b','e','d','!', - '\r','\n','U','S','B',' ','M','S','D',' ','d','e','m','o',0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + + //sector 5: data + 'W','r','i','t','e',' ','i','n',' ','y','o','u','r',' ','s','e', + 'r','i','a','l',' ','t','e','r','m','i','n','a','l','!',0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -198,23 +235,23 @@ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; - - - -USBMSD_Ram::USBMSD_Ram() { + + + +USBMSD_Ram::USBMSD_Ram() : USBFileSystem("USB") { //no init _status = 0x01; - memcpy(disk_image, disk, 512*5); - //connect(); + memcpy(disk_image, disk, 512*6); } + int USBMSD_Ram::disk_initialize() { // OK _status = 0x00; return 0; } -int USBMSD_Ram::disk_write(const uint8_t * buffer, uint64_t block_number) { +int USBMSD_Ram::_disk_write(const uint8_t * buffer, uint64_t block_number) { memcpy((void *)&disk_image[block_number*512], buffer, 512); return 0; } @@ -224,8 +261,6 @@ return 0; } -int USBMSD_Ram::disk_status() { return _status; } +int USBMSD_Ram::_disk_status() { return _status; } int USBMSD_Ram::disk_sync() { return 0; } -uint64_t USBMSD_Ram::disk_sectors() { return 32; } -uint64_t USBMSD_Ram::disk_size() { return 32*512;} - +uint64_t USBMSD_Ram::disk_sectors() { return 16; }