Code to take GPS, Accelerometer and Compass readings and print to USB for data analysis.

Dependencies:   CMPS03 FatFileSystemCpp GPS MMA7660 mbed C12832_lcd

Committer:
Alex4475
Date:
Wed May 07 09:49:54 2014 +0000
Revision:
0:2557081b4322
Code to take GPS, Accelerometer and Compass data and print to a USB for data analysis

Who changed what in which revision?

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