mbed Dev board test program

Dependencies:   EthernetNetIf mbed HTTPServer SerialLCD

Committer:
pangsk
Date:
Mon Jul 11 15:02:04 2011 +0000
Revision:
0:0f36b9fac4c5

        

Who changed what in which revision?

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