This is a lib to use ChaNFS lib with USB mass storages like USB Sticks .. Long file names work

Dependencies:  

Dependents:   WeatherStation

Committer:
NeoBelerophon
Date:
Tue Feb 01 22:14:30 2011 +0000
Revision:
0:f0133ccac168
Initial commit

Who changed what in which revision?

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