![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This package contains a simple test of tests for various elements of the SmartBoard hardware, which is a simple baseboard designed for easy embedding. It is able to run both a semi-automatic test suite as well as allow interactive testing.
Dependencies: EthernetNetIf NTPClient_NetServices mbed
This program is most of what you need to test your SmartBoard baseboard hardware. It provides a means to test the following:
- Two channels of CAN (with a loopback cable)
- RS-232 Ports
- Analog inputs
- PWM outputs
- Ethernet port
- Real time clock
- micro SD
- USB Host port
MSCFileSystem.cpp@5:42b456ce6f71, 2011-04-04 (annotated)
- Committer:
- WiredHome
- Date:
- Mon Apr 04 11:33:23 2011 +0000
- Revision:
- 5:42b456ce6f71
- Parent:
- 4:ca93a8d4874d
Several minor updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 4:ca93a8d4874d | 1 | /* USB Mass Storage device file system |
WiredHome | 4:ca93a8d4874d | 2 | * Copyrigh (c) 2010, Igor Skochinsky |
WiredHome | 4:ca93a8d4874d | 3 | * based on SDFileStorage |
WiredHome | 4:ca93a8d4874d | 4 | * Copyright (c) 2008-2009, sford |
WiredHome | 4:ca93a8d4874d | 5 | * |
WiredHome | 4:ca93a8d4874d | 6 | * Added DEBUG_X to eliminate annoying print statements |
WiredHome | 4:ca93a8d4874d | 7 | * Copyright (c) 2011, David Smart |
WiredHome | 4:ca93a8d4874d | 8 | */ |
WiredHome | 4:ca93a8d4874d | 9 | |
WiredHome | 4:ca93a8d4874d | 10 | /* Introduction |
WiredHome | 4:ca93a8d4874d | 11 | * ------------ |
WiredHome | 4:ca93a8d4874d | 12 | * TODO: write one |
WiredHome | 4:ca93a8d4874d | 13 | * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library |
WiredHome | 4:ca93a8d4874d | 14 | */ |
WiredHome | 4:ca93a8d4874d | 15 | |
WiredHome | 4:ca93a8d4874d | 16 | #include "MSCFileSystem.h" |
WiredHome | 4:ca93a8d4874d | 17 | #include "usbhost_inc.h" |
WiredHome | 4:ca93a8d4874d | 18 | |
WiredHome | 4:ca93a8d4874d | 19 | // Define this to print details |
WiredHome | 4:ca93a8d4874d | 20 | //#define DEBUG_X |
WiredHome | 4:ca93a8d4874d | 21 | |
WiredHome | 4:ca93a8d4874d | 22 | |
WiredHome | 4:ca93a8d4874d | 23 | MSCFileSystem::MSCFileSystem(const char* name) : |
WiredHome | 4:ca93a8d4874d | 24 | FATFileSystem(name) |
WiredHome | 4:ca93a8d4874d | 25 | { |
WiredHome | 4:ca93a8d4874d | 26 | } |
WiredHome | 4:ca93a8d4874d | 27 | |
WiredHome | 4:ca93a8d4874d | 28 | void print_inquiry(USB_INT08U *inqReply) |
WiredHome | 4:ca93a8d4874d | 29 | { |
WiredHome | 4:ca93a8d4874d | 30 | // see USB Mass Storage Class � UFI Command Specification, |
WiredHome | 4:ca93a8d4874d | 31 | // 4.2 INQUIRY Command |
WiredHome | 4:ca93a8d4874d | 32 | printf("Inquiry reply:\n"); |
WiredHome | 4:ca93a8d4874d | 33 | uint8_t tmp = inqReply[0]&0x1F; |
WiredHome | 4:ca93a8d4874d | 34 | printf("Peripheral device type: %02Xh\n", tmp); |
WiredHome | 4:ca93a8d4874d | 35 | if ( tmp == 0 ) |
WiredHome | 4:ca93a8d4874d | 36 | printf("\t- Direct access (floppy)\n"); |
WiredHome | 4:ca93a8d4874d | 37 | else if ( tmp == 0x1F ) |
WiredHome | 4:ca93a8d4874d | 38 | printf("\t- none (no FDD connected)\n"); |
WiredHome | 4:ca93a8d4874d | 39 | else |
WiredHome | 4:ca93a8d4874d | 40 | printf("\t- unknown type\n"); |
WiredHome | 4:ca93a8d4874d | 41 | tmp = inqReply[1] >> 7; |
WiredHome | 4:ca93a8d4874d | 42 | printf("Removable Media Bit: %d\n", tmp); |
WiredHome | 4:ca93a8d4874d | 43 | tmp = inqReply[2] & 3; |
WiredHome | 4:ca93a8d4874d | 44 | printf("ANSI Version: %02Xh\n", tmp); |
WiredHome | 4:ca93a8d4874d | 45 | if ( tmp != 0 ) |
WiredHome | 4:ca93a8d4874d | 46 | printf("\t- warning! must be 0\n"); |
WiredHome | 4:ca93a8d4874d | 47 | tmp = (inqReply[2]>>3) & 3; |
WiredHome | 4:ca93a8d4874d | 48 | printf("ECMA Version: %02Xh\n", tmp); |
WiredHome | 4:ca93a8d4874d | 49 | if ( tmp != 0 ) |
WiredHome | 4:ca93a8d4874d | 50 | printf("\t- warning! should be 0\n"); |
WiredHome | 4:ca93a8d4874d | 51 | tmp = inqReply[2]>>6; |
WiredHome | 4:ca93a8d4874d | 52 | printf("ISO Version: %02Xh\n", tmp); |
WiredHome | 4:ca93a8d4874d | 53 | if ( tmp != 0 ) |
WiredHome | 4:ca93a8d4874d | 54 | printf("\t- warning! should be 0\n"); |
WiredHome | 4:ca93a8d4874d | 55 | tmp = inqReply[3] & 0xF; |
WiredHome | 4:ca93a8d4874d | 56 | printf("Response Data Format: %02Xh\n", tmp); |
WiredHome | 4:ca93a8d4874d | 57 | if ( tmp != 1 ) |
WiredHome | 4:ca93a8d4874d | 58 | printf("\t- warning! should be 1\n"); |
WiredHome | 4:ca93a8d4874d | 59 | tmp = inqReply[4]; |
WiredHome | 4:ca93a8d4874d | 60 | printf("Additional length: %02Xh\n", tmp); |
WiredHome | 4:ca93a8d4874d | 61 | if ( tmp != 0x1F ) |
WiredHome | 4:ca93a8d4874d | 62 | printf("\t- warning! should be 1Fh\n"); |
WiredHome | 4:ca93a8d4874d | 63 | printf("Vendor Information: '%.8s'\n", &inqReply[8]); |
WiredHome | 4:ca93a8d4874d | 64 | printf("Product Identification: '%.16s'\n", &inqReply[16]); |
WiredHome | 4:ca93a8d4874d | 65 | printf("Product Revision: '%.4s'\n", &inqReply[32]); |
WiredHome | 4:ca93a8d4874d | 66 | } |
WiredHome | 4:ca93a8d4874d | 67 | |
WiredHome | 4:ca93a8d4874d | 68 | int MSCFileSystem::initialise_msc() |
WiredHome | 4:ca93a8d4874d | 69 | { |
WiredHome | 4:ca93a8d4874d | 70 | USB_INT32S rc; |
WiredHome | 4:ca93a8d4874d | 71 | USB_INT08U inquiryResult[INQUIRY_LENGTH]; |
WiredHome | 4:ca93a8d4874d | 72 | |
WiredHome | 4:ca93a8d4874d | 73 | //print_clock(); |
WiredHome | 4:ca93a8d4874d | 74 | Host_Init(); /* Initialize the host controller */ |
WiredHome | 4:ca93a8d4874d | 75 | rc = Host_EnumDev(); /* Enumerate the device connected */ |
WiredHome | 4:ca93a8d4874d | 76 | if (rc != OK) |
WiredHome | 4:ca93a8d4874d | 77 | { |
WiredHome | 4:ca93a8d4874d | 78 | fprintf(stderr, "Could not enumerate device: %d\n", rc); |
WiredHome | 4:ca93a8d4874d | 79 | return rc; |
WiredHome | 4:ca93a8d4874d | 80 | } |
WiredHome | 4:ca93a8d4874d | 81 | |
WiredHome | 4:ca93a8d4874d | 82 | |
WiredHome | 4:ca93a8d4874d | 83 | /* Initialize the mass storage and scsi interfaces */ |
WiredHome | 4:ca93a8d4874d | 84 | rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); |
WiredHome | 4:ca93a8d4874d | 85 | if (rc != OK) |
WiredHome | 4:ca93a8d4874d | 86 | { |
WiredHome | 4:ca93a8d4874d | 87 | fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); |
WiredHome | 4:ca93a8d4874d | 88 | return rc; |
WiredHome | 4:ca93a8d4874d | 89 | } |
WiredHome | 4:ca93a8d4874d | 90 | #ifdef DEBUG_X |
WiredHome | 4:ca93a8d4874d | 91 | printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); |
WiredHome | 4:ca93a8d4874d | 92 | print_inquiry(inquiryResult); |
WiredHome | 4:ca93a8d4874d | 93 | #endif |
WiredHome | 4:ca93a8d4874d | 94 | // FATFileSystem supports only 512-byte blocks |
WiredHome | 4:ca93a8d4874d | 95 | return _blkSize == 512 ? OK : 1; |
WiredHome | 4:ca93a8d4874d | 96 | } |
WiredHome | 4:ca93a8d4874d | 97 | |
WiredHome | 4:ca93a8d4874d | 98 | int MSCFileSystem::disk_initialize() |
WiredHome | 4:ca93a8d4874d | 99 | { |
WiredHome | 4:ca93a8d4874d | 100 | if ( initialise_msc() != OK ) |
WiredHome | 4:ca93a8d4874d | 101 | return 1; |
WiredHome | 4:ca93a8d4874d | 102 | |
WiredHome | 4:ca93a8d4874d | 103 | return 0; |
WiredHome | 4:ca93a8d4874d | 104 | } |
WiredHome | 4:ca93a8d4874d | 105 | |
WiredHome | 4:ca93a8d4874d | 106 | int MSCFileSystem::disk_write(const char *buffer, int block_number) |
WiredHome | 4:ca93a8d4874d | 107 | { |
WiredHome | 4:ca93a8d4874d | 108 | if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) ) |
WiredHome | 4:ca93a8d4874d | 109 | return 0; |
WiredHome | 4:ca93a8d4874d | 110 | return 1; |
WiredHome | 4:ca93a8d4874d | 111 | } |
WiredHome | 4:ca93a8d4874d | 112 | |
WiredHome | 4:ca93a8d4874d | 113 | int MSCFileSystem::disk_read(char *buffer, int block_number) |
WiredHome | 4:ca93a8d4874d | 114 | { |
WiredHome | 4:ca93a8d4874d | 115 | if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) ) |
WiredHome | 4:ca93a8d4874d | 116 | return 0; |
WiredHome | 4:ca93a8d4874d | 117 | return 1; |
WiredHome | 4:ca93a8d4874d | 118 | } |
WiredHome | 4:ca93a8d4874d | 119 | |
WiredHome | 4:ca93a8d4874d | 120 | int MSCFileSystem::disk_status() { return 0; } |
WiredHome | 4:ca93a8d4874d | 121 | int MSCFileSystem::disk_sync() { return 0; } |
WiredHome | 4:ca93a8d4874d | 122 | int MSCFileSystem::disk_sectors() { return _numBlks; } |