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