パラメータを適応変化させる事により圧縮率を向上させた動的ライス・ゴロム符号を利用した可逆圧縮方式。圧縮ソフト、圧縮率のMATLABシミュレーションは詳細はInterface誌2011年8月号に掲載されるRX62Nマイコン連動特集にて掲載予定。
MSCFileSystem.cpp@0:d920d64db582, 2011-03-30 (annotated)
- Committer:
- lynxeyed_atsu
- Date:
- Wed Mar 30 06:05:24 2011 +0000
- Revision:
- 0:d920d64db582
alpha
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lynxeyed_atsu | 0:d920d64db582 | 1 | /* USB Mass Storage device file system |
lynxeyed_atsu | 0:d920d64db582 | 2 | * Copyrigh (c) 2010, Igor Skochinsky |
lynxeyed_atsu | 0:d920d64db582 | 3 | * based on SDFileStorage |
lynxeyed_atsu | 0:d920d64db582 | 4 | * Copyright (c) 2008-2009, sford |
lynxeyed_atsu | 0:d920d64db582 | 5 | */ |
lynxeyed_atsu | 0:d920d64db582 | 6 | |
lynxeyed_atsu | 0:d920d64db582 | 7 | /* Introduction |
lynxeyed_atsu | 0:d920d64db582 | 8 | * ------------ |
lynxeyed_atsu | 0:d920d64db582 | 9 | * TODO: write one |
lynxeyed_atsu | 0:d920d64db582 | 10 | * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library |
lynxeyed_atsu | 0:d920d64db582 | 11 | */ |
lynxeyed_atsu | 0:d920d64db582 | 12 | |
lynxeyed_atsu | 0:d920d64db582 | 13 | #include "MSCFileSystem.h" |
lynxeyed_atsu | 0:d920d64db582 | 14 | #include "usbhost_inc.h" |
lynxeyed_atsu | 0:d920d64db582 | 15 | |
lynxeyed_atsu | 0:d920d64db582 | 16 | MSCFileSystem::MSCFileSystem(const char* name) : |
lynxeyed_atsu | 0:d920d64db582 | 17 | FATFileSystem(name) |
lynxeyed_atsu | 0:d920d64db582 | 18 | { |
lynxeyed_atsu | 0:d920d64db582 | 19 | } |
lynxeyed_atsu | 0:d920d64db582 | 20 | |
lynxeyed_atsu | 0:d920d64db582 | 21 | void print_inquiry(USB_INT08U *inqReply) |
lynxeyed_atsu | 0:d920d64db582 | 22 | { |
lynxeyed_atsu | 0:d920d64db582 | 23 | // see USB Mass Storage Class – UFI Command Specification, |
lynxeyed_atsu | 0:d920d64db582 | 24 | // 4.2 INQUIRY Command |
lynxeyed_atsu | 0:d920d64db582 | 25 | printf("Inquiry reply:\n"); |
lynxeyed_atsu | 0:d920d64db582 | 26 | uint8_t tmp = inqReply[0]&0x1F; |
lynxeyed_atsu | 0:d920d64db582 | 27 | printf("Peripheral device type: %02Xh\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 28 | if ( tmp == 0 ) |
lynxeyed_atsu | 0:d920d64db582 | 29 | printf("\t- Direct access (floppy)\n"); |
lynxeyed_atsu | 0:d920d64db582 | 30 | else if ( tmp == 0x1F ) |
lynxeyed_atsu | 0:d920d64db582 | 31 | printf("\t- none (no FDD connected)\n"); |
lynxeyed_atsu | 0:d920d64db582 | 32 | else |
lynxeyed_atsu | 0:d920d64db582 | 33 | printf("\t- unknown type\n"); |
lynxeyed_atsu | 0:d920d64db582 | 34 | tmp = inqReply[1] >> 7; |
lynxeyed_atsu | 0:d920d64db582 | 35 | printf("Removable Media Bit: %d\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 36 | tmp = inqReply[2] & 3; |
lynxeyed_atsu | 0:d920d64db582 | 37 | printf("ANSI Version: %02Xh\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 38 | if ( tmp != 0 ) |
lynxeyed_atsu | 0:d920d64db582 | 39 | printf("\t- warning! must be 0\n"); |
lynxeyed_atsu | 0:d920d64db582 | 40 | tmp = (inqReply[2]>>3) & 3; |
lynxeyed_atsu | 0:d920d64db582 | 41 | printf("ECMA Version: %02Xh\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 42 | if ( tmp != 0 ) |
lynxeyed_atsu | 0:d920d64db582 | 43 | printf("\t- warning! should be 0\n"); |
lynxeyed_atsu | 0:d920d64db582 | 44 | tmp = inqReply[2]>>6; |
lynxeyed_atsu | 0:d920d64db582 | 45 | printf("ISO Version: %02Xh\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 46 | if ( tmp != 0 ) |
lynxeyed_atsu | 0:d920d64db582 | 47 | printf("\t- warning! should be 0\n"); |
lynxeyed_atsu | 0:d920d64db582 | 48 | tmp = inqReply[3] & 0xF; |
lynxeyed_atsu | 0:d920d64db582 | 49 | printf("Response Data Format: %02Xh\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 50 | if ( tmp != 1 ) |
lynxeyed_atsu | 0:d920d64db582 | 51 | printf("\t- warning! should be 1\n"); |
lynxeyed_atsu | 0:d920d64db582 | 52 | tmp = inqReply[4]; |
lynxeyed_atsu | 0:d920d64db582 | 53 | printf("Additional length: %02Xh\n", tmp); |
lynxeyed_atsu | 0:d920d64db582 | 54 | if ( tmp != 0x1F ) |
lynxeyed_atsu | 0:d920d64db582 | 55 | printf("\t- warning! should be 1Fh\n"); |
lynxeyed_atsu | 0:d920d64db582 | 56 | printf("Vendor Information: '%.8s'\n", &inqReply[8]); |
lynxeyed_atsu | 0:d920d64db582 | 57 | printf("Product Identification: '%.16s'\n", &inqReply[16]); |
lynxeyed_atsu | 0:d920d64db582 | 58 | printf("Product Revision: '%.4s'\n", &inqReply[32]); |
lynxeyed_atsu | 0:d920d64db582 | 59 | } |
lynxeyed_atsu | 0:d920d64db582 | 60 | |
lynxeyed_atsu | 0:d920d64db582 | 61 | int MSCFileSystem::initialise_msc() |
lynxeyed_atsu | 0:d920d64db582 | 62 | { |
lynxeyed_atsu | 0:d920d64db582 | 63 | USB_INT32S rc; |
lynxeyed_atsu | 0:d920d64db582 | 64 | USB_INT08U inquiryResult[INQUIRY_LENGTH]; |
lynxeyed_atsu | 0:d920d64db582 | 65 | |
lynxeyed_atsu | 0:d920d64db582 | 66 | //print_clock(); |
lynxeyed_atsu | 0:d920d64db582 | 67 | Host_Init(); /* Initialize the host controller */ |
lynxeyed_atsu | 0:d920d64db582 | 68 | rc = Host_EnumDev(); /* Enumerate the device connected */ |
lynxeyed_atsu | 0:d920d64db582 | 69 | if (rc != OK) |
lynxeyed_atsu | 0:d920d64db582 | 70 | { |
lynxeyed_atsu | 0:d920d64db582 | 71 | fprintf(stderr, "Could not enumerate device: %d\n", rc); |
lynxeyed_atsu | 0:d920d64db582 | 72 | return rc; |
lynxeyed_atsu | 0:d920d64db582 | 73 | } |
lynxeyed_atsu | 0:d920d64db582 | 74 | |
lynxeyed_atsu | 0:d920d64db582 | 75 | |
lynxeyed_atsu | 0:d920d64db582 | 76 | /* Initialize the mass storage and scsi interfaces */ |
lynxeyed_atsu | 0:d920d64db582 | 77 | rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); |
lynxeyed_atsu | 0:d920d64db582 | 78 | if (rc != OK) |
lynxeyed_atsu | 0:d920d64db582 | 79 | { |
lynxeyed_atsu | 0:d920d64db582 | 80 | fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); |
lynxeyed_atsu | 0:d920d64db582 | 81 | return rc; |
lynxeyed_atsu | 0:d920d64db582 | 82 | } |
lynxeyed_atsu | 0:d920d64db582 | 83 | printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); |
lynxeyed_atsu | 0:d920d64db582 | 84 | print_inquiry(inquiryResult); |
lynxeyed_atsu | 0:d920d64db582 | 85 | // FATFileSystem supports only 512-byte blocks |
lynxeyed_atsu | 0:d920d64db582 | 86 | return _blkSize == 512 ? OK : 1; |
lynxeyed_atsu | 0:d920d64db582 | 87 | } |
lynxeyed_atsu | 0:d920d64db582 | 88 | |
lynxeyed_atsu | 0:d920d64db582 | 89 | int MSCFileSystem::disk_initialize() |
lynxeyed_atsu | 0:d920d64db582 | 90 | { |
lynxeyed_atsu | 0:d920d64db582 | 91 | if ( initialise_msc() != OK ) |
lynxeyed_atsu | 0:d920d64db582 | 92 | return 1; |
lynxeyed_atsu | 0:d920d64db582 | 93 | |
lynxeyed_atsu | 0:d920d64db582 | 94 | return 0; |
lynxeyed_atsu | 0:d920d64db582 | 95 | } |
lynxeyed_atsu | 0:d920d64db582 | 96 | |
lynxeyed_atsu | 0:d920d64db582 | 97 | int MSCFileSystem::disk_write(const char *buffer, int block_number) |
lynxeyed_atsu | 0:d920d64db582 | 98 | { |
lynxeyed_atsu | 0:d920d64db582 | 99 | if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) ) |
lynxeyed_atsu | 0:d920d64db582 | 100 | return 0; |
lynxeyed_atsu | 0:d920d64db582 | 101 | return 1; |
lynxeyed_atsu | 0:d920d64db582 | 102 | } |
lynxeyed_atsu | 0:d920d64db582 | 103 | |
lynxeyed_atsu | 0:d920d64db582 | 104 | int MSCFileSystem::disk_read(char *buffer, int block_number) |
lynxeyed_atsu | 0:d920d64db582 | 105 | { |
lynxeyed_atsu | 0:d920d64db582 | 106 | if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) ) |
lynxeyed_atsu | 0:d920d64db582 | 107 | return 0; |
lynxeyed_atsu | 0:d920d64db582 | 108 | return 1; |
lynxeyed_atsu | 0:d920d64db582 | 109 | } |
lynxeyed_atsu | 0:d920d64db582 | 110 | |
lynxeyed_atsu | 0:d920d64db582 | 111 | int MSCFileSystem::disk_status() { return 0; } |
lynxeyed_atsu | 0:d920d64db582 | 112 | int MSCFileSystem::disk_sync() { return 0; } |
lynxeyed_atsu | 0:d920d64db582 | 113 | int MSCFileSystem::disk_sectors() { return _numBlks; } |