Sertel USB Log

Fork of MSCFileSystem by Chris Styles

Committer:
mrsoundhar
Date:
Sun Jun 12 16:44:44 2016 +0000
Revision:
8:cccdf653258b
Parent:
0:3e7d2baed4b4
Soundharrajan USB Log for Drive

Who changed what in which revision?

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