MDX-20用の改造

Dependencies:   FatFileSystemCpp

Committer:
suupen
Date:
Wed Nov 23 09:12:30 2016 +0000
Revision:
4:dc14f62cb09f
Parent:
0:e294af8d0e07
Child:
7:a6b950d25e29
usbmemory???prn?????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
igorsk 0:e294af8d0e07 1 /* USB Mass Storage device file system
igorsk 0:e294af8d0e07 2 * Copyrigh (c) 2010, Igor Skochinsky
igorsk 0:e294af8d0e07 3 * based on SDFileStorage
igorsk 0:e294af8d0e07 4 * Copyright (c) 2008-2009, sford
igorsk 0:e294af8d0e07 5 */
igorsk 0:e294af8d0e07 6
igorsk 0:e294af8d0e07 7 /* Introduction
igorsk 0:e294af8d0e07 8 * ------------
igorsk 0:e294af8d0e07 9 * TODO: write one
igorsk 0:e294af8d0e07 10 * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library
igorsk 0:e294af8d0e07 11 */
suupen 4:dc14f62cb09f 12
igorsk 0:e294af8d0e07 13 #include "MSCFileSystem.h"
igorsk 0:e294af8d0e07 14 #include "usbhost_inc.h"
igorsk 0:e294af8d0e07 15
suupen 4:dc14f62cb09f 16 /*
suupen 4:dc14f62cb09f 17 **************************************************************************************************************
suupen 4:dc14f62cb09f 18 * PRINT CONFIGURATION
suupen 4:dc14f62cb09f 19 **************************************************************************************************************
suupen 4:dc14f62cb09f 20 */
suupen 4:dc14f62cb09f 21 //#define DEBUG
suupen 4:dc14f62cb09f 22 #ifdef DEBUG
suupen 4:dc14f62cb09f 23 #define DEBUG_PRINT(...) printf(__VA_ARGS__)
suupen 4:dc14f62cb09f 24 #else
suupen 4:dc14f62cb09f 25 #define DEBUG_PRINT(...)
suupen 4:dc14f62cb09f 26 #endif // DEBUG
suupen 4:dc14f62cb09f 27
suupen 4:dc14f62cb09f 28
igorsk 0:e294af8d0e07 29 MSCFileSystem::MSCFileSystem(const char* name) :
igorsk 0:e294af8d0e07 30 FATFileSystem(name)
igorsk 0:e294af8d0e07 31 {
igorsk 0:e294af8d0e07 32 }
igorsk 0:e294af8d0e07 33
igorsk 0:e294af8d0e07 34 void print_inquiry(USB_INT08U *inqReply)
igorsk 0:e294af8d0e07 35 {
igorsk 0:e294af8d0e07 36 // see USB Mass Storage Class – UFI Command Specification,
igorsk 0:e294af8d0e07 37 // 4.2 INQUIRY Command
suupen 4:dc14f62cb09f 38 DEBUG_PRINT("Inquiry reply:\n");
igorsk 0:e294af8d0e07 39 uint8_t tmp = inqReply[0]&0x1F;
suupen 4:dc14f62cb09f 40 DEBUG_PRINT("Peripheral device type: %02Xh\n", tmp);
igorsk 0:e294af8d0e07 41 if ( tmp == 0 )
suupen 4:dc14f62cb09f 42 DEBUG_PRINT("\t- Direct access (floppy)\n");
igorsk 0:e294af8d0e07 43 else if ( tmp == 0x1F )
suupen 4:dc14f62cb09f 44 DEBUG_PRINT("\t- none (no FDD connected)\n");
igorsk 0:e294af8d0e07 45 else
suupen 4:dc14f62cb09f 46 DEBUG_PRINT("\t- unknown type\n");
igorsk 0:e294af8d0e07 47 tmp = inqReply[1] >> 7;
suupen 4:dc14f62cb09f 48 DEBUG_PRINT("Removable Media Bit: %d\n", tmp);
igorsk 0:e294af8d0e07 49 tmp = inqReply[2] & 3;
suupen 4:dc14f62cb09f 50 DEBUG_PRINT("ANSI Version: %02Xh\n", tmp);
igorsk 0:e294af8d0e07 51 if ( tmp != 0 )
suupen 4:dc14f62cb09f 52 DEBUG_PRINT("\t- warning! must be 0\n");
igorsk 0:e294af8d0e07 53 tmp = (inqReply[2]>>3) & 3;
suupen 4:dc14f62cb09f 54 DEBUG_PRINT("ECMA Version: %02Xh\n", tmp);
igorsk 0:e294af8d0e07 55 if ( tmp != 0 )
suupen 4:dc14f62cb09f 56 DEBUG_PRINT("\t- warning! should be 0\n");
igorsk 0:e294af8d0e07 57 tmp = inqReply[2]>>6;
suupen 4:dc14f62cb09f 58 DEBUG_PRINT("ISO Version: %02Xh\n", tmp);
igorsk 0:e294af8d0e07 59 if ( tmp != 0 )
suupen 4:dc14f62cb09f 60 DEBUG_PRINT("\t- warning! should be 0\n");
igorsk 0:e294af8d0e07 61 tmp = inqReply[3] & 0xF;
suupen 4:dc14f62cb09f 62 DEBUG_PRINT("Response Data Format: %02Xh\n", tmp);
igorsk 0:e294af8d0e07 63 if ( tmp != 1 )
suupen 4:dc14f62cb09f 64 DEBUG_PRINT("\t- warning! should be 1\n");
igorsk 0:e294af8d0e07 65 tmp = inqReply[4];
suupen 4:dc14f62cb09f 66 DEBUG_PRINT("Additional length: %02Xh\n", tmp);
igorsk 0:e294af8d0e07 67 if ( tmp != 0x1F )
suupen 4:dc14f62cb09f 68 DEBUG_PRINT("\t- warning! should be 1Fh\n");
suupen 4:dc14f62cb09f 69 DEBUG_PRINT("Vendor Information: '%.8s'\n", &inqReply[8]);
suupen 4:dc14f62cb09f 70 DEBUG_PRINT("Product Identification: '%.16s'\n", &inqReply[16]);
suupen 4:dc14f62cb09f 71 DEBUG_PRINT("Product Revision: '%.4s'\n", &inqReply[32]);
igorsk 0:e294af8d0e07 72 }
igorsk 0:e294af8d0e07 73
igorsk 0:e294af8d0e07 74 int MSCFileSystem::initialise_msc()
igorsk 0:e294af8d0e07 75 {
igorsk 0:e294af8d0e07 76 USB_INT32S rc;
igorsk 0:e294af8d0e07 77 USB_INT08U inquiryResult[INQUIRY_LENGTH];
igorsk 0:e294af8d0e07 78
igorsk 0:e294af8d0e07 79 //print_clock();
igorsk 0:e294af8d0e07 80 Host_Init(); /* Initialize the host controller */
igorsk 0:e294af8d0e07 81 rc = Host_EnumDev(); /* Enumerate the device connected */
igorsk 0:e294af8d0e07 82 if (rc != OK)
igorsk 0:e294af8d0e07 83 {
igorsk 0:e294af8d0e07 84 fprintf(stderr, "Could not enumerate device: %d\n", rc);
igorsk 0:e294af8d0e07 85 return rc;
igorsk 0:e294af8d0e07 86 }
igorsk 0:e294af8d0e07 87
igorsk 0:e294af8d0e07 88
igorsk 0:e294af8d0e07 89 /* Initialize the mass storage and scsi interfaces */
igorsk 0:e294af8d0e07 90 rc = MS_Init( &_blkSize, &_numBlks, inquiryResult );
igorsk 0:e294af8d0e07 91 if (rc != OK)
igorsk 0:e294af8d0e07 92 {
igorsk 0:e294af8d0e07 93 fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc);
igorsk 0:e294af8d0e07 94 return rc;
igorsk 0:e294af8d0e07 95 }
suupen 4:dc14f62cb09f 96 DEBUG_PRINT("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize);
igorsk 0:e294af8d0e07 97 print_inquiry(inquiryResult);
igorsk 0:e294af8d0e07 98 // FATFileSystem supports only 512-byte blocks
igorsk 0:e294af8d0e07 99 return _blkSize == 512 ? OK : 1;
igorsk 0:e294af8d0e07 100 }
igorsk 0:e294af8d0e07 101
igorsk 0:e294af8d0e07 102 int MSCFileSystem::disk_initialize()
igorsk 0:e294af8d0e07 103 {
igorsk 0:e294af8d0e07 104 if ( initialise_msc() != OK )
igorsk 0:e294af8d0e07 105 return 1;
igorsk 0:e294af8d0e07 106
igorsk 0:e294af8d0e07 107 return 0;
igorsk 0:e294af8d0e07 108 }
igorsk 0:e294af8d0e07 109
igorsk 0:e294af8d0e07 110 int MSCFileSystem::disk_write(const char *buffer, int block_number)
igorsk 0:e294af8d0e07 111 {
igorsk 0:e294af8d0e07 112 if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) )
igorsk 0:e294af8d0e07 113 return 0;
igorsk 0:e294af8d0e07 114 return 1;
igorsk 0:e294af8d0e07 115 }
igorsk 0:e294af8d0e07 116
igorsk 0:e294af8d0e07 117 int MSCFileSystem::disk_read(char *buffer, int block_number)
igorsk 0:e294af8d0e07 118 {
igorsk 0:e294af8d0e07 119 if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) )
igorsk 0:e294af8d0e07 120 return 0;
igorsk 0:e294af8d0e07 121 return 1;
igorsk 0:e294af8d0e07 122 }
igorsk 0:e294af8d0e07 123
igorsk 0:e294af8d0e07 124 int MSCFileSystem::disk_status() { return 0; }
igorsk 0:e294af8d0e07 125 int MSCFileSystem::disk_sync() { return 0; }
igorsk 0:e294af8d0e07 126 int MSCFileSystem::disk_sectors() { return _numBlks; }