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