test fork
Dependencies: SPI_TFTx2 SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2 mbed
Fork of CANary_9341 by
CHAN_FS/diskio.c@109:3e6f0e8fca0d, 2013-06-30 (annotated)
- Committer:
- TickTock
- Date:
- Sun Jun 30 17:52:58 2013 +0000
- Branch:
- Metric
- Revision:
- 109:3e6f0e8fca0d
Change filesystem library. Got logging and playback working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TickTock | 109:3e6f0e8fca0d | 1 | /*-----------------------------------------------------------------------*/ |
TickTock | 109:3e6f0e8fca0d | 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ |
TickTock | 109:3e6f0e8fca0d | 3 | /*-----------------------------------------------------------------------*/ |
TickTock | 109:3e6f0e8fca0d | 4 | /* This is a stub disk I/O module that acts as front end of the existing */ |
TickTock | 109:3e6f0e8fca0d | 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ |
TickTock | 109:3e6f0e8fca0d | 6 | /*-----------------------------------------------------------------------*/ |
TickTock | 109:3e6f0e8fca0d | 7 | |
TickTock | 109:3e6f0e8fca0d | 8 | #include "diskio.h" |
TickTock | 109:3e6f0e8fca0d | 9 | #include "usbhost_inc.h" |
TickTock | 109:3e6f0e8fca0d | 10 | #include "mbed.h" |
TickTock | 109:3e6f0e8fca0d | 11 | |
TickTock | 109:3e6f0e8fca0d | 12 | uint32_t _numBlks = 0; |
TickTock | 109:3e6f0e8fca0d | 13 | uint32_t _blkSize = 512; |
TickTock | 109:3e6f0e8fca0d | 14 | |
TickTock | 109:3e6f0e8fca0d | 15 | int initialise_msc(); |
TickTock | 109:3e6f0e8fca0d | 16 | void print_inquiry(USB_INT08U *inqReply); |
TickTock | 109:3e6f0e8fca0d | 17 | |
TickTock | 109:3e6f0e8fca0d | 18 | |
TickTock | 109:3e6f0e8fca0d | 19 | int disk_sync() { return 0; } |
TickTock | 109:3e6f0e8fca0d | 20 | int disk_sectors() { return _numBlks; } |
TickTock | 109:3e6f0e8fca0d | 21 | |
TickTock | 109:3e6f0e8fca0d | 22 | DWORD get_fattime(void) |
TickTock | 109:3e6f0e8fca0d | 23 | { |
TickTock | 109:3e6f0e8fca0d | 24 | time_t CurrentTimeStamp; |
TickTock | 109:3e6f0e8fca0d | 25 | tm *CurrentLocalTime; |
TickTock | 109:3e6f0e8fca0d | 26 | DWORD FATFSTimeCode; |
TickTock | 109:3e6f0e8fca0d | 27 | |
TickTock | 109:3e6f0e8fca0d | 28 | CurrentTimeStamp = time(NULL); |
TickTock | 109:3e6f0e8fca0d | 29 | CurrentLocalTime = localtime(&CurrentTimeStamp); |
TickTock | 109:3e6f0e8fca0d | 30 | |
TickTock | 109:3e6f0e8fca0d | 31 | //Map the tm struct time into the FatFs time code |
TickTock | 109:3e6f0e8fca0d | 32 | FATFSTimeCode = ((CurrentLocalTime->tm_year-80)<<25) | |
TickTock | 109:3e6f0e8fca0d | 33 | ((CurrentLocalTime->tm_mon+1)<<21) | |
TickTock | 109:3e6f0e8fca0d | 34 | ((CurrentLocalTime->tm_mday)<<16) | |
TickTock | 109:3e6f0e8fca0d | 35 | ((CurrentLocalTime->tm_hour)<<11) | |
TickTock | 109:3e6f0e8fca0d | 36 | ((CurrentLocalTime->tm_min)<<5) | |
TickTock | 109:3e6f0e8fca0d | 37 | ((CurrentLocalTime->tm_sec)); |
TickTock | 109:3e6f0e8fca0d | 38 | |
TickTock | 109:3e6f0e8fca0d | 39 | return FATFSTimeCode; |
TickTock | 109:3e6f0e8fca0d | 40 | } |
TickTock | 109:3e6f0e8fca0d | 41 | |
TickTock | 109:3e6f0e8fca0d | 42 | DSTATUS disk_status(BYTE Drive) |
TickTock | 109:3e6f0e8fca0d | 43 | { |
TickTock | 109:3e6f0e8fca0d | 44 | return 0; |
TickTock | 109:3e6f0e8fca0d | 45 | } |
TickTock | 109:3e6f0e8fca0d | 46 | |
TickTock | 109:3e6f0e8fca0d | 47 | |
TickTock | 109:3e6f0e8fca0d | 48 | DRESULT disk_ioctl ( |
TickTock | 109:3e6f0e8fca0d | 49 | BYTE drv, /* Physical drive nmuber (0..) */ |
TickTock | 109:3e6f0e8fca0d | 50 | BYTE ctrl, /* Control code */ |
TickTock | 109:3e6f0e8fca0d | 51 | void *buff /* Buffer to send/receive control data */ |
TickTock | 109:3e6f0e8fca0d | 52 | ) |
TickTock | 109:3e6f0e8fca0d | 53 | { |
TickTock | 109:3e6f0e8fca0d | 54 | DRESULT res; |
TickTock | 109:3e6f0e8fca0d | 55 | |
TickTock | 109:3e6f0e8fca0d | 56 | switch(ctrl) |
TickTock | 109:3e6f0e8fca0d | 57 | { |
TickTock | 109:3e6f0e8fca0d | 58 | case CTRL_SYNC: |
TickTock | 109:3e6f0e8fca0d | 59 | res = RES_OK; |
TickTock | 109:3e6f0e8fca0d | 60 | break; |
TickTock | 109:3e6f0e8fca0d | 61 | |
TickTock | 109:3e6f0e8fca0d | 62 | case GET_SECTOR_SIZE: |
TickTock | 109:3e6f0e8fca0d | 63 | res = RES_OK; |
TickTock | 109:3e6f0e8fca0d | 64 | *(WORD *)buff = 512; |
TickTock | 109:3e6f0e8fca0d | 65 | break; |
TickTock | 109:3e6f0e8fca0d | 66 | |
TickTock | 109:3e6f0e8fca0d | 67 | case GET_SECTOR_COUNT: |
TickTock | 109:3e6f0e8fca0d | 68 | res = RES_OK; |
TickTock | 109:3e6f0e8fca0d | 69 | *(DWORD *)buff = (WORD)disk_sectors(); |
TickTock | 109:3e6f0e8fca0d | 70 | break; |
TickTock | 109:3e6f0e8fca0d | 71 | |
TickTock | 109:3e6f0e8fca0d | 72 | case GET_BLOCK_SIZE: |
TickTock | 109:3e6f0e8fca0d | 73 | res = RES_OK; |
TickTock | 109:3e6f0e8fca0d | 74 | *(DWORD *)buff = 1; |
TickTock | 109:3e6f0e8fca0d | 75 | break; |
TickTock | 109:3e6f0e8fca0d | 76 | |
TickTock | 109:3e6f0e8fca0d | 77 | default: |
TickTock | 109:3e6f0e8fca0d | 78 | res = RES_OK; |
TickTock | 109:3e6f0e8fca0d | 79 | break; |
TickTock | 109:3e6f0e8fca0d | 80 | } |
TickTock | 109:3e6f0e8fca0d | 81 | return res; |
TickTock | 109:3e6f0e8fca0d | 82 | } |
TickTock | 109:3e6f0e8fca0d | 83 | |
TickTock | 109:3e6f0e8fca0d | 84 | DSTATUS disk_initialize(BYTE Drive) { |
TickTock | 109:3e6f0e8fca0d | 85 | |
TickTock | 109:3e6f0e8fca0d | 86 | if ( initialise_msc() != OK ) |
TickTock | 109:3e6f0e8fca0d | 87 | return 1; |
TickTock | 109:3e6f0e8fca0d | 88 | return 0; |
TickTock | 109:3e6f0e8fca0d | 89 | } |
TickTock | 109:3e6f0e8fca0d | 90 | |
TickTock | 109:3e6f0e8fca0d | 91 | DRESULT disk_write(BYTE Drive,const BYTE * Buffer, DWORD SectorNumber, BYTE SectorCount) |
TickTock | 109:3e6f0e8fca0d | 92 | { |
TickTock | 109:3e6f0e8fca0d | 93 | if ( OK == MS_BulkSend(SectorNumber, SectorCount, (USB_INT08U *)Buffer) ) |
TickTock | 109:3e6f0e8fca0d | 94 | return RES_OK; |
TickTock | 109:3e6f0e8fca0d | 95 | return RES_ERROR; |
TickTock | 109:3e6f0e8fca0d | 96 | } |
TickTock | 109:3e6f0e8fca0d | 97 | |
TickTock | 109:3e6f0e8fca0d | 98 | DRESULT disk_read(BYTE Drive, BYTE * Buffer,DWORD SectorNumber, BYTE SectorCount) |
TickTock | 109:3e6f0e8fca0d | 99 | { |
TickTock | 109:3e6f0e8fca0d | 100 | if ( OK == MS_BulkRecv(SectorNumber, SectorCount, (USB_INT08U *)Buffer) ) |
TickTock | 109:3e6f0e8fca0d | 101 | return RES_OK; |
TickTock | 109:3e6f0e8fca0d | 102 | return RES_ERROR; |
TickTock | 109:3e6f0e8fca0d | 103 | } |
TickTock | 109:3e6f0e8fca0d | 104 | |
TickTock | 109:3e6f0e8fca0d | 105 | |
TickTock | 109:3e6f0e8fca0d | 106 | |
TickTock | 109:3e6f0e8fca0d | 107 | |
TickTock | 109:3e6f0e8fca0d | 108 | |
TickTock | 109:3e6f0e8fca0d | 109 | void print_inquiry(USB_INT08U *inqReply) |
TickTock | 109:3e6f0e8fca0d | 110 | { |
TickTock | 109:3e6f0e8fca0d | 111 | // see USB Mass Storage Class � UFI Command Specification, |
TickTock | 109:3e6f0e8fca0d | 112 | // 4.2 INQUIRY Command |
TickTock | 109:3e6f0e8fca0d | 113 | printf("Inquiry reply:\n"); |
TickTock | 109:3e6f0e8fca0d | 114 | uint8_t tmp = inqReply[0]&0x1F; |
TickTock | 109:3e6f0e8fca0d | 115 | printf("Peripheral device type: %02Xh\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 116 | if ( tmp == 0 ) |
TickTock | 109:3e6f0e8fca0d | 117 | printf("\t- Direct access (floppy)\n"); |
TickTock | 109:3e6f0e8fca0d | 118 | else if ( tmp == 0x1F ) |
TickTock | 109:3e6f0e8fca0d | 119 | printf("\t- none (no FDD connected)\n"); |
TickTock | 109:3e6f0e8fca0d | 120 | else |
TickTock | 109:3e6f0e8fca0d | 121 | printf("\t- unknown type\n"); |
TickTock | 109:3e6f0e8fca0d | 122 | tmp = inqReply[1] >> 7; |
TickTock | 109:3e6f0e8fca0d | 123 | printf("Removable Media Bit: %d\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 124 | tmp = inqReply[2] & 3; |
TickTock | 109:3e6f0e8fca0d | 125 | printf("ANSI Version: %02Xh\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 126 | if ( tmp != 0 ) |
TickTock | 109:3e6f0e8fca0d | 127 | printf("\t- warning! must be 0\n"); |
TickTock | 109:3e6f0e8fca0d | 128 | tmp = (inqReply[2]>>3) & 3; |
TickTock | 109:3e6f0e8fca0d | 129 | printf("ECMA Version: %02Xh\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 130 | if ( tmp != 0 ) |
TickTock | 109:3e6f0e8fca0d | 131 | printf("\t- warning! should be 0\n"); |
TickTock | 109:3e6f0e8fca0d | 132 | tmp = inqReply[2]>>6; |
TickTock | 109:3e6f0e8fca0d | 133 | printf("ISO Version: %02Xh\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 134 | if ( tmp != 0 ) |
TickTock | 109:3e6f0e8fca0d | 135 | printf("\t- warning! should be 0\n"); |
TickTock | 109:3e6f0e8fca0d | 136 | tmp = inqReply[3] & 0xF; |
TickTock | 109:3e6f0e8fca0d | 137 | printf("Response Data Format: %02Xh\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 138 | if ( tmp != 1 ) |
TickTock | 109:3e6f0e8fca0d | 139 | printf("\t- warning! should be 1\n"); |
TickTock | 109:3e6f0e8fca0d | 140 | tmp = inqReply[4]; |
TickTock | 109:3e6f0e8fca0d | 141 | printf("Additional length: %02Xh\n", tmp); |
TickTock | 109:3e6f0e8fca0d | 142 | if ( tmp != 0x1F ) |
TickTock | 109:3e6f0e8fca0d | 143 | printf("\t- warning! should be 1Fh\n"); |
TickTock | 109:3e6f0e8fca0d | 144 | printf("Vendor Information: '%.8s'\n", &inqReply[8]); |
TickTock | 109:3e6f0e8fca0d | 145 | printf("Product Identification: '%.16s'\n", &inqReply[16]); |
TickTock | 109:3e6f0e8fca0d | 146 | printf("Product Revision: '%.4s'\n", &inqReply[32]); |
TickTock | 109:3e6f0e8fca0d | 147 | } |
TickTock | 109:3e6f0e8fca0d | 148 | |
TickTock | 109:3e6f0e8fca0d | 149 | |
TickTock | 109:3e6f0e8fca0d | 150 | |
TickTock | 109:3e6f0e8fca0d | 151 | int initialise_msc() |
TickTock | 109:3e6f0e8fca0d | 152 | { |
TickTock | 109:3e6f0e8fca0d | 153 | USB_INT32S rc; |
TickTock | 109:3e6f0e8fca0d | 154 | USB_INT08U inquiryResult[INQUIRY_LENGTH]; |
TickTock | 109:3e6f0e8fca0d | 155 | |
TickTock | 109:3e6f0e8fca0d | 156 | //print_clock(); |
TickTock | 109:3e6f0e8fca0d | 157 | Host_Init(); /* Initialize the host controller */ |
TickTock | 109:3e6f0e8fca0d | 158 | rc = Host_EnumDev(); /* Enumerate the device connected */ |
TickTock | 109:3e6f0e8fca0d | 159 | if (rc != OK) |
TickTock | 109:3e6f0e8fca0d | 160 | { |
TickTock | 109:3e6f0e8fca0d | 161 | fprintf(stderr, "Could not enumerate device: %d\n", rc); |
TickTock | 109:3e6f0e8fca0d | 162 | return rc; |
TickTock | 109:3e6f0e8fca0d | 163 | } |
TickTock | 109:3e6f0e8fca0d | 164 | |
TickTock | 109:3e6f0e8fca0d | 165 | |
TickTock | 109:3e6f0e8fca0d | 166 | /* Initialize the mass storage and scsi interfaces */ |
TickTock | 109:3e6f0e8fca0d | 167 | rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); |
TickTock | 109:3e6f0e8fca0d | 168 | if (rc != OK) |
TickTock | 109:3e6f0e8fca0d | 169 | { |
TickTock | 109:3e6f0e8fca0d | 170 | fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); |
TickTock | 109:3e6f0e8fca0d | 171 | return rc; |
TickTock | 109:3e6f0e8fca0d | 172 | } |
TickTock | 109:3e6f0e8fca0d | 173 | printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); |
TickTock | 109:3e6f0e8fca0d | 174 | print_inquiry(inquiryResult); |
TickTock | 109:3e6f0e8fca0d | 175 | // FATFileSystem supports only 512-byte blocks |
TickTock | 109:3e6f0e8fca0d | 176 | return _blkSize == 512 ? OK : 1; |
TickTock | 109:3e6f0e8fca0d | 177 | } |
TickTock | 109:3e6f0e8fca0d | 178 | |
TickTock | 109:3e6f0e8fca0d | 179 | |
TickTock | 109:3e6f0e8fca0d | 180 |