dd

Dependencies:   C12832 LM75B mbed

Committer:
pfe
Date:
Tue Apr 21 10:16:20 2015 +0000
Revision:
0:05a20e3e3179
dd

Who changed what in which revision?

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