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.
Fork of USBHost_DISCO-F746NG by
FATFileSystem/ChaN/diskio.cpp@26:49c13dfc95d0, 2016-11-30 (annotated)
- Committer:
- schmalzl
- Date:
- Wed Nov 30 10:51:48 2016 +0000
- Revision:
- 26:49c13dfc95d0
- Parent:
- 24:5396b6a93262
Turbo Ede v1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DieterGraef | 24:5396b6a93262 | 1 | /*-----------------------------------------------------------------------*/ |
DieterGraef | 24:5396b6a93262 | 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ |
DieterGraef | 24:5396b6a93262 | 3 | /*-----------------------------------------------------------------------*/ |
DieterGraef | 24:5396b6a93262 | 4 | /* This is a stub disk I/O module that acts as front end of the existing */ |
DieterGraef | 24:5396b6a93262 | 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ |
DieterGraef | 24:5396b6a93262 | 6 | /*-----------------------------------------------------------------------*/ |
DieterGraef | 24:5396b6a93262 | 7 | #include "ffconf.h" |
DieterGraef | 24:5396b6a93262 | 8 | #include "diskio.h" |
DieterGraef | 24:5396b6a93262 | 9 | |
DieterGraef | 24:5396b6a93262 | 10 | #include "mbed_debug.h" |
DieterGraef | 24:5396b6a93262 | 11 | #include "FATFileSystem.h" |
DieterGraef | 24:5396b6a93262 | 12 | |
DieterGraef | 24:5396b6a93262 | 13 | using namespace mbed; |
DieterGraef | 24:5396b6a93262 | 14 | |
DieterGraef | 24:5396b6a93262 | 15 | DSTATUS disk_initialize ( |
DieterGraef | 24:5396b6a93262 | 16 | BYTE pdrv /* Physical drive number (0..) */ |
DieterGraef | 24:5396b6a93262 | 17 | ) |
DieterGraef | 24:5396b6a93262 | 18 | { |
DieterGraef | 24:5396b6a93262 | 19 | debug_if(FFS_DBG, "disk_initialize on pdrv [%d]\n", pdrv); |
DieterGraef | 24:5396b6a93262 | 20 | return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_initialize(); |
DieterGraef | 24:5396b6a93262 | 21 | } |
DieterGraef | 24:5396b6a93262 | 22 | |
DieterGraef | 24:5396b6a93262 | 23 | DSTATUS disk_status ( |
DieterGraef | 24:5396b6a93262 | 24 | BYTE pdrv /* Physical drive number (0..) */ |
DieterGraef | 24:5396b6a93262 | 25 | ) |
DieterGraef | 24:5396b6a93262 | 26 | { |
DieterGraef | 24:5396b6a93262 | 27 | debug_if(FFS_DBG, "disk_status on pdrv [%d]\n", pdrv); |
DieterGraef | 24:5396b6a93262 | 28 | return (DSTATUS)FATFileSystem::_ffs[pdrv]->disk_status(); |
DieterGraef | 24:5396b6a93262 | 29 | } |
DieterGraef | 24:5396b6a93262 | 30 | |
DieterGraef | 24:5396b6a93262 | 31 | DRESULT disk_read ( |
DieterGraef | 24:5396b6a93262 | 32 | BYTE pdrv, /* Physical drive number (0..) */ |
DieterGraef | 24:5396b6a93262 | 33 | BYTE* buff, /* Data buffer to store read data */ |
DieterGraef | 24:5396b6a93262 | 34 | DWORD sector, /* Sector address (LBA) */ |
DieterGraef | 24:5396b6a93262 | 35 | UINT count /* Number of sectors to read (1..) */ |
DieterGraef | 24:5396b6a93262 | 36 | ) |
DieterGraef | 24:5396b6a93262 | 37 | { |
DieterGraef | 24:5396b6a93262 | 38 | debug_if(FFS_DBG, "disk_read(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); |
DieterGraef | 24:5396b6a93262 | 39 | if (FATFileSystem::_ffs[pdrv]->disk_read((uint8_t*)buff, sector, count)) |
DieterGraef | 24:5396b6a93262 | 40 | return RES_PARERR; |
DieterGraef | 24:5396b6a93262 | 41 | else |
DieterGraef | 24:5396b6a93262 | 42 | return RES_OK; |
DieterGraef | 24:5396b6a93262 | 43 | } |
DieterGraef | 24:5396b6a93262 | 44 | |
DieterGraef | 24:5396b6a93262 | 45 | #if _READONLY == 0 |
DieterGraef | 24:5396b6a93262 | 46 | DRESULT disk_write ( |
DieterGraef | 24:5396b6a93262 | 47 | BYTE pdrv, /* Physical drive number (0..) */ |
DieterGraef | 24:5396b6a93262 | 48 | const BYTE* buff, /* Data to be written */ |
DieterGraef | 24:5396b6a93262 | 49 | DWORD sector, /* Sector address (LBA) */ |
DieterGraef | 24:5396b6a93262 | 50 | UINT count /* Number of sectors to write (1..) */ |
DieterGraef | 24:5396b6a93262 | 51 | ) |
DieterGraef | 24:5396b6a93262 | 52 | { |
DieterGraef | 24:5396b6a93262 | 53 | debug_if(FFS_DBG, "disk_write(sector %d, count %d) on pdrv [%d]\n", sector, count, pdrv); |
DieterGraef | 24:5396b6a93262 | 54 | if (FATFileSystem::_ffs[pdrv]->disk_write((uint8_t*)buff, sector, count)) |
DieterGraef | 24:5396b6a93262 | 55 | return RES_PARERR; |
DieterGraef | 24:5396b6a93262 | 56 | else |
DieterGraef | 24:5396b6a93262 | 57 | return RES_OK; |
DieterGraef | 24:5396b6a93262 | 58 | } |
DieterGraef | 24:5396b6a93262 | 59 | #endif /* _READONLY */ |
DieterGraef | 24:5396b6a93262 | 60 | |
DieterGraef | 24:5396b6a93262 | 61 | DRESULT disk_ioctl ( |
DieterGraef | 24:5396b6a93262 | 62 | BYTE pdrv, /* Physical drive number (0..) */ |
DieterGraef | 24:5396b6a93262 | 63 | BYTE cmd, /* Control code */ |
DieterGraef | 24:5396b6a93262 | 64 | void* buff /* Buffer to send/receive control data */ |
DieterGraef | 24:5396b6a93262 | 65 | ) |
DieterGraef | 24:5396b6a93262 | 66 | { |
DieterGraef | 24:5396b6a93262 | 67 | debug_if(FFS_DBG, "disk_ioctl(%d)\n", cmd); |
DieterGraef | 24:5396b6a93262 | 68 | switch(cmd) { |
DieterGraef | 24:5396b6a93262 | 69 | case CTRL_SYNC: |
DieterGraef | 24:5396b6a93262 | 70 | if(FATFileSystem::_ffs[pdrv] == NULL) { |
DieterGraef | 24:5396b6a93262 | 71 | return RES_NOTRDY; |
DieterGraef | 24:5396b6a93262 | 72 | } else if(FATFileSystem::_ffs[pdrv]->disk_sync()) { |
DieterGraef | 24:5396b6a93262 | 73 | return RES_ERROR; |
DieterGraef | 24:5396b6a93262 | 74 | } |
DieterGraef | 24:5396b6a93262 | 75 | return RES_OK; |
DieterGraef | 24:5396b6a93262 | 76 | case GET_SECTOR_COUNT: |
DieterGraef | 24:5396b6a93262 | 77 | if(FATFileSystem::_ffs[pdrv] == NULL) { |
DieterGraef | 24:5396b6a93262 | 78 | return RES_NOTRDY; |
DieterGraef | 24:5396b6a93262 | 79 | } else { |
DieterGraef | 24:5396b6a93262 | 80 | DWORD res = FATFileSystem::_ffs[pdrv]->disk_sectors(); |
DieterGraef | 24:5396b6a93262 | 81 | if(res > 0) { |
DieterGraef | 24:5396b6a93262 | 82 | *((DWORD*)buff) = res; // minimum allowed |
DieterGraef | 24:5396b6a93262 | 83 | return RES_OK; |
DieterGraef | 24:5396b6a93262 | 84 | } else { |
DieterGraef | 24:5396b6a93262 | 85 | return RES_ERROR; |
DieterGraef | 24:5396b6a93262 | 86 | } |
DieterGraef | 24:5396b6a93262 | 87 | } |
DieterGraef | 24:5396b6a93262 | 88 | case GET_BLOCK_SIZE: |
DieterGraef | 24:5396b6a93262 | 89 | *((DWORD*)buff) = 1; // default when not known |
DieterGraef | 24:5396b6a93262 | 90 | return RES_OK; |
DieterGraef | 24:5396b6a93262 | 91 | |
DieterGraef | 24:5396b6a93262 | 92 | } |
DieterGraef | 24:5396b6a93262 | 93 | return RES_PARERR; |
DieterGraef | 24:5396b6a93262 | 94 | } |