Dependencies:   mbed

Committer:
lynxeyed_atsu
Date:
Fri Jan 21 08:39:48 2011 +0000
Revision:
0:63ed631d8c3a

        

Who changed what in which revision?

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