Chris Styles
/
USB-A
Example program using USB A
Embed:
(wiki syntax)
Show/hide line numbers
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 00007 /* Introduction 00008 * ------------ 00009 * TODO: write one 00010 * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library 00011 */ 00012 00013 #include "MSCFileSystem.h" 00014 #include "usbhost_inc.h" 00015 00016 MSCFileSystem::MSCFileSystem(const char* name) : 00017 FATFileSystem(name) 00018 { 00019 } 00020 00021 void print_inquiry(USB_INT08U *inqReply) 00022 { 00023 // see USB Mass Storage Class – UFI Command Specification, 00024 // 4.2 INQUIRY Command 00025 printf("Inquiry reply:\n"); 00026 uint8_t tmp = inqReply[0]&0x1F; 00027 printf("Peripheral device type: %02Xh\n", tmp); 00028 if ( tmp == 0 ) 00029 printf("\t- Direct access (floppy)\n"); 00030 else if ( tmp == 0x1F ) 00031 printf("\t- none (no FDD connected)\n"); 00032 else 00033 printf("\t- unknown type\n"); 00034 tmp = inqReply[1] >> 7; 00035 printf("Removable Media Bit: %d\n", tmp); 00036 tmp = inqReply[2] & 3; 00037 printf("ANSI Version: %02Xh\n", tmp); 00038 if ( tmp != 0 ) 00039 printf("\t- warning! must be 0\n"); 00040 tmp = (inqReply[2]>>3) & 3; 00041 printf("ECMA Version: %02Xh\n", tmp); 00042 if ( tmp != 0 ) 00043 printf("\t- warning! should be 0\n"); 00044 tmp = inqReply[2]>>6; 00045 printf("ISO Version: %02Xh\n", tmp); 00046 if ( tmp != 0 ) 00047 printf("\t- warning! should be 0\n"); 00048 tmp = inqReply[3] & 0xF; 00049 printf("Response Data Format: %02Xh\n", tmp); 00050 if ( tmp != 1 ) 00051 printf("\t- warning! should be 1\n"); 00052 tmp = inqReply[4]; 00053 printf("Additional length: %02Xh\n", tmp); 00054 if ( tmp != 0x1F ) 00055 printf("\t- warning! should be 1Fh\n"); 00056 printf("Vendor Information: '%.8s'\n", &inqReply[8]); 00057 printf("Product Identification: '%.16s'\n", &inqReply[16]); 00058 printf("Product Revision: '%.4s'\n", &inqReply[32]); 00059 } 00060 00061 int MSCFileSystem::initialise_msc() 00062 { 00063 USB_INT32S rc; 00064 USB_INT08U inquiryResult[INQUIRY_LENGTH]; 00065 00066 //print_clock(); 00067 Host_Init(); /* Initialize the host controller */ 00068 rc = Host_EnumDev(); /* Enumerate the device connected */ 00069 if (rc != OK) 00070 { 00071 fprintf(stderr, "Could not enumerate device: %d\n", rc); 00072 return rc; 00073 } 00074 00075 00076 /* Initialize the mass storage and scsi interfaces */ 00077 rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); 00078 if (rc != OK) 00079 { 00080 fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); 00081 return rc; 00082 } 00083 printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); 00084 print_inquiry(inquiryResult); 00085 // FATFileSystem supports only 512-byte blocks 00086 return _blkSize == 512 ? OK : 1; 00087 } 00088 00089 int MSCFileSystem::disk_initialize() 00090 { 00091 if ( initialise_msc() != OK ) 00092 return 1; 00093 00094 return 0; 00095 } 00096 00097 int MSCFileSystem::disk_write(const char *buffer, int block_number) 00098 { 00099 if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) ) 00100 return 0; 00101 return 1; 00102 } 00103 00104 int MSCFileSystem::disk_read(char *buffer, int block_number) 00105 { 00106 if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) ) 00107 return 0; 00108 return 1; 00109 } 00110 00111 int MSCFileSystem::disk_status() { return 0; } 00112 int MSCFileSystem::disk_sync() { return 0; } 00113 int MSCFileSystem::disk_sectors() { return _numBlks; }
Generated on Thu Jul 14 2022 15:51:46 by 1.7.2