Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
diskio.c
00001 /*-----------------------------------------------------------------------*/ 00002 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ 00003 /*-----------------------------------------------------------------------*/ 00004 /* This is a stub disk I/O module that acts as front end of the existing */ 00005 /* disk I/O modules and attach it to FatFs module with common interface. */ 00006 /*-----------------------------------------------------------------------*/ 00007 00008 #include "diskio.h" 00009 #include "usbhost_inc.h" 00010 #include "mbed.h" 00011 00012 uint32_t _numBlks = 0; 00013 uint32_t _blkSize = 512; 00014 00015 int initialise_msc(); 00016 void print_inquiry(USB_INT08U *inqReply); 00017 00018 00019 int disk_sync() { return 0; } 00020 int disk_sectors() { return _numBlks; } 00021 00022 DWORD get_fattime(void) 00023 { 00024 time_t CurrentTimeStamp; 00025 tm *CurrentLocalTime; 00026 DWORD FATFSTimeCode; 00027 00028 CurrentTimeStamp = time(NULL); 00029 CurrentLocalTime = localtime(&CurrentTimeStamp); 00030 00031 //Map the tm struct time into the FatFs time code 00032 FATFSTimeCode = ((CurrentLocalTime->tm_year-80)<<25) | 00033 ((CurrentLocalTime->tm_mon+1)<<21) | 00034 ((CurrentLocalTime->tm_mday)<<16) | 00035 ((CurrentLocalTime->tm_hour)<<11) | 00036 ((CurrentLocalTime->tm_min)<<5) | 00037 ((CurrentLocalTime->tm_sec)); 00038 00039 return FATFSTimeCode; 00040 } 00041 00042 DSTATUS disk_status(BYTE Drive) 00043 { 00044 return 0; 00045 } 00046 00047 00048 DRESULT disk_ioctl ( 00049 BYTE drv, /* Physical drive nmuber (0..) */ 00050 BYTE ctrl, /* Control code */ 00051 void *buff /* Buffer to send/receive control data */ 00052 ) 00053 { 00054 DRESULT res; 00055 00056 switch(ctrl) 00057 { 00058 case CTRL_SYNC: 00059 res = RES_OK; 00060 break; 00061 00062 case GET_SECTOR_SIZE: 00063 res = RES_OK; 00064 *(WORD *)buff = 512; 00065 break; 00066 00067 case GET_SECTOR_COUNT: 00068 res = RES_OK; 00069 *(DWORD *)buff = (WORD)disk_sectors(); 00070 break; 00071 00072 case GET_BLOCK_SIZE: 00073 res = RES_OK; 00074 *(DWORD *)buff = 1; 00075 break; 00076 00077 default: 00078 res = RES_OK; 00079 break; 00080 } 00081 return res; 00082 } 00083 00084 DSTATUS disk_initialize(BYTE Drive) { 00085 00086 if ( initialise_msc() != OK ) 00087 return 1; 00088 return 0; 00089 } 00090 00091 DRESULT disk_write(BYTE Drive,const BYTE * Buffer, DWORD SectorNumber, BYTE SectorCount) 00092 { 00093 if ( OK == MS_BulkSend(SectorNumber, SectorCount, (USB_INT08U *)Buffer) ) 00094 return RES_OK; 00095 return RES_ERROR; 00096 } 00097 00098 DRESULT disk_read(BYTE Drive, BYTE * Buffer,DWORD SectorNumber, BYTE SectorCount) 00099 { 00100 if ( OK == MS_BulkRecv(SectorNumber, SectorCount, (USB_INT08U *)Buffer) ) 00101 return RES_OK; 00102 return RES_ERROR; 00103 } 00104 00105 00106 00107 00108 00109 void print_inquiry(USB_INT08U *inqReply) 00110 { 00111 // see USB Mass Storage Class � UFI Command Specification, 00112 // 4.2 INQUIRY Command 00113 printf("Inquiry reply:\n"); 00114 uint8_t tmp = inqReply[0]&0x1F; 00115 printf("Peripheral device type: %02Xh\n", tmp); 00116 if ( tmp == 0 ) 00117 printf("\t- Direct access (floppy)\n"); 00118 else if ( tmp == 0x1F ) 00119 printf("\t- none (no FDD connected)\n"); 00120 else 00121 printf("\t- unknown type\n"); 00122 tmp = inqReply[1] >> 7; 00123 printf("Removable Media Bit: %d\n", tmp); 00124 tmp = inqReply[2] & 3; 00125 printf("ANSI Version: %02Xh\n", tmp); 00126 if ( tmp != 0 ) 00127 printf("\t- warning! must be 0\n"); 00128 tmp = (inqReply[2]>>3) & 3; 00129 printf("ECMA Version: %02Xh\n", tmp); 00130 if ( tmp != 0 ) 00131 printf("\t- warning! should be 0\n"); 00132 tmp = inqReply[2]>>6; 00133 printf("ISO Version: %02Xh\n", tmp); 00134 if ( tmp != 0 ) 00135 printf("\t- warning! should be 0\n"); 00136 tmp = inqReply[3] & 0xF; 00137 printf("Response Data Format: %02Xh\n", tmp); 00138 if ( tmp != 1 ) 00139 printf("\t- warning! should be 1\n"); 00140 tmp = inqReply[4]; 00141 printf("Additional length: %02Xh\n", tmp); 00142 if ( tmp != 0x1F ) 00143 printf("\t- warning! should be 1Fh\n"); 00144 printf("Vendor Information: '%.8s'\n", &inqReply[8]); 00145 printf("Product Identification: '%.16s'\n", &inqReply[16]); 00146 printf("Product Revision: '%.4s'\n", &inqReply[32]); 00147 } 00148 00149 00150 00151 int initialise_msc() 00152 { 00153 USB_INT32S rc; 00154 USB_INT08U inquiryResult[INQUIRY_LENGTH]; 00155 00156 //print_clock(); 00157 Host_Init(); /* Initialize the host controller */ 00158 rc = Host_EnumDev(); /* Enumerate the device connected */ 00159 if (rc != OK) 00160 { 00161 fprintf(stderr, "Could not enumerate device: %d\n", rc); 00162 return rc; 00163 } 00164 00165 00166 /* Initialize the mass storage and scsi interfaces */ 00167 rc = MS_Init( &_blkSize, &_numBlks, inquiryResult ); 00168 if (rc != OK) 00169 { 00170 fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); 00171 return rc; 00172 } 00173 printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); 00174 print_inquiry(inquiryResult); 00175 // FATFileSystem supports only 512-byte blocks 00176 return _blkSize == 512 ? OK : 1; 00177 } 00178 00179 00180
Generated on Tue Jul 12 2022 19:25:48 by
1.7.2