Code for Silica

Committer:
chris
Date:
Tue Apr 06 14:09:54 2010 +0000
Revision:
0:28e93e0b9f05

        

Who changed what in which revision?

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