This package contains a simple test of tests for various elements of the SmartBoard hardware, which is a simple baseboard designed for easy embedding. It is able to run both a semi-automatic test suite as well as allow interactive testing.

Dependencies:   EthernetNetIf NTPClient_NetServices mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MSCFileSystem.cpp Source File

MSCFileSystem.cpp

00001 /* USB Mass Storage device file system
00002  * Copyrigh (c) 2010, Igor Skochinsky
00003  * based on SDFileStorage
00004  * Copyright (c) 2008-2009, sford
00005  * 
00006  * Added DEBUG_X to eliminate annoying print statements
00007  * Copyright (c) 2011, David Smart
00008  */
00009  
00010 /* Introduction
00011  * ------------
00012  * TODO: write one
00013  * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library
00014  */
00015  
00016 #include "MSCFileSystem.h"
00017 #include "usbhost_inc.h"
00018 
00019 // Define this to print details
00020 //#define DEBUG_X
00021 
00022 
00023 MSCFileSystem::MSCFileSystem(const char* name) :
00024   FATFileSystem(name)
00025 {
00026 }
00027 
00028 void print_inquiry(USB_INT08U *inqReply)
00029 {
00030     // see USB Mass Storage Class � UFI Command Specification,
00031     // 4.2 INQUIRY Command
00032     printf("Inquiry reply:\n");
00033     uint8_t tmp = inqReply[0]&0x1F;
00034     printf("Peripheral device type: %02Xh\n", tmp);
00035     if ( tmp == 0 )
00036         printf("\t- Direct access (floppy)\n");
00037     else if ( tmp == 0x1F )
00038         printf("\t- none (no FDD connected)\n");
00039     else
00040         printf("\t- unknown type\n");
00041     tmp = inqReply[1] >> 7;
00042     printf("Removable Media Bit: %d\n", tmp);
00043     tmp = inqReply[2] & 3;
00044     printf("ANSI Version: %02Xh\n", tmp);
00045     if ( tmp != 0 )
00046         printf("\t- warning! must be 0\n");
00047     tmp = (inqReply[2]>>3) & 3;
00048     printf("ECMA Version: %02Xh\n", tmp);
00049     if ( tmp != 0 )
00050         printf("\t- warning! should be 0\n");
00051     tmp = inqReply[2]>>6;
00052     printf("ISO Version: %02Xh\n", tmp);
00053     if ( tmp != 0 )
00054         printf("\t- warning! should be 0\n");
00055     tmp = inqReply[3] & 0xF;
00056     printf("Response Data Format: %02Xh\n", tmp);
00057     if ( tmp != 1 )
00058         printf("\t- warning! should be 1\n");
00059     tmp = inqReply[4];
00060     printf("Additional length: %02Xh\n", tmp);
00061     if ( tmp != 0x1F )
00062         printf("\t- warning! should be 1Fh\n");
00063     printf("Vendor Information: '%.8s'\n", &inqReply[8]);
00064     printf("Product Identification: '%.16s'\n", &inqReply[16]);
00065     printf("Product Revision: '%.4s'\n", &inqReply[32]);        
00066 }
00067 
00068 int MSCFileSystem::initialise_msc()
00069 {
00070     USB_INT32S  rc;
00071     USB_INT08U  inquiryResult[INQUIRY_LENGTH];
00072     
00073     //print_clock();
00074     Host_Init();               /* Initialize the  host controller                                    */
00075     rc = Host_EnumDev();       /* Enumerate the device connected                                            */
00076     if (rc != OK)
00077     {
00078         fprintf(stderr, "Could not enumerate device: %d\n", rc);
00079         return rc;
00080     }
00081         
00082     
00083     /* Initialize the mass storage and scsi interfaces */
00084     rc = MS_Init( &_blkSize, &_numBlks, inquiryResult );
00085     if (rc != OK)
00086     {
00087         fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc);
00088         return rc;
00089     }
00090     #ifdef DEBUG_X
00091         printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize);
00092         print_inquiry(inquiryResult);
00093     #endif
00094     // FATFileSystem supports only 512-byte blocks
00095     return _blkSize == 512 ? OK : 1;
00096 }
00097 
00098 int MSCFileSystem::disk_initialize()
00099 {
00100     if ( initialise_msc() != OK )
00101         return 1;
00102         
00103     return 0;
00104 }
00105 
00106 int MSCFileSystem::disk_write(const char *buffer, int block_number)
00107 {
00108     if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) )
00109         return 0;
00110     return 1;
00111 }
00112 
00113 int MSCFileSystem::disk_read(char *buffer, int block_number)
00114 {
00115     if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) )
00116         return 0;
00117     return 1;
00118 }
00119 
00120 int MSCFileSystem::disk_status() { return 0; }
00121 int MSCFileSystem::disk_sync() { return 0; }
00122 int MSCFileSystem::disk_sectors() { return _numBlks; }