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