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.cpp
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 #include "ffconf.h" 00008 #include "diskio.h" 00009 00010 #include "mbed_debug.h" 00011 #include "FATFileSystem.h" 00012 00013 using namespace mbed; 00014 00015 DSTATUS disk_initialize ( 00016 BYTE drv /* Physical drive nmuber (0..) */ 00017 ) 00018 { 00019 debug_if(FFS_DBG, "disk_initialize on drv [%d]\n", drv); 00020 return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize(); 00021 } 00022 00023 DSTATUS disk_status ( 00024 BYTE drv /* Physical drive nmuber (0..) */ 00025 ) 00026 { 00027 debug_if(FFS_DBG, "disk_status on drv [%d]\n", drv); 00028 return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status(); 00029 } 00030 00031 DRESULT disk_read ( 00032 BYTE drv, /* Physical drive nmuber (0..) */ 00033 BYTE *buff, /* Data buffer to store read data */ 00034 DWORD sector, /* Sector address (LBA) */ 00035 BYTE count /* Number of sectors to read (1..255) */ 00036 ) 00037 { 00038 debug_if(FFS_DBG, "disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv); 00039 for(DWORD s=sector; s<sector+count; s++) { 00040 debug_if(FFS_DBG, " disk_read(sector %d)\n", s); 00041 int res = FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, s); 00042 if(res) { 00043 return RES_PARERR; 00044 } 00045 buff += 512; 00046 } 00047 return RES_OK; 00048 } 00049 00050 #if _READONLY == 0 00051 DRESULT disk_write ( 00052 BYTE drv, /* Physical drive nmuber (0..) */ 00053 const BYTE *buff, /* Data to be written */ 00054 DWORD sector, /* Sector address (LBA) */ 00055 BYTE count /* Number of sectors to write (1..255) */ 00056 ) 00057 { 00058 debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv); 00059 for(DWORD s = sector; s < sector + count; s++) { 00060 debug_if(FFS_DBG, " disk_write(sector %d)\n", s); 00061 int res = FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, s); 00062 if(res) { 00063 return RES_PARERR; 00064 } 00065 buff += 512; 00066 } 00067 return RES_OK; 00068 } 00069 #endif /* _READONLY */ 00070 00071 DRESULT disk_ioctl ( 00072 BYTE drv, /* Physical drive nmuber (0..) */ 00073 BYTE ctrl, /* Control code */ 00074 void *buff /* Buffer to send/receive control data */ 00075 ) 00076 { 00077 debug_if(FFS_DBG, "disk_ioctl(%d)\n", ctrl); 00078 switch(ctrl) { 00079 case CTRL_SYNC: 00080 if(FATFileSystem::_ffs[drv] == NULL) { 00081 return RES_NOTRDY; 00082 } else if(FATFileSystem::_ffs[drv]->disk_sync()) { 00083 return RES_ERROR; 00084 } 00085 return RES_OK; 00086 case GET_SECTOR_COUNT: 00087 if(FATFileSystem::_ffs[drv] == NULL) { 00088 return RES_NOTRDY; 00089 } else { 00090 DWORD res = FATFileSystem::_ffs[drv]->disk_sectors(); 00091 if(res > 0) { 00092 *((DWORD*)buff) = res; // minimum allowed 00093 return RES_OK; 00094 } else { 00095 return RES_ERROR; 00096 } 00097 } 00098 case GET_BLOCK_SIZE: 00099 *((DWORD*)buff) = 1; // default when not known 00100 return RES_OK; 00101 00102 } 00103 return RES_PARERR; 00104 } 00105
Generated on Tue Jul 12 2022 18:55:00 by
1.7.2