Dependents:   sample_collection_for_starboard_orange starboard_orange_samples

Committer:
chris
Date:
Wed May 19 06:31:49 2010 +0000
Revision:
0:f4e330489777

        

Who changed what in which revision?

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