V

Dependencies:   mbed FatFileSystemCpp TextLCD

Committer:
bertonieto
Date:
Mon Aug 12 21:54:14 2019 +0000
Revision:
2:73cbcff90232
Export new

Who changed what in which revision?

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