Wiljan Arias / WhexReefMonitor

Dependencies:   mbed-rtos EthernetInterface FatFileSystemCpp MCP23S17 SDFileSystem mbed

Fork of HTTPServerHelloWorld by Donatien Garnier

Committer:
wyunreal
Date:
Sat Feb 08 17:33:41 2014 +0000
Revision:
7:1fe91b525d9a
Parent:
6:b2c4687b421d
add watchdog timer support

Who changed what in which revision?

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