Drone code for Prof. Coode

Dependencies:   C12832_lcd FatFileSystemCpp MMA7660 mbed

Fork of app-board-Bubble-Level by jim hamblen

Committer:
ecleland
Date:
Thu Sep 10 18:22:29 2015 +0000
Revision:
3:6dae4f871cdc
Drone Code for Prof. Cooke

Who changed what in which revision?

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